Coverage Report - org.kuali.rice.kim.document.IdentityManagementPersonDocument
 
Classes in this File Line Coverage Branch Coverage Complexity
IdentityManagementPersonDocument
0%
0/202
0%
0/86
1.956
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.kim.document;
 17  
 
 18  
 import org.apache.commons.collections.CollectionUtils;
 19  
 import org.apache.commons.lang.StringUtils;
 20  
 import org.hibernate.annotations.Fetch;
 21  
 import org.hibernate.annotations.FetchMode;
 22  
 import org.hibernate.annotations.GenericGenerator;
 23  
 import org.hibernate.annotations.Parameter;
 24  
 import org.hibernate.annotations.Type;
 25  
 import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
 26  
 import org.kuali.rice.kim.api.KimConstants;
 27  
 import org.kuali.rice.kim.api.identity.employment.EntityEmployment;
 28  
 import org.kuali.rice.kim.api.role.Role;
 29  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 30  
 import org.kuali.rice.kim.api.type.KimType;
 31  
 import org.kuali.rice.kim.bo.ui.KimDocumentRoleMember;
 32  
 import org.kuali.rice.kim.bo.ui.KimDocumentRoleQualifier;
 33  
 import org.kuali.rice.kim.bo.ui.PersonDocumentAddress;
 34  
 import org.kuali.rice.kim.bo.ui.PersonDocumentAffiliation;
 35  
 import org.kuali.rice.kim.bo.ui.PersonDocumentCitizenship;
 36  
 import org.kuali.rice.kim.bo.ui.PersonDocumentEmail;
 37  
 import org.kuali.rice.kim.bo.ui.PersonDocumentEmploymentInfo;
 38  
 import org.kuali.rice.kim.bo.ui.PersonDocumentGroup;
 39  
 import org.kuali.rice.kim.bo.ui.PersonDocumentName;
 40  
 import org.kuali.rice.kim.bo.ui.PersonDocumentPhone;
 41  
 import org.kuali.rice.kim.bo.ui.PersonDocumentPrivacy;
 42  
 import org.kuali.rice.kim.bo.ui.PersonDocumentRole;
 43  
 import org.kuali.rice.kim.bo.ui.RoleDocumentDelegationMember;
 44  
 import org.kuali.rice.kim.bo.ui.RoleDocumentDelegationMemberQualifier;
 45  
 import org.kuali.rice.kim.impl.type.KimTypeAttributesHelper;
 46  
 import org.kuali.rice.kim.service.KIMServiceLocatorInternal;
 47  
 import org.kuali.rice.kim.service.UiDocumentService;
 48  
 import org.kuali.rice.krad.service.DocumentHelperService;
 49  
 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
 50  
 import org.kuali.rice.krad.service.SequenceAccessorService;
 51  
 import org.kuali.rice.krad.util.GlobalVariables;
 52  
 
 53  
 import javax.persistence.AssociationOverride;
 54  
 import javax.persistence.AssociationOverrides;
 55  
 import javax.persistence.AttributeOverride;
 56  
 import javax.persistence.AttributeOverrides;
 57  
 import javax.persistence.CascadeType;
 58  
 import javax.persistence.Column;
 59  
 import javax.persistence.Entity;
 60  
 import javax.persistence.FetchType;
 61  
 import javax.persistence.GeneratedValue;
 62  
 import javax.persistence.JoinColumn;
 63  
 import javax.persistence.OneToMany;
 64  
 import javax.persistence.OneToOne;
 65  
 import javax.persistence.Table;
 66  
 import javax.persistence.Transient;
 67  
 import java.util.ArrayList;
 68  
 import java.util.HashMap;
 69  
 import java.util.List;
 70  
 import java.util.Map;
 71  
 
 72  
 /**
 73  
  * This is a description of what this class does - shyu don't forget to fill
 74  
  * this in.
 75  
  *
 76  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 77  
  *
 78  
  */
 79  
 @Entity
 80  
 @AttributeOverrides({
 81  
         @AttributeOverride(name="documentNumber",column=@Column(name="FDOC_NBR"))
 82  
 })
 83  
 @AssociationOverrides({
 84  
         @AssociationOverride(name="documentHeader",joinColumns=@JoinColumn(name="FDOC_NBR",referencedColumnName="DOC_HDR_ID",insertable=false,updatable=false))
 85  
 })
 86  
 @Table(name="KRIM_PERSON_DOCUMENT_T")
 87  
 public class IdentityManagementPersonDocument extends IdentityManagementKimDocument {
 88  
 
 89  
     protected static final long serialVersionUID = -534993712085516925L;
 90  
     // principal data
 91  
     
 92  
     @GeneratedValue(generator="KRIM_PRNCPL_ID_S")
 93  
         @GenericGenerator(name="KRIM_PRNCPL_ID_S",strategy="org.kuali.rice.core.jpa.spring.RiceNumericStringSequenceStyleGenerator",parameters={
 94  
                         @Parameter(name="sequence_name",value="KRIM_PRNCPL_ID_S"),
 95  
                         @Parameter(name="value_column",value="id")
 96  
                 })
 97  
         @Column(name="PRNCPL_ID")
 98  
     protected String principalId;
 99  
     @Column(name="PRNCPL_NM")
 100  
     protected String principalName;
 101  
     @GeneratedValue(generator="KRIM_ENTITY_ID_S")
 102  
         @GenericGenerator(name="KRIM_ENTITY_ID_S",strategy="org.kuali.rice.core.jpa.spring.RiceNumericStringSequenceStyleGenerator",parameters={
 103  
                         @Parameter(name="sequence_name",value="KRIM_ENTITY_ID_S"),
 104  
                         @Parameter(name="value_column",value="id")
 105  
                 })
 106  
         @Column(name="ENTITY_ID")
 107  
     protected String entityId;
 108  
     @Type(type="org.kuali.rice.krad.util.HibernateKualiHashType")
 109  
     @Column(name="PRNCPL_PSWD")
 110  
     protected String password;
 111  
 
 112  0
     protected String univId = "";
 113  
     // affiliation data
 114  
     @OneToMany(targetEntity=PersonDocumentAffiliation.class, fetch=FetchType.EAGER, cascade={CascadeType.ALL})
 115  
     @Fetch(value = FetchMode.SELECT)
 116  
     @JoinColumn(name="FDOC_NBR",insertable=false,updatable=false)
 117  
     protected List<PersonDocumentAffiliation> affiliations;
 118  
 
 119  0
     @Transient
 120  
     protected String campusCode = "";
 121  
     // external identifier data
 122  0
     @Transient
 123  
     protected Map<String, String> externalIdentifiers = null;
 124  
 
 125  
     @Column(name="ACTV_IND")
 126  
         @Type(type="yes_no")
 127  
     protected boolean active;
 128  
 
 129  
     // citizenship
 130  
     @Transient
 131  
     protected List<PersonDocumentCitizenship> citizenships;
 132  
     // protected List<DocEmploymentInfo> employmentInformations;
 133  
     @OneToMany(targetEntity=PersonDocumentName.class, fetch=FetchType.EAGER, cascade={CascadeType.ALL})
 134  
     @Fetch(value = FetchMode.SELECT)
 135  
     @JoinColumn(name="FDOC_NBR",insertable=false,updatable=false)
 136  
     protected List<PersonDocumentName> names;
 137  
     @OneToMany(targetEntity=PersonDocumentAddress.class, fetch=FetchType.EAGER, cascade={CascadeType.ALL})
 138  
     @Fetch(value = FetchMode.SELECT)
 139  
     @JoinColumn(name="FDOC_NBR",insertable=false,updatable=false)
 140  
     protected List<PersonDocumentAddress> addrs;
 141  
     @OneToMany(targetEntity=PersonDocumentPhone.class, fetch=FetchType.EAGER, cascade={CascadeType.ALL})
 142  
     @Fetch(value = FetchMode.SELECT)
 143  
     @JoinColumn(name="FDOC_NBR")
 144  
     protected List<PersonDocumentPhone> phones;
 145  
     @OneToMany(targetEntity=PersonDocumentEmail.class, fetch=FetchType.EAGER, cascade={CascadeType.ALL})
 146  
     @Fetch(value = FetchMode.SELECT)
 147  
     @JoinColumn(name="FDOC_NBR",insertable=false,updatable=false)
 148  
     protected List<PersonDocumentEmail> emails;
 149  
     @OneToMany(targetEntity=PersonDocumentGroup.class, fetch=FetchType.EAGER, cascade={CascadeType.ALL})
 150  
     @Fetch(value = FetchMode.SELECT)
 151  
     @JoinColumn(name="FDOC_NBR",insertable=false,updatable=false)
 152  
     protected List<PersonDocumentGroup> groups;
 153  
     @OneToMany(targetEntity=PersonDocumentRole.class, fetch=FetchType.EAGER, cascade={CascadeType.ALL})
 154  
     @Fetch(value = FetchMode.SELECT)
 155  
     @JoinColumn(name="FDOC_NBR",insertable=false,updatable=false)
 156  
     protected List<PersonDocumentRole> roles;
 157  
 
 158  
     @OneToOne(targetEntity=PersonDocumentPrivacy.class, fetch=FetchType.EAGER, cascade={CascadeType.ALL})
 159  
     @JoinColumn(name="FDOC_NBR",insertable=false,updatable=false)
 160  
     protected PersonDocumentPrivacy privacy;
 161  
 
 162  0
     public IdentityManagementPersonDocument() {
 163  0
         affiliations = new ArrayList<PersonDocumentAffiliation>();
 164  0
         citizenships = new ArrayList<PersonDocumentCitizenship>();
 165  
         // employmentInformations = new ArrayList<DocEmploymentInfo>();
 166  0
         names = new ArrayList<PersonDocumentName>();
 167  0
         addrs = new ArrayList<PersonDocumentAddress>();
 168  0
         phones = new ArrayList<PersonDocumentPhone>();
 169  0
         emails = new ArrayList<PersonDocumentEmail>();
 170  0
         groups = new ArrayList<PersonDocumentGroup>();
 171  0
         roles = new ArrayList<PersonDocumentRole>();
 172  0
         privacy = new PersonDocumentPrivacy();
 173  0
         this.active = true;
 174  
         // privacy.setDocumentNumber(documentNumber);
 175  0
     }
 176  
 
 177  
     public String getPrincipalId() {
 178  0
         return this.principalId;
 179  
     }
 180  
 
 181  
     public void setPrincipalId(String principalId) {
 182  0
         this.principalId = principalId;
 183  0
     }
 184  
 
 185  
     public String getPrincipalName() {
 186  0
         return this.principalName;
 187  
     }
 188  
 
 189  
     /*
 190  
      * sets the principal name.  
 191  
      * Principal names are converted to lower case.
 192  
      */
 193  
     public void setPrincipalName(String principalName) {
 194  0
         this.principalName = principalName; // != null ? principalName.toLowerCase() : principalName ;
 195  0
     }
 196  
 
 197  
     public String getEntityId() {
 198  0
         return this.entityId;
 199  
     }
 200  
 
 201  
     public void setEntityId(String entityId) {
 202  0
         this.entityId = entityId;
 203  0
     }
 204  
 
 205  
     public List<PersonDocumentAffiliation> getAffiliations() {
 206  0
         return this.affiliations;
 207  
     }
 208  
 
 209  
     public void setAffiliations(List<PersonDocumentAffiliation> affiliations) {
 210  0
         this.affiliations = affiliations;
 211  0
     }
 212  
 
 213  
     public String getCampusCode() {
 214  0
         return this.campusCode;
 215  
     }
 216  
 
 217  
     public void setCampusCode(String campusCode) {
 218  0
         this.campusCode = campusCode;
 219  0
     }
 220  
 
 221  
     public Map<String, String> getExternalIdentifiers() {
 222  0
         return this.externalIdentifiers;
 223  
     }
 224  
 
 225  
     public void setExternalIdentifiers(Map<String, String> externalIdentifiers) {
 226  0
         this.externalIdentifiers = externalIdentifiers;
 227  0
     }
 228  
 
 229  
     public String getPassword() {
 230  0
         return this.password;
 231  
     }
 232  
 
 233  
     public void setPassword(String password) {
 234  0
         this.password = password;
 235  0
     }
 236  
 
 237  
     public boolean isActive() {
 238  0
         return this.active;
 239  
     }
 240  
 
 241  
     public void setActive(boolean active) {
 242  0
         this.active = active;
 243  0
     }
 244  
 
 245  
     public List<PersonDocumentCitizenship> getCitizenships() {
 246  0
         return this.citizenships;
 247  
     }
 248  
 
 249  
     public void setCitizenships(List<PersonDocumentCitizenship> citizenships) {
 250  0
         this.citizenships = citizenships;
 251  0
     }
 252  
 
 253  
     public List<PersonDocumentName> getNames() {
 254  0
         return this.names;
 255  
     }
 256  
 
 257  
     public void setNames(List<PersonDocumentName> names) {
 258  0
         this.names = names;
 259  0
     }
 260  
 
 261  
     public List<PersonDocumentAddress> getAddrs() {
 262  0
         return this.addrs;
 263  
     }
 264  
 
 265  
     public void setAddrs(List<PersonDocumentAddress> addrs) {
 266  0
         this.addrs = addrs;
 267  0
     }
 268  
 
 269  
     public List<PersonDocumentPhone> getPhones() {
 270  0
         return this.phones;
 271  
     }
 272  
 
 273  
     public void setPhones(List<PersonDocumentPhone> phones) {
 274  0
         this.phones = phones;
 275  0
     }
 276  
 
 277  
     public List<PersonDocumentEmail> getEmails() {
 278  0
         return this.emails;
 279  
     }
 280  
 
 281  
     public void setEmails(List<PersonDocumentEmail> emails) {
 282  0
         this.emails = emails;
 283  0
     }
 284  
 
 285  
     public void setGroups(List<PersonDocumentGroup> groups) {
 286  0
         this.groups = groups;
 287  0
     }
 288  
 
 289  
     public List<PersonDocumentRole> getRoles() {
 290  0
         return this.roles;
 291  
     }
 292  
 
 293  
     public void setRoles(List<PersonDocumentRole> roles) {
 294  0
         this.roles = roles;
 295  0
     }
 296  
 
 297  
     public List<PersonDocumentGroup> getGroups() {
 298  0
         return this.groups;
 299  
     }
 300  
 
 301  
     public String getUnivId() {
 302  0
         return this.univId;
 303  
     }
 304  
 
 305  
     public void setUnivId(String univId) {
 306  0
         this.univId = univId;
 307  0
     }
 308  
 
 309  
     public PersonDocumentPrivacy getPrivacy() {
 310  0
         return this.privacy;
 311  
     }
 312  
 
 313  
     public void setPrivacy(PersonDocumentPrivacy privacy) {
 314  0
         this.privacy = privacy;
 315  0
     }
 316  
 
 317  
     public void initializeDocumentForNewPerson() {
 318  0
         if(StringUtils.isBlank(this.principalId)){
 319  0
             this.principalId = getSequenceAccessorService().getNextAvailableSequenceNumber(KimConstants.SequenceNames.KRIM_PRNCPL_ID_S).toString();
 320  
         }
 321  0
         if(StringUtils.isBlank(this.entityId)){
 322  0
             this.entityId = getSequenceAccessorService().getNextAvailableSequenceNumber(KimConstants.SequenceNames.KRIM_ENTITY_ID_S).toString();
 323  
         }
 324  0
     }
 325  
 
 326  
     @SuppressWarnings("unchecked")
 327  
     @Override
 328  
     public List buildListOfDeletionAwareLists() {
 329  0
         List managedLists = super.buildListOfDeletionAwareLists();
 330  0
         List<PersonDocumentEmploymentInfo> empInfos = new ArrayList<PersonDocumentEmploymentInfo>();
 331  0
         for (PersonDocumentAffiliation affiliation : getAffiliations()) {
 332  0
             empInfos.addAll(affiliation.getEmpInfos());
 333  
         }
 334  
 
 335  0
         managedLists.add(empInfos);
 336  0
         managedLists.add(getAffiliations());
 337  0
         managedLists.add(getCitizenships());
 338  0
         managedLists.add(getPhones());
 339  0
         managedLists.add(getAddrs());
 340  0
         managedLists.add(getEmails());
 341  0
         managedLists.add(getNames());
 342  0
         managedLists.add(getGroups());
 343  0
         managedLists.add(getRoles());
 344  0
         return managedLists;
 345  
     }
 346  
 
 347  
     /**
 348  
      * @see org.kuali.rice.krad.document.DocumentBase#doRouteStatusChange(org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange)
 349  
      */
 350  
     @Override
 351  
     public void doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) {
 352  0
         super.doRouteStatusChange(statusChangeEvent);
 353  0
         if (getDocumentHeader().getWorkflowDocument().isProcessed()) {
 354  0
                 setIfRolesEditable();
 355  0
             KIMServiceLocatorInternal.getUiDocumentService().saveEntityPerson(this);
 356  
         }
 357  0
     }
 358  
 
 359  
 
 360  
     @Override
 361  
     public void prepareForSave(){
 362  0
         if (StringUtils.isBlank(getPrivacy().getDocumentNumber())) {
 363  0
             getPrivacy().setDocumentNumber(
 364  
                     getDocumentNumber());
 365  
         }
 366  0
         setEmployeeRecordIds();
 367  0
         for (PersonDocumentRole role : getRoles()) {
 368  0
                 role.setDocumentNumber(getDocumentNumber());
 369  
                 //if (StringUtils.isEmpty(role.getRoleId())) {
 370  
                     //        SequenceAccessorService sas = getSequenceAccessorService();
 371  
                         //        Long nextSeq = sas.getNextAvailableSequenceNumber(
 372  
                         //                        "KRIM_ROLE_ID_S", this.getClass());
 373  
                         //        String roleId = nextSeq.toString();
 374  
                         //        role.setRoleId(roleId);
 375  
                     //}
 376  0
             for (KimDocumentRoleMember rolePrncpl : role.getRolePrncpls()) {
 377  0
                 rolePrncpl.setDocumentNumber(getDocumentNumber());
 378  0
                 rolePrncpl.setRoleId(role.getRoleId());
 379  0
                 if (StringUtils.isEmpty(rolePrncpl.getRoleMemberId())) {
 380  0
                                 SequenceAccessorService sas = getSequenceAccessorService();
 381  0
                                         Long nextSeq = sas.getNextAvailableSequenceNumber(
 382  
                                                         "KRIM_ROLE_MBR_ID_S", this.getClass());
 383  0
                                         String roleMemberId = nextSeq.toString();
 384  0
                                         rolePrncpl.setRoleMemberId(roleMemberId);
 385  
                         }
 386  0
                 for (KimDocumentRoleQualifier qualifier : rolePrncpl.getQualifiers()) {
 387  0
                     qualifier.setDocumentNumber(getDocumentNumber());
 388  0
                     qualifier.setKimTypId(role.getKimTypeId());
 389  
                 }
 390  
             }
 391  
         }
 392  0
         if(getDelegationMembers()!=null){
 393  0
             for(RoleDocumentDelegationMember delegationMember: getDelegationMembers()){
 394  0
                 delegationMember.setDocumentNumber(getDocumentNumber());
 395  0
                 for (RoleDocumentDelegationMemberQualifier qualifier: delegationMember.getQualifiers()) {
 396  0
                     qualifier.setDocumentNumber(getDocumentNumber());
 397  0
                     qualifier.setKimTypId(delegationMember.getRoleBo().getKimTypeId());
 398  
                 }
 399  0
                 addDelegationMemberToDelegation(delegationMember);
 400  
             }
 401  
         }
 402  0
         if (getAddrs() != null) {
 403  
                 String entityAddressId;
 404  0
                 for(PersonDocumentAddress address : getAddrs()) {
 405  0
                         address.setDocumentNumber(getDocumentNumber());
 406  0
                         if (StringUtils.isEmpty(address.getEntityAddressId())) {
 407  0
                                 SequenceAccessorService sas = getSequenceAccessorService();
 408  0
                                         Long nextSeq = sas.getNextAvailableSequenceNumber(
 409  
                                                         "KRIM_ENTITY_ADDR_ID_S", this.getClass());
 410  0
                                         entityAddressId = nextSeq.toString();
 411  0
                                         address.setEntityAddressId(entityAddressId);
 412  0
                         }
 413  
                 }
 414  
         }
 415  0
         if (getAffiliations() != null) {
 416  
                 String affiliationId;
 417  0
                 for(PersonDocumentAffiliation affiliation : getAffiliations()) {
 418  0
                         affiliation.setDocumentNumber(getDocumentNumber());
 419  0
                         if (StringUtils.isEmpty(affiliation.getEntityAffiliationId())) {
 420  0
                                 SequenceAccessorService sas = getSequenceAccessorService();
 421  0
                                         Long nextSeq = sas.getNextAvailableSequenceNumber(
 422  
                                                         "KRIM_ENTITY_AFLTN_ID_S", this.getClass());
 423  0
                                         affiliationId = nextSeq.toString();
 424  0
                                         affiliation.setEntityAffiliationId(affiliationId);
 425  0
                         }
 426  
                 }
 427  
         }
 428  0
         if (getEmails() != null) {
 429  
                 String entityEmailId;
 430  0
                 for(PersonDocumentEmail email : getEmails()) {
 431  0
                         email.setDocumentNumber(getDocumentNumber());
 432  0
                         if (StringUtils.isEmpty(email.getEntityEmailId())) {
 433  0
                                 SequenceAccessorService sas = getSequenceAccessorService();
 434  0
                                         Long nextSeq = sas.getNextAvailableSequenceNumber(
 435  
                                                         "KRIM_ENTITY_EMAIL_ID_S", this.getClass());
 436  0
                                         entityEmailId = nextSeq.toString();
 437  0
                                         email.setEntityEmailId(entityEmailId);
 438  0
                         }
 439  
                 }
 440  
         }
 441  0
         if (getGroups() != null) {
 442  
                 String groupMemberId;
 443  0
                 for(PersonDocumentGroup group : getGroups()) {
 444  0
                         group.setDocumentNumber(getDocumentNumber());
 445  0
                         if (StringUtils.isEmpty(group.getGroupMemberId())) {
 446  0
                                 SequenceAccessorService sas = getSequenceAccessorService();
 447  0
                                         Long nextSeq = sas.getNextAvailableSequenceNumber(
 448  
                                                         "KRIM_GRP_MBR_ID_S", this.getClass());
 449  0
                                         groupMemberId = nextSeq.toString();
 450  0
                                         group.setGroupMemberId(groupMemberId);
 451  0
                         }
 452  
                 }
 453  
         }
 454  0
         if (getNames() != null) {
 455  
                 String entityNameId;
 456  0
                 for(PersonDocumentName name : getNames()) {
 457  0
                         name.setDocumentNumber(getDocumentNumber());
 458  0
                         if (StringUtils.isEmpty(name.getEntityNameId())) {
 459  0
                                 SequenceAccessorService sas = getSequenceAccessorService();
 460  0
                                         Long nextSeq = sas.getNextAvailableSequenceNumber(
 461  
                                                         "KRIM_ENTITY_NM_ID_S", this.getClass());
 462  0
                                         entityNameId = nextSeq.toString();
 463  0
                                         name.setEntityNameId(entityNameId);
 464  0
                         }
 465  
                 }
 466  
         }
 467  0
         if (getPhones() != null) {
 468  
                 String entityPhoneId;
 469  0
                 for(PersonDocumentPhone phone : getPhones()) {
 470  0
                         phone.setDocumentNumber(getDocumentNumber());
 471  0
                         if (StringUtils.isEmpty(phone.getEntityPhoneId())) {
 472  0
                                 SequenceAccessorService sas = getSequenceAccessorService();
 473  0
                                         Long nextSeq = sas.getNextAvailableSequenceNumber(
 474  
                                                         "KRIM_ENTITY_PHONE_ID_S", this.getClass());
 475  0
                                         entityPhoneId = nextSeq.toString();
 476  0
                                         phone.setEntityPhoneId(entityPhoneId);
 477  0
                         }
 478  
                 }
 479  
         }
 480  
         
 481  0
     }
 482  
 
 483  
     protected void setEmployeeRecordIds(){
 484  0
             List<EntityEmployment> empInfos = getUiDocumentService().getEntityEmploymentInformationInfo(getEntityId());
 485  0
         for(PersonDocumentAffiliation affiliation: getAffiliations()) {
 486  0
             int employeeRecordCounter = CollectionUtils.isEmpty(empInfos) ? 0 : empInfos.size();
 487  0
             for(PersonDocumentEmploymentInfo empInfo: affiliation.getEmpInfos()){
 488  0
                 if(CollectionUtils.isNotEmpty(empInfos)){
 489  0
                     for(EntityEmployment origEmpInfo: empInfos){
 490  0
                         if (origEmpInfo.getEmployeeId().equals(empInfo.getEntityEmploymentId())) {
 491  0
                             empInfo.setEmploymentRecordId(origEmpInfo.getEmploymentRecordId());
 492  
                         }
 493  
                     }
 494  
                 }
 495  0
                 if(StringUtils.isEmpty(empInfo.getEmploymentRecordId())){
 496  0
                     employeeRecordCounter++;
 497  0
                     empInfo.setEmploymentRecordId(employeeRecordCounter+"");
 498  
                 }
 499  
             }
 500  0
         }
 501  0
     }
 502  
 
 503  
     public KimTypeAttributesHelper getKimTypeAttributesHelper(String roleId) {
 504  0
         Role role = KimApiServiceLocator.getRoleService().getRole(roleId);
 505  0
         KimType kimTypeInfo = KimApiServiceLocator.getKimTypeInfoService().getKimType(role.getKimTypeId());
 506  0
         return new KimTypeAttributesHelper(kimTypeInfo);
 507  
         //addDelegationRoleKimTypeAttributeHelper(roleId, helper);
 508  
     }
 509  
 
 510  
         public void setIfRolesEditable(){
 511  0
                 if(CollectionUtils.isNotEmpty(getRoles())){
 512  0
                         for(PersonDocumentRole role: getRoles()){
 513  0
                                 role.setEditable(validAssignRole(role));
 514  
                         }
 515  
                 }
 516  0
         }
 517  
 
 518  
         public boolean validAssignRole(PersonDocumentRole role){
 519  0
         boolean rulePassed = true;
 520  0
         if(StringUtils.isNotEmpty(role.getNamespaceCode())){
 521  0
                 Map<String,String> additionalPermissionDetails = new HashMap<String,String>();
 522  0
                 additionalPermissionDetails.put(KimConstants.AttributeConstants.NAMESPACE_CODE, role.getNamespaceCode());
 523  0
                 additionalPermissionDetails.put(KimConstants.AttributeConstants.ROLE_NAME, role.getRoleName());
 524  0
                         if (!getDocumentHelperService().getDocumentAuthorizer(this).isAuthorizedByTemplate(
 525  
                                         this,
 526  
                                         KimConstants.NAMESPACE_CODE,
 527  
                                         KimConstants.PermissionTemplateNames.ASSIGN_ROLE,
 528  
                                         GlobalVariables.getUserSession().getPrincipalId(),
 529  
                                         additionalPermissionDetails, null)){
 530  0
                     rulePassed = false;
 531  
                         }
 532  
         }
 533  0
         return rulePassed;
 534  
         }
 535  
 
 536  
         @Transient
 537  
         protected transient DocumentHelperService documentHelperService;
 538  
         @Transient
 539  
         protected transient UiDocumentService uiDocumentService;
 540  
 
 541  
         protected DocumentHelperService getDocumentHelperService() {
 542  0
             if ( documentHelperService == null ) {
 543  0
                 documentHelperService = KRADServiceLocatorWeb.getDocumentHelperService();
 544  
                 }
 545  0
             return this.documentHelperService;
 546  
         }
 547  
 
 548  
         protected UiDocumentService getUiDocumentService() {
 549  0
             if (uiDocumentService == null ) {
 550  0
                     uiDocumentService = KIMServiceLocatorInternal.getUiDocumentService();
 551  
                 }
 552  0
             return this.uiDocumentService;
 553  
         }
 554  
 
 555  
 }