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