001 /** 002 * Copyright 2005-2014 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.rice.kim.bo.ui; 017 018 import org.hibernate.annotations.Fetch; 019 import org.hibernate.annotations.FetchMode; 020 import org.hibernate.annotations.GenericGenerator; 021 import org.hibernate.annotations.Parameter; 022 import org.kuali.rice.core.api.delegation.DelegationType; 023 import org.kuali.rice.core.api.membership.MemberType; 024 import org.kuali.rice.kim.api.KimConstants; 025 import org.kuali.rice.kim.api.group.Group; 026 import org.kuali.rice.kim.api.role.Role; 027 import org.kuali.rice.kim.api.services.KimApiServiceLocator; 028 import org.kuali.rice.kim.impl.role.RoleBo; 029 import org.kuali.rice.kim.impl.type.KimTypeAttributesHelper; 030 import org.kuali.rice.kim.impl.type.KimTypeBo; 031 import org.springframework.util.AutoPopulatingList; 032 033 import javax.persistence.CascadeType; 034 import javax.persistence.Column; 035 import javax.persistence.Entity; 036 import javax.persistence.FetchType; 037 import javax.persistence.GeneratedValue; 038 import javax.persistence.Id; 039 import javax.persistence.IdClass; 040 import javax.persistence.JoinColumn; 041 import javax.persistence.JoinColumns; 042 import javax.persistence.OneToMany; 043 import javax.persistence.Table; 044 import javax.persistence.Transient; 045 import java.util.List; 046 047 /** 048 * This is a description of what this class does - kellerj don't forget to fill this in. 049 * 050 * @author Kuali Rice Team (kuali-rice@googleroles.com) 051 * 052 */ 053 @IdClass(RoleDocumentDelegationMemberId.class) 054 @Entity 055 @Table(name="KRIM_PND_DLGN_MBR_T") 056 public class RoleDocumentDelegationMember extends KimDocumentBoActivatableToFromBase { 057 058 private static final long serialVersionUID = 1L; 059 060 @Id 061 @GeneratedValue(generator="KRIM_DLGN_MBR_ID_S") 062 @GenericGenerator(name="KRIM_DLGN_MBR_ID_S",strategy="org.kuali.rice.core.jpa.spring.RiceNumericStringSequenceStyleGenerator",parameters={ 063 @Parameter(name="sequence_name",value="KRIM_DLGN_MBR_ID_S"), 064 @Parameter(name="value_column",value="id") 065 }) 066 @Column(name="DLGN_MBR_ID") 067 protected String delegationMemberId; 068 069 @Column(name="ROLE_MBR_ID") 070 protected String roleMemberId; 071 @Transient 072 protected String roleMemberMemberId; 073 @Transient 074 protected String roleMemberMemberTypeCode; 075 @Transient 076 protected String roleMemberName; 077 @Transient 078 protected String roleMemberNamespaceCode; 079 080 @Transient 081 private KimTypeAttributesHelper attributesHelper; 082 //For Person Document UI - flattening the delegation - delegation member hierarchy 083 @Transient 084 protected RoleBo roleBo = new RoleBo(); 085 086 @Column(name="DLGN_ID") 087 protected String delegationId; 088 089 @Column(name="MBR_ID") 090 protected String memberId; 091 092 @Column(name="MBR_TYP_CD") 093 protected String memberTypeCode = KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE.getCode(); 094 095 @Transient 096 protected String memberNamespaceCode; 097 098 @Column(name="MBR_NM") 099 protected String memberName; 100 @OneToMany(targetEntity=RoleDocumentDelegationMemberQualifier.class, fetch=FetchType.EAGER, cascade={CascadeType.ALL}) 101 @Fetch(value = FetchMode.SELECT) 102 @JoinColumns({ 103 @JoinColumn(name="dlgn_id",insertable=false,updatable=false), 104 @JoinColumn(name="fdoc_nbr", insertable=false, updatable=false) 105 }) 106 protected List <RoleDocumentDelegationMemberQualifier> qualifiers = new AutoPopulatingList(RoleDocumentDelegationMemberQualifier.class); 107 108 @Transient 109 protected String delegationTypeCode; 110 111 /** 112 * @return the delegationTypeCode 113 */ 114 public String getDelegationTypeCode() { 115 return this.delegationTypeCode; 116 } 117 118 /** 119 * @param delegationTypeCode the delegationTypeCode to set 120 */ 121 public void setDelegationTypeCode(String delegationTypeCode) { 122 this.delegationTypeCode = delegationTypeCode; 123 } 124 125 public String getDelegationId() { 126 return this.delegationId; 127 } 128 129 public void setDelegationId(String delegationId) { 130 this.delegationId = delegationId; 131 } 132 133 /** 134 * @return the qualifiers 135 */ 136 public List<RoleDocumentDelegationMemberQualifier> getQualifiers() { 137 return this.qualifiers; 138 } 139 140 public RoleDocumentDelegationMemberQualifier getQualifier(String kimAttributeDefnId) { 141 for(RoleDocumentDelegationMemberQualifier qualifier:qualifiers){ 142 if(qualifier.getKimAttrDefnId().equals(kimAttributeDefnId)) { 143 return qualifier; 144 } 145 } 146 return null; 147 } 148 149 /** 150 * @param qualifiers the qualifiers to set 151 */ 152 public void setQualifiers(List<RoleDocumentDelegationMemberQualifier> qualifiers) { 153 this.qualifiers = qualifiers; 154 } 155 156 public int getNumberOfQualifiers(){ 157 return qualifiers==null?0:qualifiers.size(); 158 } 159 160 /** 161 * @return the memberId 162 */ 163 public String getMemberId() { 164 return this.memberId; 165 } 166 167 /** 168 * @param memberId the memberId to set 169 */ 170 public void setMemberId(String memberId) { 171 this.memberId = memberId; 172 } 173 174 /** 175 * @return the memberName 176 */ 177 public String getMemberName() { 178 return this.memberName; 179 } 180 181 /** 182 * @param memberName the memberName to set 183 */ 184 public void setMemberName(String memberName) { 185 this.memberName = memberName; 186 } 187 188 /** 189 * @return the assignedToId 190 */ 191 public String getDelegationMemberId() { 192 return this.delegationMemberId; 193 } 194 195 /** 196 * @param delegationMemberId the assignedToId to set 197 */ 198 public void setDelegationMemberId(String delegationMemberId) { 199 this.delegationMemberId = delegationMemberId; 200 } 201 202 /** 203 * @return the memberTypeCode 204 */ 205 public String getMemberTypeCode() { 206 return this.memberTypeCode; 207 } 208 209 /** 210 * @param memberTypeCode the memberTypeCode to set 211 */ 212 public void setMemberTypeCode(String memberTypeCode) { 213 this.memberTypeCode = memberTypeCode; 214 } 215 216 217 public boolean isDelegationPrimary(){ 218 return DelegationType.PRIMARY.getCode().equals(getDelegationTypeCode()); 219 } 220 221 public boolean isDelegationSecondary(){ 222 return DelegationType.SECONDARY.getCode().equals(getDelegationTypeCode()); 223 } 224 225 /** 226 * @return the memberNamespaceCode 227 */ 228 public String getMemberNamespaceCode() { 229 if ( memberNamespaceCode == null ) { 230 populateDerivedValues(); 231 } 232 return this.memberNamespaceCode; 233 } 234 235 /** 236 * @param memberNamespaceCode the memberNamespaceCode to set 237 */ 238 public void setMemberNamespaceCode(String memberNamespaceCode) { 239 this.memberNamespaceCode = memberNamespaceCode; 240 } 241 242 protected void populateDerivedValues() { 243 if(MemberType.GROUP.getCode().equals(getMemberTypeCode())){ 244 Group groupInfo = null; 245 groupInfo = KimApiServiceLocator.getGroupService().getGroup(getMemberId()); 246 if (groupInfo != null) { 247 setMemberNamespaceCode(groupInfo.getNamespaceCode()); 248 } 249 } else if(MemberType.ROLE.getCode().equals(getMemberTypeCode())){ 250 Role role; 251 role = KimApiServiceLocator.getRoleService().getRole(getMemberId()); 252 setMemberNamespaceCode(role.getNamespaceCode()); 253 } 254 } 255 256 /** 257 * @return the roleMemberId 258 */ 259 public String getRoleMemberId() { 260 return this.roleMemberId; 261 } 262 263 /** 264 * @param roleMemberId the roleMemberId to set 265 */ 266 public void setRoleMemberId(String roleMemberId) { 267 this.roleMemberId = roleMemberId; 268 } 269 270 public boolean isRole(){ 271 return getMemberTypeCode()!=null && getMemberTypeCode().equals(MemberType.ROLE.getCode()); 272 } 273 274 public boolean isGroup(){ 275 return getMemberTypeCode()!=null && getMemberTypeCode().equals(MemberType.GROUP.getCode()); 276 } 277 278 public boolean isPrincipal(){ 279 return getMemberTypeCode()!=null && getMemberTypeCode().equals(MemberType.PRINCIPAL.getCode()); 280 } 281 282 /** 283 * @return the roleMemberName 284 */ 285 public String getRoleMemberName() { 286 return this.roleMemberName; 287 } 288 289 /** 290 * @param roleMemberName the roleMemberName to set 291 */ 292 public void setRoleMemberName(String roleMemberName) { 293 this.roleMemberName = roleMemberName; 294 } 295 296 /** 297 * @return the roleMemberNamespaceCode 298 */ 299 public String getRoleMemberNamespaceCode() { 300 return this.roleMemberNamespaceCode; 301 } 302 303 /** 304 * @param roleMemberNamespaceCode the roleMemberNamespaceCode to set 305 */ 306 public void setRoleMemberNamespaceCode(String roleMemberNamespaceCode) { 307 this.roleMemberNamespaceCode = roleMemberNamespaceCode; 308 } 309 310 /** 311 * @return the roleBo 312 */ 313 public RoleBo getRoleBo() { 314 return this.roleBo; 315 } 316 317 /** 318 * @param roleBo the roleBo to set 319 */ 320 public void setRoleBo(RoleBo roleBo) { 321 this.roleBo = roleBo; 322 setAttributesHelper(new KimTypeAttributesHelper(KimTypeBo.to(roleBo.getKimRoleType()))); 323 } 324 325 /** 326 * @return the attributesHelper 327 */ 328 public KimTypeAttributesHelper getAttributesHelper() { 329 return this.attributesHelper; 330 } 331 332 /** 333 * @param attributesHelper the attributesHelper to set 334 */ 335 public void setAttributesHelper(KimTypeAttributesHelper attributesHelper) { 336 this.attributesHelper = attributesHelper; 337 } 338 339 /** 340 * @return the roleMemberMemberId 341 */ 342 public String getRoleMemberMemberId() { 343 return this.roleMemberMemberId; 344 } 345 346 /** 347 * @param roleMemberMemberId the roleMemberMemberId to set 348 */ 349 public void setRoleMemberMemberId(String roleMemberMemberId) { 350 this.roleMemberMemberId = roleMemberMemberId; 351 } 352 353 /** 354 * @return the roleMemberMemberTypeCode 355 */ 356 public String getRoleMemberMemberTypeCode() { 357 return this.roleMemberMemberTypeCode; 358 } 359 360 /** 361 * @param roleMemberMemberTypeCode the roleMemberMemberTypeCode to set 362 */ 363 public void setRoleMemberMemberTypeCode(String roleMemberMemberTypeCode) { 364 this.roleMemberMemberTypeCode = roleMemberMemberTypeCode; 365 } 366 }