001/** 002 * Copyright 2005-2016 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 */ 016package org.kuali.rice.kim.document; 017 018import org.apache.commons.collections.CollectionUtils; 019import org.apache.commons.lang.StringUtils; 020import org.eclipse.persistence.annotations.JoinFetch; 021import org.eclipse.persistence.annotations.JoinFetchType; 022import org.kuali.rice.core.api.membership.MemberType; 023import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange; 024import org.kuali.rice.kim.api.KimConstants; 025import org.kuali.rice.kim.api.identity.employment.EntityEmployment; 026import org.kuali.rice.kim.api.role.Role; 027import org.kuali.rice.kim.api.services.KimApiServiceLocator; 028import org.kuali.rice.kim.api.type.KimType; 029import org.kuali.rice.kim.bo.ui.KimDocumentRoleMember; 030import org.kuali.rice.kim.bo.ui.KimDocumentRoleQualifier; 031import org.kuali.rice.kim.bo.ui.KimDocumentRoleResponsibilityAction; 032import org.kuali.rice.kim.bo.ui.PersonDocumentAddress; 033import org.kuali.rice.kim.bo.ui.PersonDocumentAffiliation; 034import org.kuali.rice.kim.bo.ui.PersonDocumentCitizenship; 035import org.kuali.rice.kim.bo.ui.PersonDocumentEmail; 036import org.kuali.rice.kim.bo.ui.PersonDocumentEmploymentInfo; 037import org.kuali.rice.kim.bo.ui.PersonDocumentGroup; 038import org.kuali.rice.kim.bo.ui.PersonDocumentName; 039import org.kuali.rice.kim.bo.ui.PersonDocumentPhone; 040import org.kuali.rice.kim.bo.ui.PersonDocumentPrivacy; 041import org.kuali.rice.kim.bo.ui.PersonDocumentRole; 042import org.kuali.rice.kim.bo.ui.RoleDocumentDelegation; 043import org.kuali.rice.kim.bo.ui.RoleDocumentDelegationMember; 044import org.kuali.rice.kim.bo.ui.RoleDocumentDelegationMemberQualifier; 045import org.kuali.rice.kim.impl.role.RoleBo; 046import org.kuali.rice.kim.impl.role.RoleMemberBo; 047import org.kuali.rice.kim.impl.services.KimImplServiceLocator; 048import org.kuali.rice.kim.impl.type.KimTypeAttributesHelper; 049import org.kuali.rice.kim.service.KIMServiceLocatorInternal; 050import org.kuali.rice.kim.service.UiDocumentService; 051import org.kuali.rice.kns.service.DocumentHelperService; 052import org.kuali.rice.kns.service.KNSServiceLocator; 053import org.kuali.rice.krad.data.jpa.converters.BooleanYNConverter; 054import org.kuali.rice.krad.data.jpa.converters.HashConverter; 055import org.kuali.rice.krad.data.platform.MaxValueIncrementerFactory; 056import org.kuali.rice.krad.rules.rule.event.DocumentEvent; 057import org.kuali.rice.krad.util.GlobalVariables; 058import org.springframework.jdbc.support.incrementer.DataFieldMaxValueIncrementer; 059 060import javax.persistence.AttributeOverride; 061import javax.persistence.AttributeOverrides; 062import javax.persistence.CascadeType; 063import javax.persistence.Column; 064import javax.persistence.Convert; 065import javax.persistence.Entity; 066import javax.persistence.JoinColumn; 067import javax.persistence.OneToMany; 068import javax.persistence.OneToOne; 069import javax.persistence.PrimaryKeyJoinColumn; 070import javax.persistence.Table; 071import javax.persistence.Transient; 072import java.util.ArrayList; 073import java.util.HashMap; 074import java.util.List; 075import java.util.Map; 076 077/** 078 * This is a description of what this class does - shyu don't forget to fill 079 * this in. 080 * 081 * @author Kuali Rice Team (rice.collab@kuali.org) 082 * 083 */ 084@AttributeOverrides({ @AttributeOverride(name = "documentNumber", column = @Column(name = "FDOC_NBR")) }) 085@Entity 086@Table(name = "KRIM_PERSON_DOCUMENT_T") 087public class IdentityManagementPersonDocument extends IdentityManagementKimDocument { 088 089 protected static final long serialVersionUID = -534993712085516925L; 090 091 // principal data 092 @Column(name = "PRNCPL_ID") 093 protected String principalId; 094 095 @Column(name = "PRNCPL_NM") 096 protected String principalName; 097 098 @Column(name = "ENTITY_ID") 099 protected String entityId; 100 101 //@Type(type="org.kuali.rice.krad.util.HibernateKualiHashType") 102 @Column(name = "PRNCPL_PSWD") 103 @Convert(converter = HashConverter.class) 104 protected String password; 105 106 @Column(name = "UNIV_ID") 107 protected String univId = ""; 108 109 // affiliation data 110 @JoinFetch(value= JoinFetchType.OUTER) 111 @OneToMany(targetEntity = PersonDocumentAffiliation.class, orphanRemoval = true, cascade = { CascadeType.REFRESH, CascadeType.REMOVE, CascadeType.PERSIST }) 112 @JoinColumn(name = "FDOC_NBR", referencedColumnName = "FDOC_NBR", insertable = false, updatable = false) 113 protected List<PersonDocumentAffiliation> affiliations; 114 115 @Transient 116 protected String campusCode = ""; 117 118 // external identifier data 119 @Transient 120 protected Map<String, String> externalIdentifiers = null; 121 122 @Column(name = "ACTV_IND") 123 @Convert(converter = BooleanYNConverter.class) 124 protected boolean active; 125 126 // citizenship 127 @Transient 128 protected List<PersonDocumentCitizenship> citizenships; 129 130 // protected List<DocEmploymentInfo> employmentInformations; 131 @JoinFetch(value= JoinFetchType.OUTER) 132 @OneToMany(targetEntity = PersonDocumentName.class, orphanRemoval = true, cascade = { CascadeType.REFRESH, CascadeType.REMOVE, CascadeType.PERSIST }) 133 @JoinColumn(name = "FDOC_NBR", referencedColumnName = "FDOC_NBR", insertable = false, updatable = false) 134 protected List<PersonDocumentName> names; 135 136 @JoinFetch(value= JoinFetchType.OUTER) 137 @OneToMany(targetEntity = PersonDocumentAddress.class, orphanRemoval = true, cascade = { CascadeType.REFRESH, CascadeType.REMOVE, CascadeType.PERSIST }) 138 @JoinColumn(name = "FDOC_NBR", referencedColumnName = "FDOC_NBR", insertable = false, updatable = false) 139 protected List<PersonDocumentAddress> addrs; 140 141 @JoinFetch(value= JoinFetchType.OUTER) 142 @OneToMany(targetEntity = PersonDocumentPhone.class, orphanRemoval = true, cascade = { CascadeType.REFRESH, CascadeType.REMOVE, CascadeType.PERSIST }) 143 @JoinColumn(name = "FDOC_NBR", referencedColumnName = "FDOC_NBR", insertable = false, updatable = false) 144 protected List<PersonDocumentPhone> phones; 145 146 @JoinFetch(value= JoinFetchType.OUTER) 147 @OneToMany(targetEntity = PersonDocumentEmail.class, orphanRemoval = true, cascade = { CascadeType.REFRESH, CascadeType.REMOVE, CascadeType.PERSIST }) 148 @JoinColumn(name = "FDOC_NBR", referencedColumnName = "FDOC_NBR", insertable = false, updatable = false) 149 protected List<PersonDocumentEmail> emails; 150 151 @JoinFetch(value= JoinFetchType.OUTER) 152 @OneToMany(targetEntity = PersonDocumentGroup.class, orphanRemoval = true, cascade = { CascadeType.REFRESH, CascadeType.REMOVE, CascadeType.PERSIST }) 153 @JoinColumn(name = "FDOC_NBR", referencedColumnName = "FDOC_NBR", insertable = false, updatable = false) 154 protected List<PersonDocumentGroup> groups; 155 156 @JoinFetch(value= JoinFetchType.OUTER) 157 @OneToMany(targetEntity = PersonDocumentRole.class, orphanRemoval = true, cascade = { CascadeType.REFRESH, CascadeType.REMOVE, CascadeType.PERSIST }) 158 @JoinColumn(name = "FDOC_NBR", referencedColumnName = "FDOC_NBR", insertable = false, updatable = false) 159 protected List<PersonDocumentRole> roles; 160 161 @JoinFetch(value= JoinFetchType.OUTER) 162 @OneToOne(targetEntity = PersonDocumentPrivacy.class, orphanRemoval = true, cascade = { CascadeType.REFRESH, CascadeType.REMOVE, CascadeType.PERSIST }) 163 @PrimaryKeyJoinColumn(name = "FDOC_NBR", referencedColumnName = "FDOC_NBR") 164 protected PersonDocumentPrivacy privacy; 165 166 public IdentityManagementPersonDocument() { 167 affiliations = new ArrayList<PersonDocumentAffiliation>(); 168 citizenships = new ArrayList<PersonDocumentCitizenship>(); 169 // employmentInformations = new ArrayList<DocEmploymentInfo>(); 170 names = new ArrayList<PersonDocumentName>(); 171 addrs = new ArrayList<PersonDocumentAddress>(); 172 phones = new ArrayList<PersonDocumentPhone>(); 173 emails = new ArrayList<PersonDocumentEmail>(); 174 groups = new ArrayList<PersonDocumentGroup>(); 175 roles = new ArrayList<PersonDocumentRole>(); 176 privacy = new PersonDocumentPrivacy(); 177 this.active = true; 178 } 179 180 public String getPrincipalId() { 181 return this.principalId; 182 } 183 184 public void setPrincipalId(String principalId) { 185 this.principalId = principalId; 186 } 187 188 public String getPrincipalName() { 189 return this.principalName; 190 } 191 192 /* 193 * sets the principal name. 194 * Principal names are converted to lower case. 195 */ 196 public void setPrincipalName(String principalName) { 197 this.principalName = principalName; 198 } 199 200 public String getEntityId() { 201 return this.entityId; 202 } 203 204 public void setEntityId(String entityId) { 205 this.entityId = entityId; 206 } 207 208 public List<PersonDocumentAffiliation> getAffiliations() { 209 return this.affiliations; 210 } 211 212 public void setAffiliations(List<PersonDocumentAffiliation> affiliations) { 213 this.affiliations = affiliations; 214 } 215 216 public String getCampusCode() { 217 return this.campusCode; 218 } 219 220 public void setCampusCode(String campusCode) { 221 this.campusCode = campusCode; 222 } 223 224 public Map<String, String> getExternalIdentifiers() { 225 return this.externalIdentifiers; 226 } 227 228 public void setExternalIdentifiers(Map<String, String> externalIdentifiers) { 229 this.externalIdentifiers = externalIdentifiers; 230 } 231 232 public String getPassword() { 233 return this.password; 234 } 235 236 public void setPassword(String password) { 237 this.password = password; 238 } 239 240 public boolean isActive() { 241 return this.active; 242 } 243 244 public void setActive(boolean active) { 245 this.active = active; 246 } 247 248 public List<PersonDocumentCitizenship> getCitizenships() { 249 return this.citizenships; 250 } 251 252 public void setCitizenships(List<PersonDocumentCitizenship> citizenships) { 253 this.citizenships = citizenships; 254 } 255 256 public List<PersonDocumentName> getNames() { 257 return this.names; 258 } 259 260 public void setNames(List<PersonDocumentName> names) { 261 this.names = names; 262 } 263 264 public List<PersonDocumentAddress> getAddrs() { 265 return this.addrs; 266 } 267 268 public void setAddrs(List<PersonDocumentAddress> addrs) { 269 this.addrs = addrs; 270 } 271 272 public List<PersonDocumentPhone> getPhones() { 273 return this.phones; 274 } 275 276 public void setPhones(List<PersonDocumentPhone> phones) { 277 this.phones = phones; 278 } 279 280 public List<PersonDocumentEmail> getEmails() { 281 return this.emails; 282 } 283 284 public void setEmails(List<PersonDocumentEmail> emails) { 285 this.emails = emails; 286 } 287 288 public void setGroups(List<PersonDocumentGroup> groups) { 289 this.groups = groups; 290 } 291 292 public List<PersonDocumentRole> getRoles() { 293 return this.roles; 294 } 295 296 public void setRoles(List<PersonDocumentRole> roles) { 297 this.roles = roles; 298 } 299 300 public List<PersonDocumentGroup> getGroups() { 301 return this.groups; 302 } 303 304 public String getUnivId() { 305 return this.univId; 306 } 307 308 public void setUnivId(String univId) { 309 this.univId = univId; 310 } 311 312 public PersonDocumentPrivacy getPrivacy() { 313 return this.privacy; 314 } 315 316 public void setPrivacy(PersonDocumentPrivacy privacy) { 317 this.privacy = privacy; 318 } 319 320 public void initializeDocumentForNewPerson() { 321 if (StringUtils.isBlank(this.principalId)) { 322 DataFieldMaxValueIncrementer incrementer = MaxValueIncrementerFactory.getIncrementer(KimImplServiceLocator.getDataSource(), KimConstants.SequenceNames.KRIM_PRNCPL_ID_S); 323 this.principalId = incrementer.nextStringValue(); 324 } 325 if (StringUtils.isBlank(this.entityId)) { 326 DataFieldMaxValueIncrementer incrementer = MaxValueIncrementerFactory.getIncrementer(KimImplServiceLocator.getDataSource(), KimConstants.SequenceNames.KRIM_ENTITY_ID_S); 327 this.entityId = incrementer.nextStringValue(); 328 } 329 } 330 331 @SuppressWarnings({"unchecked", "rawtypes", "deprecation"}) 332 @Override 333 public List buildListOfDeletionAwareLists() { 334 List managedLists = super.buildListOfDeletionAwareLists(); 335 List<PersonDocumentEmploymentInfo> empInfos = new ArrayList<PersonDocumentEmploymentInfo>(); 336 for (PersonDocumentAffiliation affiliation : getAffiliations()) { 337 empInfos.addAll(affiliation.getEmpInfos()); 338 } 339 managedLists.add(empInfos); 340 managedLists.add(getAffiliations()); 341 managedLists.add(getCitizenships()); 342 managedLists.add(getPhones()); 343 managedLists.add(getAddrs()); 344 managedLists.add(getEmails()); 345 managedLists.add(getNames()); 346 managedLists.add(getGroups()); 347 managedLists.add(getRoles()); 348 return managedLists; 349 } 350 351 /** 352 * @see org.kuali.rice.krad.document.DocumentBase#doRouteStatusChange(org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange) 353 */ 354 @Override 355 public void doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) { 356 super.doRouteStatusChange(statusChangeEvent); 357 if (getDocumentHeader().getWorkflowDocument().isProcessed()) { 358 setIfRolesEditable(); 359 KIMServiceLocatorInternal.getUiDocumentService().saveEntityPerson(this); 360 } 361 } 362 363 @Override 364 public void prepareForSave() { 365 if (StringUtils.isBlank(getPrivacy().getDocumentNumber())) { 366 getPrivacy().setDocumentNumber(getDocumentNumber()); 367 } 368 setEmployeeRecordIds(); 369 for (PersonDocumentRole role : getRoles()) { 370 role.setDocumentNumber(getDocumentNumber()); 371 for (KimDocumentRoleMember rolePrncpl : role.getRolePrncpls()) { 372 rolePrncpl.setDocumentNumber(getDocumentNumber()); 373 rolePrncpl.setRoleId(role.getRoleId()); 374 if (StringUtils.isEmpty(rolePrncpl.getRoleMemberId())) { 375 DataFieldMaxValueIncrementer incrementer = MaxValueIncrementerFactory.getIncrementer(KimImplServiceLocator.getDataSource(), "KRIM_ROLE_MBR_ID_S"); 376 rolePrncpl.setRoleMemberId(incrementer.nextStringValue()); 377 } 378 for (KimDocumentRoleQualifier qualifier : rolePrncpl.getQualifiers()) { 379 qualifier.setDocumentNumber(getDocumentNumber()); 380 qualifier.setRoleMemberId(rolePrncpl.getRoleMemberId()); 381 qualifier.setKimTypId(role.getKimTypeId()); 382 } 383 for (KimDocumentRoleResponsibilityAction responsibilityAction : rolePrncpl.getRoleRspActions()) { 384 responsibilityAction.setDocumentNumber(getDocumentNumber()); 385 responsibilityAction.setRoleMemberId(rolePrncpl.getRoleMemberId()); 386 responsibilityAction.setRoleResponsibilityId("*"); 387 } 388 } 389 } 390 if (getDelegationMembers() != null) { 391 for (RoleDocumentDelegationMember delegationMember : getDelegationMembers()) { 392 delegationMember.setDocumentNumber(getDocumentNumber()); 393 for (RoleDocumentDelegationMemberQualifier qualifier : delegationMember.getQualifiers()) { 394 qualifier.setDocumentNumber(getDocumentNumber()); 395 qualifier.setKimTypId(delegationMember.getRoleBo().getKimTypeId()); 396 } 397 addDelegationMemberToDelegation(delegationMember); 398 } 399 } 400 // important to do this after getDelegationMembers since the addDelegationMemberToDelegation method will create 401 // primary and/or secondary delegations for us in a "just-in-time" fashion 402 if (getDelegations() != null) { 403 List<RoleDocumentDelegation> emptyDelegations = new ArrayList<>(); 404 for (RoleDocumentDelegation delegation : getDelegations()) { 405 delegation.setDocumentNumber(getDocumentNumber()); 406 if (delegation.getMembers().isEmpty()) { 407 emptyDelegations.add(delegation); 408 } 409 } 410 // remove any empty delegations because we just don't need them 411 getDelegations().removeAll(emptyDelegations); 412 } 413 if (getAddrs() != null) { 414 for (PersonDocumentAddress address : getAddrs()) { 415 address.setDocumentNumber(getDocumentNumber()); 416 if (StringUtils.isEmpty(address.getEntityAddressId())) { 417 DataFieldMaxValueIncrementer incrementer = MaxValueIncrementerFactory.getIncrementer(KimImplServiceLocator.getDataSource(), "KRIM_ENTITY_ADDR_ID_S"); 418 address.setEntityAddressId(incrementer.nextStringValue()); 419 } 420 } 421 } 422 if (getAffiliations() != null) { 423 String nextValue = null; 424 425 for (PersonDocumentAffiliation affiliation : getAffiliations()) { 426 affiliation.setDocumentNumber(getDocumentNumber()); 427 if (StringUtils.isEmpty(affiliation.getEntityAffiliationId())) { 428 DataFieldMaxValueIncrementer incrementer = MaxValueIncrementerFactory.getIncrementer(KimImplServiceLocator.getDataSource(), "KRIM_ENTITY_AFLTN_ID_S"); 429 nextValue = incrementer.nextStringValue(); 430 affiliation.setEntityAffiliationId(nextValue); 431 } 432 for (PersonDocumentEmploymentInfo empInfo : affiliation.getEmpInfos()) { 433 empInfo.setDocumentNumber(getDocumentNumber()); 434 if (StringUtils.isEmpty(empInfo.getEntityAffiliationId())) { 435 empInfo.setEntityAffiliationId(nextValue); 436 } 437 } 438 } 439 } 440 if (getEmails() != null) { 441 for (PersonDocumentEmail email : getEmails()) { 442 email.setDocumentNumber(getDocumentNumber()); 443 if (StringUtils.isEmpty(email.getEntityEmailId())) { 444 DataFieldMaxValueIncrementer incrementer = MaxValueIncrementerFactory.getIncrementer(KimImplServiceLocator.getDataSource(), "KRIM_ENTITY_EMAIL_ID_S"); 445 email.setEntityEmailId(incrementer.nextStringValue()); 446 } 447 } 448 } 449 if (getGroups() != null) { 450 for (PersonDocumentGroup group : getGroups()) { 451 group.setDocumentNumber(getDocumentNumber()); 452 if (StringUtils.isEmpty(group.getGroupMemberId())) { 453 DataFieldMaxValueIncrementer incrementer = MaxValueIncrementerFactory.getIncrementer(KimImplServiceLocator.getDataSource(), "KRIM_GRP_MBR_ID_S"); 454 group.setGroupMemberId(incrementer.nextStringValue()); 455 } 456 } 457 } 458 if (getNames() != null) { 459 for (PersonDocumentName name : getNames()) { 460 name.setDocumentNumber(getDocumentNumber()); 461 if (StringUtils.isEmpty(name.getEntityNameId())) { 462 DataFieldMaxValueIncrementer incrementer = MaxValueIncrementerFactory.getIncrementer(KimImplServiceLocator.getDataSource(), "KRIM_ENTITY_NM_ID_S"); 463 name.setEntityNameId(incrementer.nextStringValue()); 464 } 465 } 466 } 467 if (getPhones() != null) { 468 for (PersonDocumentPhone phone : getPhones()) { 469 phone.setDocumentNumber(getDocumentNumber()); 470 if (StringUtils.isEmpty(phone.getEntityPhoneId())) { 471 DataFieldMaxValueIncrementer incrementer = MaxValueIncrementerFactory.getIncrementer(KimImplServiceLocator.getDataSource(), "KRIM_ENTITY_PHONE_ID_S"); 472 phone.setEntityPhoneId(incrementer.nextStringValue()); 473 } 474 } 475 } 476 } 477 478 @Override 479 public void postProcessSave(DocumentEvent event) { 480 super.postProcessSave(event); 481 // after the save has completed, we want to restore any potentially @Transient state that JPA might have 482 // discarded, specifically the delegation members have a lot of this 483 resyncTransientState(); 484 } 485 486 public void resyncTransientState() { 487 getDelegationMembers().clear(); 488 for (RoleDocumentDelegation delegation : getDelegations()) { 489 for (RoleDocumentDelegationMember delegationMember : delegation.getMembers()) { 490 491 // RoleDocumentDelegationMember has a number of transient fields that are derived from the role member, 492 // we must populate them in order for the person document to work properly when loading an existing 493 // person document 494 495 RoleMemberBo roleMember = getUiDocumentService().getRoleMember(delegationMember.getRoleMemberId()); 496 delegationMember.setRoleMemberMemberId(roleMember.getMemberId()); 497 delegationMember.setRoleMemberMemberTypeCode(roleMember.getType().getCode()); 498 delegationMember.setRoleMemberName(getUiDocumentService().getMemberName(MemberType.fromCode(delegationMember.getRoleMemberMemberTypeCode()), delegationMember.getRoleMemberMemberId())); 499 delegationMember.setRoleMemberNamespaceCode(getUiDocumentService().getMemberNamespaceCode(MemberType.fromCode(delegationMember.getRoleMemberMemberTypeCode()), delegationMember.getRoleMemberMemberId())); 500 delegationMember.setDelegationTypeCode(delegation.getDelegationTypeCode()); 501 Role role = KimApiServiceLocator.getRoleService().getRole(roleMember.getRoleId()); 502 delegationMember.setRoleBo(RoleBo.from(role)); 503 504 // don't want to be able to "delete" existing delegation members from the person document, so we 505 // indicate that we are editing the delegation member, which we are 506 delegationMember.setEdit(true); 507 508 getDelegationMembers().add(delegationMember); 509 } 510 } 511 } 512 513 514 515 protected void setEmployeeRecordIds() { 516 List<EntityEmployment> empInfos = getUiDocumentService().getEntityEmploymentInformationInfo(getEntityId()); 517 for (PersonDocumentAffiliation affiliation : getAffiliations()) { 518 int employeeRecordCounter = CollectionUtils.isEmpty(empInfos) ? 0 : empInfos.size(); 519 for (PersonDocumentEmploymentInfo empInfo : affiliation.getEmpInfos()) { 520 if (CollectionUtils.isNotEmpty(empInfos)) { 521 for (EntityEmployment origEmpInfo : empInfos) { 522 if (origEmpInfo.getId().equals(empInfo.getEntityEmploymentId())) { 523 empInfo.setEmploymentRecordId(origEmpInfo.getEmploymentRecordId()); 524 } 525 } 526 } 527 if (StringUtils.isEmpty(empInfo.getEmploymentRecordId())) { 528 employeeRecordCounter++; 529 empInfo.setEmploymentRecordId(employeeRecordCounter + ""); 530 } 531 } 532 } 533 } 534 535 public KimTypeAttributesHelper getKimTypeAttributesHelper(String roleId) { 536 Role role = KimApiServiceLocator.getRoleService().getRole(roleId); 537 KimType kimTypeInfo = KimApiServiceLocator.getKimTypeInfoService().getKimType(role.getKimTypeId()); 538 return new KimTypeAttributesHelper(kimTypeInfo); 539 } 540 541 public void setIfRolesEditable() { 542 if (CollectionUtils.isNotEmpty(getRoles())) { 543 for (PersonDocumentRole role : getRoles()) { 544 role.setEditable(validAssignRole(role)); 545 } 546 } 547 } 548 549 public boolean validAssignRole(PersonDocumentRole role) { 550 boolean rulePassed = true; 551 if (StringUtils.isNotEmpty(role.getNamespaceCode())) { 552 Map<String, String> additionalPermissionDetails = new HashMap<String, String>(); 553 additionalPermissionDetails.put(KimConstants.AttributeConstants.NAMESPACE_CODE, role.getNamespaceCode()); 554 additionalPermissionDetails.put(KimConstants.AttributeConstants.ROLE_NAME, role.getRoleName()); 555 if (!getDocumentHelperService().getDocumentAuthorizer(this).isAuthorizedByTemplate(this, KimConstants.NAMESPACE_CODE, KimConstants.PermissionTemplateNames.ASSIGN_ROLE, GlobalVariables.getUserSession().getPrincipalId(), additionalPermissionDetails, null)) { 556 rulePassed = false; 557 } 558 } 559 return rulePassed; 560 } 561 562 @Transient 563 protected transient DocumentHelperService documentHelperService; 564 565 @Transient 566 protected transient UiDocumentService uiDocumentService; 567 568 protected DocumentHelperService getDocumentHelperService() { 569 if (documentHelperService == null) { 570 documentHelperService = KNSServiceLocator.getDocumentHelperService(); 571 } 572 return this.documentHelperService; 573 } 574 575 protected UiDocumentService getUiDocumentService() { 576 if (uiDocumentService == null) { 577 uiDocumentService = KIMServiceLocatorInternal.getUiDocumentService(); 578 } 579 return this.uiDocumentService; 580 } 581}