Coverage Report - org.kuali.rice.kim.document.IdentityManagementPersonDocument
 
Classes in this File Line Coverage Branch Coverage Complexity
IdentityManagementPersonDocument
0%
0/141
0%
0/48
1.533
 
 1  
 /*
 2  
  * Copyright 2007-2008 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 java.util.ArrayList;
 19  
 import java.util.HashMap;
 20  
 import java.util.List;
 21  
 import java.util.Map;
 22  
 
 23  
 import org.apache.commons.collections.CollectionUtils;
 24  
 import org.apache.commons.lang.StringUtils;
 25  
 import org.apache.ojb.broker.PersistenceBroker;
 26  
 import org.apache.ojb.broker.PersistenceBrokerException;
 27  
 import org.kuali.rice.kew.dto.DocumentRouteStatusChangeDTO;
 28  
 import org.kuali.rice.kim.bo.entity.dto.KimEntityEmploymentInformationInfo;
 29  
 import org.kuali.rice.kim.bo.impl.KimAttributes;
 30  
 import org.kuali.rice.kim.bo.role.dto.KimRoleInfo;
 31  
 import org.kuali.rice.kim.bo.types.dto.KimTypeInfo;
 32  
 import org.kuali.rice.kim.bo.ui.KimDocumentRoleMember;
 33  
 import org.kuali.rice.kim.bo.ui.KimDocumentRoleQualifier;
 34  
 import org.kuali.rice.kim.bo.ui.PersonDocumentAddress;
 35  
 import org.kuali.rice.kim.bo.ui.PersonDocumentAffiliation;
 36  
 import org.kuali.rice.kim.bo.ui.PersonDocumentCitizenship;
 37  
 import org.kuali.rice.kim.bo.ui.PersonDocumentEmail;
 38  
 import org.kuali.rice.kim.bo.ui.PersonDocumentEmploymentInfo;
 39  
 import org.kuali.rice.kim.bo.ui.PersonDocumentGroup;
 40  
 import org.kuali.rice.kim.bo.ui.PersonDocumentName;
 41  
 import org.kuali.rice.kim.bo.ui.PersonDocumentPhone;
 42  
 import org.kuali.rice.kim.bo.ui.PersonDocumentPrivacy;
 43  
 import org.kuali.rice.kim.bo.ui.PersonDocumentRole;
 44  
 import org.kuali.rice.kim.bo.ui.RoleDocumentDelegationMember;
 45  
 import org.kuali.rice.kim.bo.ui.RoleDocumentDelegationMemberQualifier;
 46  
 import org.kuali.rice.kim.service.KIMServiceLocator;
 47  
 import org.kuali.rice.kim.service.UiDocumentService;
 48  
 import org.kuali.rice.kim.util.KimCommonUtils;
 49  
 import org.kuali.rice.kim.util.KimConstants;
 50  
 import org.kuali.rice.kns.service.DocumentHelperService;
 51  
 import org.kuali.rice.kns.service.KNSServiceLocator;
 52  
 import org.kuali.rice.kns.util.GlobalVariables;
 53  
 
 54  
 /**
 55  
  * This is a description of what this class does - shyu don't forget to fill
 56  
  * this in.
 57  
  *
 58  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 59  
  *
 60  
  */
 61  
 public class IdentityManagementPersonDocument extends IdentityManagementKimDocument {
 62  
 
 63  
     protected static final long serialVersionUID = -534993712085516925L;
 64  
     // principal data
 65  
     protected String principalId;
 66  
     protected String principalName;   
 67  
     protected String entityId;
 68  
     protected String password;
 69  
 
 70  
     // ext id - now hard coded for "tax id" & "univ id"
 71  0
     protected String univId = "";
 72  
     // affiliation data
 73  
     protected List<PersonDocumentAffiliation> affiliations;
 74  
 
 75  0
     protected String campusCode = "";
 76  
     // external identifier data
 77  0
     protected Map<String, String> externalIdentifiers = null;
 78  
 
 79  
     protected boolean active;
 80  
 
 81  
     // citizenship
 82  
     protected List<PersonDocumentCitizenship> citizenships;
 83  
     // protected List<DocEmploymentInfo> employmentInformations;
 84  
     protected List<PersonDocumentName> names;
 85  
     protected List<PersonDocumentAddress> addrs;
 86  
     protected List<PersonDocumentPhone> phones;
 87  
     protected List<PersonDocumentEmail> emails;
 88  
     protected List<PersonDocumentGroup> groups;
 89  
     protected List<PersonDocumentRole> roles;
 90  
 
 91  
     protected PersonDocumentPrivacy privacy;
 92  
 
 93  0
     public IdentityManagementPersonDocument() {
 94  0
         affiliations = new ArrayList<PersonDocumentAffiliation>();
 95  0
         citizenships = new ArrayList<PersonDocumentCitizenship>();
 96  
         // employmentInformations = new ArrayList<DocEmploymentInfo>();
 97  0
         names = new ArrayList<PersonDocumentName>();
 98  0
         addrs = new ArrayList<PersonDocumentAddress>();
 99  0
         phones = new ArrayList<PersonDocumentPhone>();
 100  0
         emails = new ArrayList<PersonDocumentEmail>();
 101  0
         groups = new ArrayList<PersonDocumentGroup>();
 102  0
         roles = new ArrayList<PersonDocumentRole>();
 103  0
         privacy = new PersonDocumentPrivacy();
 104  0
         this.active = true;
 105  
         // privacy.setDocumentNumber(documentNumber);
 106  0
     }
 107  
 
 108  
     public String getPrincipalId() {
 109  0
         return this.principalId;
 110  
     }
 111  
 
 112  
     public void setPrincipalId(String principalId) {
 113  0
         this.principalId = principalId;
 114  0
     }
 115  
 
 116  
     public String getPrincipalName() {
 117  0
         return this.principalName;
 118  
     }
 119  
 
 120  
     /*
 121  
      * sets the principal name.  
 122  
      * Principal names are converted to lower case.
 123  
      */
 124  
     public void setPrincipalName(String principalName) {
 125  0
         this.principalName = principalName; // != null ? principalName.toLowerCase() : principalName ;
 126  0
     }
 127  
 
 128  
     public String getEntityId() {
 129  0
         return this.entityId;
 130  
     }
 131  
 
 132  
     public void setEntityId(String entityId) {
 133  0
         this.entityId = entityId;
 134  0
     }
 135  
 
 136  
     public List<PersonDocumentAffiliation> getAffiliations() {
 137  0
         return this.affiliations;
 138  
     }
 139  
 
 140  
     public void setAffiliations(List<PersonDocumentAffiliation> affiliations) {
 141  0
         this.affiliations = affiliations;
 142  0
     }
 143  
 
 144  
     public String getCampusCode() {
 145  0
         return this.campusCode;
 146  
     }
 147  
 
 148  
     public void setCampusCode(String campusCode) {
 149  0
         this.campusCode = campusCode;
 150  0
     }
 151  
 
 152  
     public Map<String, String> getExternalIdentifiers() {
 153  0
         return this.externalIdentifiers;
 154  
     }
 155  
 
 156  
     public void setExternalIdentifiers(Map<String, String> externalIdentifiers) {
 157  0
         this.externalIdentifiers = externalIdentifiers;
 158  0
     }
 159  
 
 160  
     public String getPassword() {
 161  0
         return this.password;
 162  
     }
 163  
 
 164  
     public void setPassword(String password) {
 165  0
         this.password = password;
 166  0
     }
 167  
 
 168  
     public boolean isActive() {
 169  0
         return this.active;
 170  
     }
 171  
 
 172  
     public void setActive(boolean active) {
 173  0
         this.active = active;
 174  0
     }
 175  
 
 176  
     public List<PersonDocumentCitizenship> getCitizenships() {
 177  0
         return this.citizenships;
 178  
     }
 179  
 
 180  
     public void setCitizenships(List<PersonDocumentCitizenship> citizenships) {
 181  0
         this.citizenships = citizenships;
 182  0
     }
 183  
 
 184  
     public List<PersonDocumentName> getNames() {
 185  0
         return this.names;
 186  
     }
 187  
 
 188  
     public void setNames(List<PersonDocumentName> names) {
 189  0
         this.names = names;
 190  0
     }
 191  
 
 192  
     public List<PersonDocumentAddress> getAddrs() {
 193  0
         return this.addrs;
 194  
     }
 195  
 
 196  
     public void setAddrs(List<PersonDocumentAddress> addrs) {
 197  0
         this.addrs = addrs;
 198  0
     }
 199  
 
 200  
     public List<PersonDocumentPhone> getPhones() {
 201  0
         return this.phones;
 202  
     }
 203  
 
 204  
     public void setPhones(List<PersonDocumentPhone> phones) {
 205  0
         this.phones = phones;
 206  0
     }
 207  
 
 208  
     public List<PersonDocumentEmail> getEmails() {
 209  0
         return this.emails;
 210  
     }
 211  
 
 212  
     public void setEmails(List<PersonDocumentEmail> emails) {
 213  0
         this.emails = emails;
 214  0
     }
 215  
 
 216  
     public void setGroups(List<PersonDocumentGroup> groups) {
 217  0
         this.groups = groups;
 218  0
     }
 219  
 
 220  
     public List<PersonDocumentRole> getRoles() {
 221  0
         return this.roles;
 222  
     }
 223  
 
 224  
     public void setRoles(List<PersonDocumentRole> roles) {
 225  0
         this.roles = roles;
 226  0
     }
 227  
 
 228  
     public List<PersonDocumentGroup> getGroups() {
 229  0
         return this.groups;
 230  
     }
 231  
 
 232  
     public String getUnivId() {
 233  0
         return this.univId;
 234  
     }
 235  
 
 236  
     public void setUnivId(String univId) {
 237  0
         this.univId = univId;
 238  0
     }
 239  
 
 240  
     public PersonDocumentPrivacy getPrivacy() {
 241  0
         return this.privacy;
 242  
     }
 243  
 
 244  
     public void setPrivacy(PersonDocumentPrivacy privacy) {
 245  0
         this.privacy = privacy;
 246  0
     }
 247  
 
 248  
     public void initializeDocumentForNewPerson() {
 249  0
         if(StringUtils.isBlank(this.principalId)){
 250  0
             this.principalId = getSequenceAccessorService().getNextAvailableSequenceNumber(KimConstants.SequenceNames.KRIM_PRNCPL_ID_S).toString();
 251  
         }
 252  0
         if(StringUtils.isBlank(this.entityId)){
 253  0
             this.entityId = getSequenceAccessorService().getNextAvailableSequenceNumber(KimConstants.SequenceNames.KRIM_ENTITY_ID_S).toString();
 254  
         }
 255  0
     }
 256  
 
 257  
     @SuppressWarnings("unchecked")
 258  
     @Override
 259  
     public List buildListOfDeletionAwareLists() {
 260  0
         List managedLists = super.buildListOfDeletionAwareLists();
 261  0
         List<PersonDocumentEmploymentInfo> empInfos = new ArrayList<PersonDocumentEmploymentInfo>();
 262  0
         for (PersonDocumentAffiliation affiliation : getAffiliations()) {
 263  0
             empInfos.addAll(affiliation.getEmpInfos());
 264  
         }
 265  
 
 266  0
         managedLists.add(empInfos);
 267  0
         managedLists.add(getAffiliations());
 268  0
         managedLists.add(getCitizenships());
 269  0
         managedLists.add(getPhones());
 270  0
         managedLists.add(getAddrs());
 271  0
         managedLists.add(getEmails());
 272  0
         managedLists.add(getNames());
 273  0
         managedLists.add(getGroups());
 274  0
         managedLists.add(getRoles());
 275  0
         return managedLists;
 276  
     }
 277  
 
 278  
     /**
 279  
      * @see org.kuali.rice.kns.document.DocumentBase#doRouteStatusChange(org.kuali.rice.kew.dto.DocumentRouteStatusChangeDTO)
 280  
      */
 281  
     @Override
 282  
     public void doRouteStatusChange(DocumentRouteStatusChangeDTO statusChangeEvent) {
 283  0
         super.doRouteStatusChange(statusChangeEvent);
 284  0
         if (getDocumentHeader().getWorkflowDocument().stateIsProcessed()) {
 285  0
                 setIfRolesEditable();
 286  0
             KIMServiceLocator.getUiDocumentService().saveEntityPerson(this);
 287  
         }
 288  0
     }
 289  
 
 290  
 
 291  
     @Override
 292  
     public void prepareForSave(){
 293  0
         if (StringUtils.isBlank(getPrivacy().getDocumentNumber())) {
 294  0
             getPrivacy().setDocumentNumber(
 295  
                     getDocumentNumber());
 296  
         }
 297  0
         setEmployeeRecordIds();
 298  0
         for (PersonDocumentRole role : getRoles()) {
 299  0
             for (KimDocumentRoleMember rolePrncpl : role.getRolePrncpls()) {
 300  0
                 rolePrncpl.setDocumentNumber(getDocumentNumber());
 301  0
                 for (KimDocumentRoleQualifier qualifier : rolePrncpl.getQualifiers()) {
 302  0
                     qualifier.setDocumentNumber(getDocumentNumber());
 303  0
                     qualifier.setKimTypId(role.getKimTypeId());
 304  
                 }
 305  
             }
 306  
         }
 307  0
         if(getDelegationMembers()!=null){
 308  0
             for(RoleDocumentDelegationMember delegationMember: getDelegationMembers()){
 309  0
                 delegationMember.setDocumentNumber(getDocumentNumber());
 310  0
                 for (RoleDocumentDelegationMemberQualifier qualifier: delegationMember.getQualifiers()) {
 311  0
                     qualifier.setDocumentNumber(getDocumentNumber());
 312  0
                     qualifier.setKimTypId(delegationMember.getRoleImpl().getKimTypeId());
 313  
                 }
 314  0
                 addDelegationMemberToDelegation(delegationMember);
 315  
             }
 316  
         }
 317  0
     }
 318  
 
 319  
     protected void setEmployeeRecordIds(){
 320  0
             List<KimEntityEmploymentInformationInfo> empInfos = getUiDocumentService().getEntityEmploymentInformationInfo(getEntityId());
 321  0
         for(PersonDocumentAffiliation affiliation: getAffiliations()) {
 322  0
             int employeeRecordCounter = CollectionUtils.isEmpty(empInfos) ? 0 : empInfos.size();
 323  0
             for(PersonDocumentEmploymentInfo empInfo: affiliation.getEmpInfos()){
 324  0
                 if(CollectionUtils.isNotEmpty(empInfos)){
 325  0
                     for(KimEntityEmploymentInformationInfo origEmpInfo: empInfos){
 326  0
                         if (origEmpInfo.getEntityEmploymentId().equals(empInfo.getEntityEmploymentId())) {
 327  0
                             empInfo.setEmploymentRecordId(origEmpInfo.getEmploymentRecordId());
 328  
                         }
 329  
                     }
 330  
                 }
 331  0
                 if(StringUtils.isEmpty(empInfo.getEmploymentRecordId())){
 332  0
                     employeeRecordCounter++;
 333  0
                     empInfo.setEmploymentRecordId(employeeRecordCounter+"");
 334  
                 }
 335  
             }
 336  0
         }
 337  0
     }
 338  
 
 339  
     public KimTypeAttributesHelper getKimTypeAttributesHelper(String roleId) {
 340  0
         KimRoleInfo roleInfo = KIMServiceLocator.getRoleService().getRole(roleId);
 341  0
         KimTypeInfo kimTypeInfo = KIMServiceLocator.getTypeInfoService().getKimType(roleInfo.getKimTypeId());
 342  0
         return new KimTypeAttributesHelper(kimTypeInfo);
 343  
         //addDelegationRoleKimTypeAttributeHelper(roleId, helper);
 344  
     }
 345  
 
 346  
         public void setIfRolesEditable(){
 347  0
                 if(CollectionUtils.isNotEmpty(getRoles())){
 348  0
                         for(PersonDocumentRole role: getRoles()){
 349  0
                                 role.setEditable(validAssignRole(role));
 350  
                         }
 351  
                 }
 352  0
         }
 353  
 
 354  
         public boolean validAssignRole(PersonDocumentRole role){
 355  0
         boolean rulePassed = true;
 356  0
         if(StringUtils.isNotEmpty(role.getNamespaceCode())){
 357  0
                 Map<String,String> additionalPermissionDetails = new HashMap<String,String>();
 358  0
                 additionalPermissionDetails.put(KimAttributes.NAMESPACE_CODE, role.getNamespaceCode());
 359  0
                 additionalPermissionDetails.put(KimAttributes.ROLE_NAME, role.getRoleName());
 360  0
                         if (!getDocumentHelperService().getDocumentAuthorizer(this).isAuthorizedByTemplate(
 361  
                                         this,
 362  
                                         KimConstants.NAMESPACE_CODE,
 363  
                                         KimConstants.PermissionTemplateNames.ASSIGN_ROLE,
 364  
                                         GlobalVariables.getUserSession().getPrincipalId(),
 365  
                                         additionalPermissionDetails, null)){
 366  0
                     rulePassed = false;
 367  
                         }
 368  
         }
 369  0
         return rulePassed;
 370  
         }
 371  
 
 372  
         protected transient DocumentHelperService documentHelperService;
 373  
         protected transient UiDocumentService uiDocumentService;
 374  
 
 375  
         protected DocumentHelperService getDocumentHelperService() {
 376  0
             if ( documentHelperService == null ) {
 377  0
                 documentHelperService = KNSServiceLocator.getDocumentHelperService();
 378  
                 }
 379  0
             return this.documentHelperService;
 380  
         }
 381  
 
 382  
         protected UiDocumentService getUiDocumentService() {
 383  0
             if (uiDocumentService == null ) {
 384  0
                     uiDocumentService = KIMServiceLocator.getUiDocumentService();
 385  
                 }
 386  0
             return this.uiDocumentService;
 387  
         }
 388  
 
 389  
 }