| 1 |  |   | 
  | 2 |  |   | 
  | 3 |  |   | 
  | 4 |  |   | 
  | 5 |  |   | 
  | 6 |  |   | 
  | 7 |  |   | 
  | 8 |  |   | 
  | 9 |  |   | 
  | 10 |  |   | 
  | 11 |  |   | 
  | 12 |  |   | 
  | 13 |  |   | 
  | 14 |  |   | 
  | 15 |  |   | 
  | 16 |  |  package org.kuali.rice.kim.document.rule; | 
  | 17 |  |   | 
  | 18 |  |  import java.sql.Timestamp; | 
  | 19 |  |  import java.util.ArrayList; | 
  | 20 |  |  import java.util.HashMap; | 
  | 21 |  |  import java.util.HashSet; | 
  | 22 |  |  import java.util.List; | 
  | 23 |  |  import java.util.Map; | 
  | 24 |  |  import java.util.Set; | 
  | 25 |  |   | 
  | 26 |  |  import org.apache.commons.collections.CollectionUtils; | 
  | 27 |  |  import org.apache.commons.lang.StringUtils; | 
  | 28 |  |  import org.kuali.rice.core.util.RiceKeyConstants; | 
  | 29 |  |  import org.kuali.rice.core.xml.dto.AttributeSet; | 
  | 30 |  |  import org.kuali.rice.kim.bo.entity.KimPrincipal; | 
  | 31 |  |  import org.kuali.rice.kim.bo.entity.dto.KimEntityDefaultInfo; | 
  | 32 |  |  import org.kuali.rice.kim.bo.entity.impl.KimPrincipalImpl; | 
  | 33 |  |  import org.kuali.rice.kim.bo.role.impl.RoleMemberImpl; | 
  | 34 |  |  import org.kuali.rice.kim.bo.types.dto.AttributeDefinitionMap; | 
  | 35 |  |  import org.kuali.rice.kim.bo.types.dto.KimTypeInfo; | 
  | 36 |  |  import org.kuali.rice.kim.bo.ui.KimDocumentRoleMember; | 
  | 37 |  |  import org.kuali.rice.kim.bo.ui.KimDocumentRoleQualifier; | 
  | 38 |  |  import org.kuali.rice.kim.bo.ui.PersonDocumentAffiliation; | 
  | 39 |  |  import org.kuali.rice.kim.bo.ui.PersonDocumentBoDefaultBase; | 
  | 40 |  |  import org.kuali.rice.kim.bo.ui.PersonDocumentEmploymentInfo; | 
  | 41 |  |  import org.kuali.rice.kim.bo.ui.PersonDocumentGroup; | 
  | 42 |  |  import org.kuali.rice.kim.bo.ui.PersonDocumentName; | 
  | 43 |  |  import org.kuali.rice.kim.bo.ui.PersonDocumentRole; | 
  | 44 |  |  import org.kuali.rice.kim.bo.ui.RoleDocumentDelegationMember; | 
  | 45 |  |  import org.kuali.rice.kim.document.IdentityManagementPersonDocument; | 
  | 46 |  |  import org.kuali.rice.kim.document.authorization.IdentityManagementKimDocumentAuthorizer; | 
  | 47 |  |  import org.kuali.rice.kim.rule.event.ui.AddGroupEvent; | 
  | 48 |  |  import org.kuali.rice.kim.rule.event.ui.AddPersonDelegationMemberEvent; | 
  | 49 |  |  import org.kuali.rice.kim.rule.event.ui.AddRoleEvent; | 
  | 50 |  |  import org.kuali.rice.kim.rule.ui.AddGroupRule; | 
  | 51 |  |  import org.kuali.rice.kim.rule.ui.AddPersonDelegationMemberRule; | 
  | 52 |  |  import org.kuali.rice.kim.rule.ui.AddPersonDocumentRoleQualifierRule; | 
  | 53 |  |  import org.kuali.rice.kim.rule.ui.AddRoleRule; | 
  | 54 |  |  import org.kuali.rice.kim.rules.ui.PersonDocumentDelegationMemberRule; | 
  | 55 |  |  import org.kuali.rice.kim.rules.ui.PersonDocumentGroupRule; | 
  | 56 |  |  import org.kuali.rice.kim.rules.ui.PersonDocumentRoleRule; | 
  | 57 |  |  import org.kuali.rice.kim.service.*; | 
  | 58 |  |  import org.kuali.rice.kim.service.support.KimTypeService; | 
  | 59 |  |  import org.kuali.rice.kim.util.KIMPropertyConstants; | 
  | 60 |  |  import org.kuali.rice.kns.datadictionary.AttributeDefinition; | 
  | 61 |  |  import org.kuali.rice.kns.document.Document; | 
  | 62 |  |  import org.kuali.rice.kns.rules.TransactionalDocumentRuleBase; | 
  | 63 |  |  import org.kuali.rice.kns.service.BusinessObjectService; | 
  | 64 |  |  import org.kuali.rice.kns.service.KNSServiceLocator; | 
  | 65 |  |  import org.kuali.rice.kns.service.KNSServiceLocatorWeb; | 
  | 66 |  |  import org.kuali.rice.kns.util.GlobalVariables; | 
  | 67 |  |  import org.kuali.rice.kns.util.KNSConstants; | 
  | 68 |  |  import org.kuali.rice.kns.util.ObjectUtils; | 
  | 69 |  |   | 
  | 70 |  |   | 
  | 71 |  |   | 
  | 72 |  |   | 
  | 73 |  |   | 
  | 74 |  |   | 
  | 75 |  |   | 
  | 76 | 0 |  public class IdentityManagementPersonDocumentRule extends TransactionalDocumentRuleBase implements AddGroupRule, AddRoleRule, AddPersonDocumentRoleQualifierRule, AddPersonDelegationMemberRule { | 
  | 77 |  |   | 
  | 78 |  |   | 
  | 79 |  |   | 
  | 80 |  |          protected AddGroupRule addGroupRule; | 
  | 81 |  |          protected AddRoleRule  addRoleRule; | 
  | 82 |  |          protected AddPersonDelegationMemberRule addPersonDelegationMemberRule; | 
  | 83 |  |          protected IdentityManagementKimDocumentAuthorizer authorizer; | 
  | 84 |  |          protected BusinessObjectService businessObjectService; | 
  | 85 |  |          protected IdentityService identityService; | 
  | 86 |  |          protected RoleService roleService; | 
  | 87 |  |          protected UiDocumentService uiDocumentService; | 
  | 88 | 0 |          protected Class<? extends AddGroupRule> addGroupRuleClass = PersonDocumentGroupRule.class; | 
  | 89 | 0 |          protected Class<? extends AddRoleRule> addRoleRuleClass = PersonDocumentRoleRule.class; | 
  | 90 | 0 |          protected Class<? extends AddPersonDelegationMemberRule> addPersonDelegationMemberRuleClass = PersonDocumentDelegationMemberRule.class; | 
  | 91 |  |   | 
  | 92 | 0 |          protected AttributeValidationHelper attributeValidationHelper = new AttributeValidationHelper(); | 
  | 93 |  |   | 
  | 94 |  |      @Override | 
  | 95 |  |      protected boolean processCustomSaveDocumentBusinessRules(Document document) { | 
  | 96 | 0 |          if (!(document instanceof IdentityManagementPersonDocument)) { | 
  | 97 | 0 |              return false; | 
  | 98 |  |          } | 
  | 99 |  |   | 
  | 100 | 0 |          IdentityManagementPersonDocument personDoc = (IdentityManagementPersonDocument)document; | 
  | 101 | 0 |          boolean valid = true; | 
  | 102 |  |   | 
  | 103 | 0 |          GlobalVariables.getMessageMap().addToErrorPath(KNSConstants.DOCUMENT_PROPERTY_NAME); | 
  | 104 |  |   | 
  | 105 |  |           | 
  | 106 | 0 |          getDictionaryValidationService().validateDocumentAndUpdatableReferencesRecursively(document, getMaxDictionaryValidationDepth(), true, false); | 
  | 107 | 0 |          valid &= validDuplicatePrincipalName(personDoc); | 
  | 108 | 0 |          KimEntityDefaultInfo origEntity = getIdentityManagementService().getEntityDefaultInfo(personDoc.getEntityId()); | 
  | 109 | 0 |          boolean isCreatingNew = origEntity==null?true:false; | 
  | 110 | 0 |          if(getUIDocumentService().canModifyEntity(GlobalVariables.getUserSession().getPrincipalId(), personDoc.getPrincipalId()) || isCreatingNew) | 
  | 111 | 0 |                  valid &= validateEntityInformation(isCreatingNew, personDoc); | 
  | 112 |  |           | 
  | 113 | 0 |          valid &= validateRoleQualifier (personDoc.getRoles()); | 
  | 114 | 0 |          valid &= validateDelegationMemberRoleQualifier(personDoc.getDelegationMembers()); | 
  | 115 | 0 |          if (StringUtils.isNotBlank(personDoc.getPrincipalName())) { | 
  | 116 | 0 |                  valid &= doesPrincipalNameExist (personDoc.getPrincipalName(), personDoc.getPrincipalId()); | 
  | 117 |  |          } | 
  | 118 |  |   | 
  | 119 | 0 |          valid &= validActiveDatesForRole (personDoc.getRoles()); | 
  | 120 | 0 |          valid &= validActiveDatesForGroup (personDoc.getGroups()); | 
  | 121 | 0 |          valid &= validActiveDatesForDelegations (personDoc.getDelegationMembers()); | 
  | 122 |  |   | 
  | 123 |  |   | 
  | 124 |  |           | 
  | 125 |  |   | 
  | 126 |  |   | 
  | 127 |  |   | 
  | 128 | 0 |          GlobalVariables.getMessageMap().removeFromErrorPath(KNSConstants.DOCUMENT_PROPERTY_NAME); | 
  | 129 |  |   | 
  | 130 | 0 |          return valid; | 
  | 131 |  |      } | 
  | 132 |  |   | 
  | 133 |  |      protected boolean validateEntityInformation(boolean isCreatingNew, IdentityManagementPersonDocument personDoc){ | 
  | 134 | 0 |          boolean valid = true; | 
  | 135 | 0 |          boolean canOverridePrivacyPreferences = getUIDocumentService().canOverrideEntityPrivacyPreferences(GlobalVariables.getUserSession().getPrincipalId(), personDoc.getPrincipalId()); | 
  | 136 | 0 |          valid &= checkMultipleDefault (personDoc.getAffiliations(), "affiliations"); | 
  | 137 | 0 |          if(isCreatingNew || canOverridePrivacyPreferences || !personDoc.getPrivacy().isSuppressName()) | 
  | 138 | 0 |                  valid &= checkMultipleDefault (personDoc.getNames(), "names"); | 
  | 139 | 0 |          if(isCreatingNew || canOverridePrivacyPreferences || !personDoc.getPrivacy().isSuppressAddress()) | 
  | 140 | 0 |                  valid &= checkMultipleDefault (personDoc.getAddrs(), "addrs"); | 
  | 141 | 0 |          if(isCreatingNew || canOverridePrivacyPreferences || !personDoc.getPrivacy().isSuppressPhone()) | 
  | 142 | 0 |                  valid &= checkMultipleDefault (personDoc.getPhones(), "phones"); | 
  | 143 | 0 |          if(isCreatingNew || canOverridePrivacyPreferences || !personDoc.getPrivacy().isSuppressEmail()) | 
  | 144 | 0 |                  valid &= checkMultipleDefault (personDoc.getEmails(), "emails"); | 
  | 145 | 0 |          valid &= checkPrimaryEmploymentInfo (personDoc.getAffiliations()); | 
  | 146 | 0 |          valid &= validEmployeeIDForAffiliation(personDoc.getAffiliations()); | 
  | 147 | 0 |          valid &= checkAffiliationTypeChange (personDoc.getAffiliations()); | 
  | 148 | 0 |          valid &= checkUniqueAffiliationTypePerCampus(personDoc.getAffiliations()); | 
  | 149 | 0 |              return valid; | 
  | 150 |  |      } | 
  | 151 |  |   | 
  | 152 |  |      @SuppressWarnings("unchecked") | 
  | 153 |  |          protected boolean validDuplicatePrincipalName(IdentityManagementPersonDocument personDoc){ | 
  | 154 | 0 |              Map<String, String> criteria = new HashMap<String, String>(); | 
  | 155 | 0 |              criteria.put("principalName", personDoc.getPrincipalName()); | 
  | 156 | 0 |              List<KimPrincipalImpl> prncplImpls = (List<KimPrincipalImpl>)getBusinessObjectService().findMatching(KimPrincipalImpl.class, criteria); | 
  | 157 | 0 |              boolean rulePassed = true; | 
  | 158 | 0 |              if(prncplImpls!=null && prncplImpls.size()>0){ | 
  | 159 | 0 |                      if(prncplImpls.size()==1 && prncplImpls.get(0).getPrincipalId().equals(personDoc.getPrincipalId())) | 
  | 160 | 0 |                              rulePassed = true; | 
  | 161 |  |                      else{ | 
  | 162 | 0 |                              GlobalVariables.getMessageMap().putError("document.principalName", | 
  | 163 |  |                                              RiceKeyConstants.ERROR_DUPLICATE_ENTRY, new String[] {"Principal Name"}); | 
  | 164 | 0 |                              rulePassed = false; | 
  | 165 |  |                      } | 
  | 166 |  |              } | 
  | 167 | 0 |              return rulePassed; | 
  | 168 |  |      } | 
  | 169 |  |   | 
  | 170 |  |          protected boolean checkUnassignableRoles(IdentityManagementPersonDocument document) { | 
  | 171 | 0 |                  boolean valid = true; | 
  | 172 | 0 |              Map<String,Set<String>> unassignableRoles = getAuthorizer( document ).getUnassignableRoles(document, GlobalVariables.getUserSession().getPerson()); | 
  | 173 | 0 |          for (String namespaceCode : unassignableRoles.keySet()) { | 
  | 174 | 0 |                  for (String roleName : unassignableRoles.get(namespaceCode)) { | 
  | 175 | 0 |                          int i = 0; | 
  | 176 | 0 |                          for (PersonDocumentRole role : document.getRoles()) { | 
  | 177 | 0 |                                  if (role.isEditable() && namespaceCode.endsWith(role.getNamespaceCode()) && roleName.equals(role.getRoleName())) { | 
  | 178 | 0 |                                          GlobalVariables.getMessageMap().putError("roles["+i+"].roleId", RiceKeyConstants.ERROR_ASSIGN_ROLE, new String[] {namespaceCode, roleName}); | 
  | 179 | 0 |                                  valid = false; | 
  | 180 |  |                                  } | 
  | 181 | 0 |                                  i++; | 
  | 182 |  |                          } | 
  | 183 | 0 |                  } | 
  | 184 |  |          } | 
  | 185 | 0 |          return valid; | 
  | 186 |  |          } | 
  | 187 |  |   | 
  | 188 |  |          protected boolean checkUnpopulatableGroups(IdentityManagementPersonDocument document) { | 
  | 189 | 0 |                  boolean valid = true; | 
  | 190 | 0 |              Map<String,Set<String>> unpopulatableGroups = getAuthorizer( document ).getUnpopulateableGroups(document, GlobalVariables.getUserSession().getPerson()); | 
  | 191 | 0 |          for (String namespaceCode : unpopulatableGroups.keySet()) { | 
  | 192 | 0 |                  for (String groupName : unpopulatableGroups.get(namespaceCode)) { | 
  | 193 | 0 |                          int i = 0; | 
  | 194 | 0 |                          for (PersonDocumentGroup group : document.getGroups()) { | 
  | 195 | 0 |                                  if ( (group.getNamespaceCode() != null && namespaceCode.endsWith(group.getNamespaceCode())) && (group.getGroupName() != null && groupName.equals(group.getGroupName()))) { | 
  | 196 | 0 |                                          GlobalVariables.getMessageMap().putError("groups["+i+"].groupId", RiceKeyConstants.ERROR_POPULATE_GROUP, new String[] {namespaceCode, groupName}); | 
  | 197 |  |                                  } | 
  | 198 | 0 |                                  i++; | 
  | 199 |  |                          } | 
  | 200 | 0 |                  } | 
  | 201 | 0 |                  valid = false; | 
  | 202 |  |          } | 
  | 203 | 0 |          return valid; | 
  | 204 |  |          } | 
  | 205 |  |   | 
  | 206 |  |      @Override | 
  | 207 |  |          protected boolean processCustomRouteDocumentBusinessRules(Document document) { | 
  | 208 | 0 |                  super.processCustomRouteDocumentBusinessRules(document); | 
  | 209 | 0 |          IdentityManagementPersonDocument personDoc = (IdentityManagementPersonDocument)document; | 
  | 210 | 0 |          boolean valid = true; | 
  | 211 | 0 |          GlobalVariables.getMessageMap().addToErrorPath(KNSConstants.DOCUMENT_PROPERTY_NAME); | 
  | 212 | 0 |          valid &= validateAffiliationAndName( personDoc ); | 
  | 213 | 0 |          valid &= checkAffiliationEithOneEMpInfo (personDoc.getAffiliations()); | 
  | 214 | 0 |          GlobalVariables.getMessageMap().removeFromErrorPath(KNSConstants.DOCUMENT_PROPERTY_NAME); | 
  | 215 |  |   | 
  | 216 | 0 |          return valid; | 
  | 217 |  |          } | 
  | 218 |  |   | 
  | 219 |  |   | 
  | 220 |  |          protected boolean checkMultipleDefault (List <? extends PersonDocumentBoDefaultBase> boList, String listName) { | 
  | 221 | 0 |              boolean valid = true; | 
  | 222 | 0 |              boolean isDefaultSet = false; | 
  | 223 | 0 |              int i = 0; | 
  | 224 | 0 |              for (PersonDocumentBoDefaultBase item : boList) { | 
  | 225 | 0 |                       if (item.isDflt()) { | 
  | 226 | 0 |                               if (isDefaultSet) { | 
  | 227 | 0 |                                       GlobalVariables.getMessageMap().putError(listName+"[" + i + "].dflt",RiceKeyConstants.ERROR_MULTIPLE_DEFAULT_SELETION); | 
  | 228 | 0 |                                       valid = false; | 
  | 229 |  |                               } else { | 
  | 230 | 0 |                                       isDefaultSet = true; | 
  | 231 |  |                               } | 
  | 232 |  |                       } | 
  | 233 | 0 |                       i++; | 
  | 234 |  |              } | 
  | 235 | 0 |              if (!boList.isEmpty() && !isDefaultSet) { | 
  | 236 | 0 |                                  GlobalVariables.getMessageMap().putError(listName+"[0].dflt",RiceKeyConstants.ERROR_NO_DEFAULT_SELETION); | 
  | 237 |  |              } | 
  | 238 | 0 |              return valid; | 
  | 239 |  |      } | 
  | 240 |  |   | 
  | 241 |  |      protected boolean checkPrimaryEmploymentInfo (List <PersonDocumentAffiliation> affiliations) { | 
  | 242 | 0 |              boolean valid = true; | 
  | 243 | 0 |              int i = 0; | 
  | 244 | 0 |              int firstAfflnCounter = -1; | 
  | 245 | 0 |              boolean isPrimarySet = false; | 
  | 246 | 0 |              for (PersonDocumentAffiliation affiliation : affiliations) { | 
  | 247 | 0 |                      int j = 0; | 
  | 248 | 0 |                      for (PersonDocumentEmploymentInfo empInfo : affiliation.getEmpInfos()) { | 
  | 249 | 0 |                               if(firstAfflnCounter==-1) | 
  | 250 | 0 |                                       firstAfflnCounter = i; | 
  | 251 | 0 |                              if (empInfo.isPrimary()) { | 
  | 252 | 0 |                                       if (isPrimarySet) { | 
  | 253 |  |                                                | 
  | 254 | 0 |                                               GlobalVariables.getMessageMap().putError("affiliations[" + i + "].empInfos["+ j +"].primary",RiceKeyConstants.ERROR_MULTIPLE_PRIMARY_EMPLOYMENT); | 
  | 255 | 0 |                                               valid = false; | 
  | 256 |  |                                       } else { | 
  | 257 | 0 |                                               isPrimarySet = true; | 
  | 258 |  |                                       } | 
  | 259 | 0 |                                       j++; | 
  | 260 |  |                               } | 
  | 261 |  |                      } | 
  | 262 | 0 |                       i++; | 
  | 263 | 0 |              } | 
  | 264 | 0 |              if(!isPrimarySet && firstAfflnCounter!=-1){ | 
  | 265 | 0 |                      GlobalVariables.getMessageMap().putError("affiliations[" + firstAfflnCounter + "].empInfos[0].primary",RiceKeyConstants.ERROR_NO_PRIMARY_EMPLOYMENT); | 
  | 266 | 0 |                      valid = false; | 
  | 267 |  |              } | 
  | 268 | 0 |              return valid; | 
  | 269 |  |      } | 
  | 270 |  |   | 
  | 271 |  |      protected boolean checkAffiliationTypeChange (List <PersonDocumentAffiliation> affiliations) { | 
  | 272 | 0 |              boolean valid = true; | 
  | 273 | 0 |              int i = 0; | 
  | 274 | 0 |              for (PersonDocumentAffiliation affiliation : affiliations) { | 
  | 275 | 0 |                      if (affiliation.getAffiliationType() != null && !affiliation.getAffiliationTypeCode().equals(affiliation.getAffiliationType().getAffiliationTypeCode())) { | 
  | 276 | 0 |                              PersonDocumentAffiliation copiedAffiliation = (PersonDocumentAffiliation)ObjectUtils.deepCopy(affiliation); | 
  | 277 | 0 |                              copiedAffiliation.refreshReferenceObject("affiliationType"); | 
  | 278 | 0 |                              if (!copiedAffiliation.getAffiliationType().isEmploymentAffiliationType() && affiliation.getAffiliationType().isEmploymentAffiliationType() && !copiedAffiliation.getEmpInfos().isEmpty()) { | 
  | 279 | 0 |                                       GlobalVariables.getMessageMap().putError("affiliations[" + i + "].affiliationTypeCode",RiceKeyConstants.ERROR_NOT_EMPLOYMENT_AFFILIATION_TYPE,new String[] {affiliation.getAffiliationType().getAffiliationTypeName(), copiedAffiliation.getAffiliationType().getAffiliationTypeName()}); | 
  | 280 | 0 |                                       valid = false; | 
  | 281 |  |                              } | 
  | 282 |  |                      } | 
  | 283 | 0 |                  i++; | 
  | 284 |  |              } | 
  | 285 | 0 |              return valid; | 
  | 286 |  |      } | 
  | 287 |  |   | 
  | 288 |  |      protected boolean validEmployeeIDForAffiliation(List <PersonDocumentAffiliation> affiliations) { | 
  | 289 | 0 |              boolean valid = true; | 
  | 290 | 0 |              int i = 0; | 
  | 291 | 0 |              int j = 0; | 
  | 292 | 0 |              for(PersonDocumentAffiliation affiliation : affiliations) { | 
  | 293 | 0 |                      if(affiliation.getAffiliationType() != null && affiliation.getAffiliationType().isEmploymentAffiliationType()){ | 
  | 294 | 0 |                              if(affiliation.getEmpInfos()!=null){ | 
  | 295 | 0 |                                  j = 0; | 
  | 296 | 0 |                                  for (PersonDocumentEmploymentInfo empInfo : affiliation.getEmpInfos()) { | 
  | 297 | 0 |                                          if (StringUtils.isEmpty(empInfo.getEmployeeId())) { | 
  | 298 | 0 |                                                          GlobalVariables.getMessageMap().putError("affiliations[" + i + "].empInfos["+ j +"].employeeId", RiceKeyConstants.ERROR_REQUIRED_CONDITIONALLY, new String[] {"Employee ID", "an employee"}); | 
  | 299 | 0 |                                                          valid = false; | 
  | 300 | 0 |                                                   j++; | 
  | 301 |  |                                           } | 
  | 302 |  |                                  } | 
  | 303 |  |                              } | 
  | 304 |  |                      } | 
  | 305 | 0 |                  i++; | 
  | 306 |  |              } | 
  | 307 | 0 |              return valid; | 
  | 308 |  |      } | 
  | 309 |  |   | 
  | 310 |  |      protected boolean isPersonAnEmployee(List<PersonDocumentAffiliation> affiliations){ | 
  | 311 | 0 |              boolean isEmployee = false; | 
  | 312 | 0 |              for (PersonDocumentAffiliation affiliation : affiliations){ | 
  | 313 | 0 |                      if (affiliation.getAffiliationType() != null && affiliation.getAffiliationType().isEmploymentAffiliationType()){ | 
  | 314 | 0 |                              isEmployee = true; | 
  | 315 | 0 |                              break; | 
  | 316 |  |                      } | 
  | 317 |  |              } | 
  | 318 | 0 |              return isEmployee; | 
  | 319 |  |      } | 
  | 320 |  |   | 
  | 321 |  |      protected boolean checkUniqueAffiliationTypePerCampus (List <PersonDocumentAffiliation> affiliations) { | 
  | 322 | 0 |              boolean valid = true; | 
  | 323 | 0 |              int i = 0; | 
  | 324 | 0 |              for (PersonDocumentAffiliation affiliation : affiliations) { | 
  | 325 | 0 |                      int j = 0; | 
  | 326 | 0 |                  for (PersonDocumentAffiliation affiliation1 : affiliations) { | 
  | 327 | 0 |                              if (j > i && affiliation.getAffiliationTypeCode() .equals(affiliation1.getAffiliationTypeCode()) && affiliation.getCampusCode().equals(affiliation1.getCampusCode())) { | 
  | 328 | 0 |                                               GlobalVariables.getMessageMap().putError("affiliations[" + j + "].affiliationTypeCode",RiceKeyConstants.ERROR_NOT_UNIQUE_AFFILIATION_TYPE_PER_CAMPUE, affiliation.getAffiliationType().getAffiliationTypeName()); | 
  | 329 | 0 |                                               valid = false; | 
  | 330 |  |                              } | 
  | 331 | 0 |                              j++; | 
  | 332 |  |                  } | 
  | 333 | 0 |                  i++; | 
  | 334 | 0 |              } | 
  | 335 | 0 |              return valid; | 
  | 336 |  |      } | 
  | 337 |  |   | 
  | 338 |  |      protected boolean checkAffiliationEithOneEMpInfo (List <PersonDocumentAffiliation> affiliations) { | 
  | 339 | 0 |              boolean valid = true; | 
  | 340 | 0 |              int i = 0; | 
  | 341 | 0 |              for (PersonDocumentAffiliation affiliation : affiliations) { | 
  | 342 | 0 |                              if (affiliation.getAffiliationType() .isEmploymentAffiliationType() && affiliation.getEmpInfos().isEmpty()) { | 
  | 343 | 0 |                                               GlobalVariables.getMessageMap().putError("affiliations[" + i + "].affiliationTypeCode",RiceKeyConstants.ERROR_ONE_ITEM_REQUIRED, "Employment Information"); | 
  | 344 | 0 |                                               valid = false; | 
  | 345 |  |                              } | 
  | 346 | 0 |                  i++; | 
  | 347 |  |              } | 
  | 348 | 0 |              return valid; | 
  | 349 |  |      } | 
  | 350 |  |   | 
  | 351 |  |       | 
  | 352 |  |   | 
  | 353 |  |   | 
  | 354 |  |      protected boolean validateAffiliationAndName(IdentityManagementPersonDocument personDoc) { | 
  | 355 | 0 |              boolean valid = true; | 
  | 356 | 0 |              if (personDoc.getAffiliations().isEmpty()) { | 
  | 357 | 0 |                       GlobalVariables.getMessageMap().putError("affiliations[0]",RiceKeyConstants.ERROR_ONE_ITEM_REQUIRED, "affiliation"); | 
  | 358 | 0 |                       valid = false; | 
  | 359 |  |              } | 
  | 360 | 0 |              if (personDoc.getNames().isEmpty()) { | 
  | 361 | 0 |                       GlobalVariables.getMessageMap().putError("names[0]",RiceKeyConstants.ERROR_ONE_ITEM_REQUIRED, "name"); | 
  | 362 | 0 |                       valid = false; | 
  | 363 |  |              } else{ | 
  | 364 | 0 |                  boolean activeExists = false; | 
  | 365 | 0 |                  for(PersonDocumentName name: personDoc.getNames()){ | 
  | 366 | 0 |                          if(name.isActive()){ | 
  | 367 | 0 |                                  activeExists = true; | 
  | 368 |  |                                 } | 
  | 369 |  |                  } | 
  | 370 | 0 |                  if(!activeExists){ | 
  | 371 | 0 |                          GlobalVariables.getMessageMap().putError("names[0]", RiceKeyConstants.ERROR_ONE_ACTIVE_ITEM_REQUIRED, "name"); | 
  | 372 | 0 |                               valid = false; | 
  | 373 |  |                  } | 
  | 374 | 0 |                  return valid; | 
  | 375 |  |   | 
  | 376 |  |              } | 
  | 377 | 0 |              return valid; | 
  | 378 |  |      } | 
  | 379 |  |   | 
  | 380 |  |      protected boolean doesPrincipalNameExist (String principalName, String principalId) { | 
  | 381 | 0 |              KimPrincipal principal = getIdentityService().getPrincipalByPrincipalName(principalName); | 
  | 382 | 0 |              if (principal != null && (StringUtils.isBlank(principalId) || !principal.getPrincipalId().equals(principalId))) { | 
  | 383 | 0 |                  GlobalVariables.getMessageMap().putError(KIMPropertyConstants.Person.PRINCIPAL_NAME,RiceKeyConstants.ERROR_EXIST_PRINCIPAL_NAME, principalName); | 
  | 384 | 0 |                          return false; | 
  | 385 |  |              } | 
  | 386 | 0 |              return true; | 
  | 387 |  |      } | 
  | 388 |  |   | 
  | 389 |  |      protected boolean validateRoleQualifier( List<PersonDocumentRole> roles ) { | 
  | 390 | 0 |                  AttributeSet validationErrors = new AttributeSet(); | 
  | 391 | 0 |          GlobalVariables.getMessageMap().removeFromErrorPath(KNSConstants.DOCUMENT_PROPERTY_NAME); | 
  | 392 | 0 |          int i = 0; | 
  | 393 | 0 |              for(PersonDocumentRole role : roles ) { | 
  | 394 | 0 |                      KimTypeService kimTypeService = KIMServiceLocatorWeb.getKimTypeService(role.getKimRoleType()); | 
  | 395 | 0 |                  if(CollectionUtils.isEmpty(role.getRolePrncpls()) && !role.getDefinitions().isEmpty()){ | 
  | 396 | 0 |                          KimTypeInfo kimTypeInfo = KIMServiceLocatorWeb.getTypeInfoService().getKimType(role.getKimRoleType().getKimTypeId()); | 
  | 397 | 0 |                          AttributeSet blankQualifiers = attributeValidationHelper.getBlankValueQualifiersMap(kimTypeInfo.getAttributeDefinitions()); | 
  | 398 | 0 |                          AttributeSet localErrors = kimTypeService.validateAttributes( | 
  | 399 |  |                                  role.getKimRoleType().getKimTypeId(), blankQualifiers); | 
  | 400 | 0 |                          if(localErrors!=null && !localErrors.isEmpty()){ | 
  | 401 | 0 |                                  GlobalVariables.getMessageMap().putError("document.roles["+i+"].newRolePrncpl.qualifiers[0].attrVal", | 
  | 402 |  |                                                  RiceKeyConstants.ERROR_ONE_ITEM_REQUIRED, "Role Qualifier"); | 
  | 403 | 0 |                                  return false; | 
  | 404 |  |                          } | 
  | 405 |  |                  } | 
  | 406 |  |   | 
  | 407 | 0 |                  final AttributeDefinitionMap attributeDefinitions = role.getDefinitions(); | 
  | 408 | 0 |                  final Set<String> uniqueQualifierAttributes = findUniqueQualificationAttributes(role, attributeDefinitions); | 
  | 409 |  |   | 
  | 410 | 0 |                  if ( kimTypeService != null ) { | 
  | 411 | 0 |                          int j = 0; | 
  | 412 | 0 |                          for ( KimDocumentRoleMember rolePrincipal : role.getRolePrncpls() ) { | 
  | 413 | 0 |                                  AttributeSet localErrors = kimTypeService.validateAttributes( role.getKimRoleType().getKimTypeId(), attributeValidationHelper.convertQualifiersToMap( rolePrincipal.getQualifiers() ) ); | 
  | 414 | 0 |                                  validationErrors.putAll( attributeValidationHelper.convertErrors("roles["+i+"].rolePrncpls["+j+"]",attributeValidationHelper.convertQualifiersToAttrIdxMap(rolePrincipal.getQualifiers()),localErrors) ); | 
  | 415 |  |   | 
  | 416 | 0 |                                  if (uniqueQualifierAttributes.size() > 0) { | 
  | 417 | 0 |                                          validateUniquePersonRoleQualifiersUniqueForMembership(role, rolePrincipal, j, uniqueQualifierAttributes, i, validationErrors); | 
  | 418 |  |                                  } | 
  | 419 |  |   | 
  | 420 | 0 |                                  j++; | 
  | 421 | 0 |                          } | 
  | 422 |  |                  } | 
  | 423 | 0 |                  i++; | 
  | 424 | 0 |              } | 
  | 425 | 0 |          GlobalVariables.getMessageMap().addToErrorPath(KNSConstants.DOCUMENT_PROPERTY_NAME); | 
  | 426 | 0 |              if (validationErrors.isEmpty()) { | 
  | 427 | 0 |                      return true; | 
  | 428 |  |              } else { | 
  | 429 | 0 |                      attributeValidationHelper.moveValidationErrorsToErrorMap(validationErrors); | 
  | 430 | 0 |                      return false; | 
  | 431 |  |              } | 
  | 432 |  |      } | 
  | 433 |  |   | 
  | 434 |  |       | 
  | 435 |  |   | 
  | 436 |  |   | 
  | 437 |  |   | 
  | 438 |  |   | 
  | 439 |  |   | 
  | 440 |  |   | 
  | 441 |  |   | 
  | 442 |  |   | 
  | 443 |  |      protected boolean validateUniquePersonRoleQualifiersUniqueForMembership(PersonDocumentRole role, KimDocumentRoleMember membershipToCheck, int membershipToCheckIndex, Set<String> uniqueQualifierAttributes, int roleIndex, AttributeSet validationErrors) { | 
  | 444 | 0 |              boolean foundError = false; | 
  | 445 | 0 |              int count = 0; | 
  | 446 |  |   | 
  | 447 | 0 |              for (KimDocumentRoleMember membership : role.getRolePrncpls()) { | 
  | 448 | 0 |                      if (membershipToCheckIndex != count) { | 
  | 449 | 0 |                              if (sameMembershipQualifications(membershipToCheck, membership, uniqueQualifierAttributes)) { | 
  | 450 | 0 |                                      foundError = true; | 
  | 451 |  |   | 
  | 452 | 0 |                                      int qualifierCount = 0; | 
  | 453 |  |   | 
  | 454 | 0 |                                          for (KimDocumentRoleQualifier qualifier : membership.getQualifiers()) { | 
  | 455 | 0 |                                                  if (qualifier != null && uniqueQualifierAttributes.contains(qualifier.getKimAttrDefnId())) { | 
  | 456 | 0 |                                                          validationErrors.put("document.roles["+roleIndex+"].rolePrncpls["+membershipToCheckIndex+"].qualifiers["+qualifierCount+"].attrVal", RiceKeyConstants.ERROR_DOCUMENT_IDENTITY_MANAGEMENT_PERSON_QUALIFIER_VALUE_NOT_UNIQUE+":"+qualifier.getKimAttribute().getAttributeName()+";"+qualifier.getAttrVal()); | 
  | 457 |  |                                                  } | 
  | 458 | 0 |                                                  qualifierCount += 1; | 
  | 459 |  |                                          } | 
  | 460 |  |                              } | 
  | 461 |  |                      } | 
  | 462 |  |   | 
  | 463 | 0 |                      count += 1; | 
  | 464 |  |              } | 
  | 465 | 0 |              return foundError; | 
  | 466 |  |      } | 
  | 467 |  |   | 
  | 468 |  |       | 
  | 469 |  |   | 
  | 470 |  |   | 
  | 471 |  |   | 
  | 472 |  |   | 
  | 473 |  |   | 
  | 474 |  |   | 
  | 475 |  |      protected boolean sameMembershipQualifications(KimDocumentRoleMember membershipA, KimDocumentRoleMember membershipB, Set<String> uniqueQualifierAttributes) { | 
  | 476 | 0 |              boolean equalSoFar = true; | 
  | 477 | 0 |              for (String uniqueQualifierAttributeDefinitionId : uniqueQualifierAttributes) { | 
  | 478 | 0 |                      final KimDocumentRoleQualifier qualifierA = membershipA.getQualifier(uniqueQualifierAttributeDefinitionId); | 
  | 479 | 0 |                      final KimDocumentRoleQualifier qualifierB = membershipB.getQualifier(uniqueQualifierAttributeDefinitionId); | 
  | 480 |  |   | 
  | 481 | 0 |                      if (qualifierA != null && qualifierB != null) { | 
  | 482 | 0 |                              equalSoFar &= (qualifierA.getAttrVal() == null && qualifierB.getAttrVal() == null) || (qualifierA.getAttrVal() == null || qualifierA.getAttrVal().equals(qualifierB.getAttrVal())); | 
  | 483 |  |                      } | 
  | 484 | 0 |              } | 
  | 485 | 0 |              return equalSoFar; | 
  | 486 |  |      } | 
  | 487 |  |   | 
  | 488 |  |       | 
  | 489 |  |   | 
  | 490 |  |   | 
  | 491 |  |   | 
  | 492 |  |   | 
  | 493 |  |   | 
  | 494 |  |   | 
  | 495 |  |      public Set<String> findUniqueQualificationAttributes(PersonDocumentRole role, AttributeDefinitionMap attributeDefinitions) { | 
  | 496 | 0 |              Set<String> uniqueQualifications = new HashSet<String>(); | 
  | 497 |  |   | 
  | 498 | 0 |              if (role.getRolePrncpls() != null && role.getRolePrncpls().size() > 1) { | 
  | 499 | 0 |                      final KimDocumentRoleMember membership = role.getRolePrncpls().get(0); | 
  | 500 | 0 |                      for (KimDocumentRoleQualifier qualifier: membership.getQualifiers()) { | 
  | 501 | 0 |                              if (qualifier != null && qualifier.getKimAttribute() != null && !StringUtils.isBlank(qualifier.getKimAttribute().getAttributeName())) { | 
  | 502 | 0 |                                  final AttributeDefinition relatedDefinition = attributeDefinitions.getByAttributeName(qualifier.getKimAttribute().getAttributeName()); | 
  | 503 |  |   | 
  | 504 | 0 |                                  if (relatedDefinition != null && relatedDefinition.getUnique() != null && relatedDefinition.getUnique().booleanValue()) { | 
  | 505 | 0 |                                          uniqueQualifications.add(qualifier.getKimAttrDefnId()); | 
  | 506 |  |                                  } | 
  | 507 | 0 |                              } | 
  | 508 |  |                      } | 
  | 509 |  |              } | 
  | 510 |  |   | 
  | 511 | 0 |              return uniqueQualifications; | 
  | 512 |  |      } | 
  | 513 |  |   | 
  | 514 |  |      protected boolean validActiveDatesForRole (List<PersonDocumentRole> roles ) { | 
  | 515 | 0 |              boolean valid = true; | 
  | 516 | 0 |                  int i = 0; | 
  | 517 | 0 |              for(PersonDocumentRole role : roles ) { | 
  | 518 | 0 |                          int j = 0; | 
  | 519 | 0 |                      for (KimDocumentRoleMember principal : role.getRolePrncpls()) { | 
  | 520 | 0 |                              valid &= validateActiveDate("roles["+i+"].rolePrncpls["+j+"].activeToDate",principal.getActiveFromDate(), principal.getActiveToDate()); | 
  | 521 | 0 |                              j++; | 
  | 522 |  |                      } | 
  | 523 | 0 |                      i++; | 
  | 524 | 0 |              } | 
  | 525 | 0 |              return valid; | 
  | 526 |  |      } | 
  | 527 |  |   | 
  | 528 |  |      protected boolean validActiveDatesForGroup (List<PersonDocumentGroup> groups ) { | 
  | 529 | 0 |              boolean valid = true; | 
  | 530 | 0 |                  int i = 0; | 
  | 531 | 0 |              for(PersonDocumentGroup group : groups ) { | 
  | 532 | 0 |                       valid &= validateActiveDate("groups["+i+"].activeToDate",group.getActiveFromDate(), group.getActiveToDate()); | 
  | 533 | 0 |                      i++; | 
  | 534 |  |              } | 
  | 535 | 0 |              return valid; | 
  | 536 |  |      } | 
  | 537 |  |   | 
  | 538 |  |      protected boolean validActiveDatesForDelegations(List<RoleDocumentDelegationMember> delegationMembers) { | 
  | 539 | 0 |              boolean valid = true; | 
  | 540 | 0 |                  int i = 0; | 
  | 541 | 0 |                  for(RoleDocumentDelegationMember delegationMember: delegationMembers){ | 
  | 542 | 0 |                       valid &= validateActiveDate("delegationMembers["+i+"].activeToDate", delegationMember.getActiveFromDate(), delegationMember.getActiveToDate()); | 
  | 543 | 0 |                      i++; | 
  | 544 |  |                  } | 
  | 545 | 0 |              return valid; | 
  | 546 |  |      } | 
  | 547 |  |   | 
  | 548 |  |          protected boolean validateActiveDate(String errorPath, Timestamp activeFromDate, Timestamp activeToDate) { | 
  | 549 |  |                   | 
  | 550 | 0 |                  boolean valid = true; | 
  | 551 | 0 |                  if (activeFromDate != null && activeToDate !=null && activeToDate.before(activeFromDate)) { | 
  | 552 | 0 |                  GlobalVariables.getMessageMap().putError(errorPath, RiceKeyConstants.ERROR_ACTIVE_TO_DATE_BEFORE_FROM_DATE); | 
  | 553 | 0 |              valid = false; | 
  | 554 |  |                  } | 
  | 555 | 0 |                  return valid; | 
  | 556 |  |          } | 
  | 557 |  |   | 
  | 558 |  |      public boolean processAddGroup(AddGroupEvent addGroupEvent) { | 
  | 559 | 0 |          return getAddGroupRule().processAddGroup(addGroupEvent); | 
  | 560 |  |      } | 
  | 561 |  |   | 
  | 562 |  |      public boolean processAddRole(AddRoleEvent addRoleEvent) { | 
  | 563 | 0 |          return getAddRoleRule().processAddRole(addRoleEvent); | 
  | 564 |  |      } | 
  | 565 |  |   | 
  | 566 |  |      public boolean processAddPersonDelegationMember(AddPersonDelegationMemberEvent addPersonDelegationMemberEvent){ | 
  | 567 | 0 |              return getAddPersonDelegationMemberRule().processAddPersonDelegationMember(addPersonDelegationMemberEvent); | 
  | 568 |  |      } | 
  | 569 |  |   | 
  | 570 |  |          public IdentityService getIdentityService() { | 
  | 571 | 0 |                  if ( identityService == null ) { | 
  | 572 | 0 |                          identityService = KIMServiceLocator.getIdentityService(); | 
  | 573 |  |                  } | 
  | 574 | 0 |                  return identityService; | 
  | 575 |  |          } | 
  | 576 |  |   | 
  | 577 |  |          public RoleService getRoleService() { | 
  | 578 | 0 |                  if ( roleService == null ) { | 
  | 579 | 0 |                          roleService = KIMServiceLocator.getRoleService(); | 
  | 580 |  |                  } | 
  | 581 | 0 |                  return roleService; | 
  | 582 |  |          } | 
  | 583 |  |   | 
  | 584 |  |          public UiDocumentService getUIDocumentService() { | 
  | 585 | 0 |                  if ( uiDocumentService == null ) { | 
  | 586 | 0 |                          uiDocumentService = KIMServiceLocatorInternal.getUiDocumentService(); | 
  | 587 |  |                  } | 
  | 588 | 0 |                  return uiDocumentService; | 
  | 589 |  |          } | 
  | 590 |  |   | 
  | 591 |  |          public IdentityManagementKimDocumentAuthorizer getAuthorizer(IdentityManagementPersonDocument document) { | 
  | 592 | 0 |                  if ( authorizer == null ) { | 
  | 593 | 0 |                          authorizer = (IdentityManagementKimDocumentAuthorizer) KNSServiceLocatorWeb.getDocumentHelperService().getDocumentAuthorizer(document); | 
  | 594 |  |                  } | 
  | 595 | 0 |                  return authorizer; | 
  | 596 |  |          } | 
  | 597 |  |   | 
  | 598 |  |   | 
  | 599 |  |   | 
  | 600 |  |           | 
  | 601 |  |   | 
  | 602 |  |   | 
  | 603 |  |          public Class<? extends AddGroupRule> getAddGroupRuleClass() { | 
  | 604 | 0 |                  return this.addGroupRuleClass; | 
  | 605 |  |          } | 
  | 606 |  |   | 
  | 607 |  |   | 
  | 608 |  |   | 
  | 609 |  |           | 
  | 610 |  |   | 
  | 611 |  |   | 
  | 612 |  |   | 
  | 613 |  |   | 
  | 614 |  |          public void setAddGroupRuleClass(Class<? extends AddGroupRule> addGroupRuleClass) { | 
  | 615 | 0 |                  this.addGroupRuleClass = addGroupRuleClass; | 
  | 616 | 0 |          } | 
  | 617 |  |   | 
  | 618 |  |   | 
  | 619 |  |   | 
  | 620 |  |           | 
  | 621 |  |   | 
  | 622 |  |   | 
  | 623 |  |          public Class<? extends AddRoleRule> getAddRoleRuleClass() { | 
  | 624 | 0 |                  return this.addRoleRuleClass; | 
  | 625 |  |          } | 
  | 626 |  |   | 
  | 627 |  |   | 
  | 628 |  |   | 
  | 629 |  |           | 
  | 630 |  |   | 
  | 631 |  |   | 
  | 632 |  |   | 
  | 633 |  |   | 
  | 634 |  |          public void setAddRoleRuleClass(Class<? extends AddRoleRule> addRoleRuleClass) { | 
  | 635 | 0 |                  this.addRoleRuleClass = addRoleRuleClass; | 
  | 636 | 0 |          } | 
  | 637 |  |   | 
  | 638 |  |   | 
  | 639 |  |   | 
  | 640 |  |           | 
  | 641 |  |   | 
  | 642 |  |   | 
  | 643 |  |          public AddGroupRule getAddGroupRule() { | 
  | 644 | 0 |                  if ( addGroupRule == null ) { | 
  | 645 |  |                          try { | 
  | 646 | 0 |                                  addGroupRule = addGroupRuleClass.newInstance(); | 
  | 647 | 0 |                          } catch ( Exception ex ) { | 
  | 648 | 0 |                                  throw new RuntimeException( "Unable to create AddGroupRule instance using class: " + addGroupRuleClass, ex ); | 
  | 649 | 0 |                          } | 
  | 650 |  |                  } | 
  | 651 | 0 |                  return addGroupRule; | 
  | 652 |  |          } | 
  | 653 |  |   | 
  | 654 |  |   | 
  | 655 |  |   | 
  | 656 |  |           | 
  | 657 |  |   | 
  | 658 |  |   | 
  | 659 |  |          public AddRoleRule getAddRoleRule() { | 
  | 660 | 0 |                  if ( addRoleRule == null ) { | 
  | 661 |  |                          try { | 
  | 662 | 0 |                                  addRoleRule = addRoleRuleClass.newInstance(); | 
  | 663 | 0 |                          } catch ( Exception ex ) { | 
  | 664 | 0 |                                  throw new RuntimeException( "Unable to create AddRoleRule instance using class: " + addRoleRuleClass, ex ); | 
  | 665 | 0 |                          } | 
  | 666 |  |                  } | 
  | 667 | 0 |                  return addRoleRule; | 
  | 668 |  |          } | 
  | 669 |  |   | 
  | 670 |  |           | 
  | 671 |  |   | 
  | 672 |  |   | 
  | 673 |  |          public AddPersonDelegationMemberRule getAddPersonDelegationMemberRule() { | 
  | 674 | 0 |                  if(addPersonDelegationMemberRule == null){ | 
  | 675 |  |                          try { | 
  | 676 | 0 |                                  addPersonDelegationMemberRule = addPersonDelegationMemberRuleClass.newInstance(); | 
  | 677 | 0 |                          } catch ( Exception ex ) { | 
  | 678 | 0 |                                  throw new RuntimeException( "Unable to create AddPersonDelegationMemberRuleClass instance using class: " + addPersonDelegationMemberRuleClass, ex ); | 
  | 679 | 0 |                          } | 
  | 680 |  |                  } | 
  | 681 | 0 |                  return addPersonDelegationMemberRule; | 
  | 682 |  |          } | 
  | 683 |  |   | 
  | 684 |  |           | 
  | 685 |  |   | 
  | 686 |  |   | 
  | 687 |  |          public BusinessObjectService getBusinessObjectService() { | 
  | 688 | 0 |                  if ( businessObjectService == null ) { | 
  | 689 | 0 |                          businessObjectService = KNSServiceLocator.getBusinessObjectService(); | 
  | 690 |  |                  } | 
  | 691 | 0 |                  return businessObjectService; | 
  | 692 |  |          } | 
  | 693 |  |   | 
  | 694 |  |          public boolean processAddPersonDocumentRoleQualifier(IdentityManagementPersonDocument document, PersonDocumentRole role, KimDocumentRoleMember kimDocumentRoleMember, int selectedRoleIdx) { | 
  | 695 | 0 |                  boolean dateValidationSuccess = validateActiveDate("document.roles[" + selectedRoleIdx + "].newRolePrncpl.activeFromDate", kimDocumentRoleMember.getActiveFromDate(), kimDocumentRoleMember.getActiveToDate()); | 
  | 696 | 0 |                  String errorPath = "roles[" + selectedRoleIdx + "].newRolePrncpl"; | 
  | 697 | 0 |                  AttributeSet validationErrors = new AttributeSet(); | 
  | 698 | 0 |          GlobalVariables.getMessageMap().removeFromErrorPath(KNSConstants.DOCUMENT_PROPERTY_NAME); | 
  | 699 | 0 |          KimTypeService kimTypeService = KIMServiceLocatorWeb.getKimTypeService(role.getKimRoleType()); | 
  | 700 |  |   | 
  | 701 |  |          boolean attributesUnique; | 
  | 702 |  |                  AttributeSet errorsAttributesAgainstExisting; | 
  | 703 | 0 |              int i = 0; | 
  | 704 | 0 |              boolean rulePassed = true; | 
  | 705 | 0 |              AttributeSet newMemberQualifiers = attributeValidationHelper.convertQualifiersToMap(kimDocumentRoleMember.getQualifiers()); | 
  | 706 |  |              AttributeSet oldMemberQualifiers; | 
  | 707 | 0 |              List<String> roleIds = new ArrayList<String>(); | 
  | 708 | 0 |              roleIds.add(role.getRoleId()); | 
  | 709 |  |               | 
  | 710 | 0 |              for(KimDocumentRoleMember member: role.getRolePrncpls()){ | 
  | 711 | 0 |                      oldMemberQualifiers = member.getQualifierAsAttributeSet(); | 
  | 712 | 0 |                      errorsAttributesAgainstExisting = kimTypeService.validateAttributesAgainstExisting( | 
  | 713 |  |                                      role.getKimRoleType().getKimTypeId(), newMemberQualifiers, oldMemberQualifiers); | 
  | 714 | 0 |                      validationErrors.putAll( | 
  | 715 |  |                                          attributeValidationHelper.convertErrors( | 
  | 716 |  |                                                  errorPath, | 
  | 717 |  |                                                  attributeValidationHelper.convertQualifiersToAttrIdxMap(kimDocumentRoleMember.getQualifiers()), | 
  | 718 |  |                                                  errorsAttributesAgainstExisting)); | 
  | 719 |  |   | 
  | 720 | 0 |                      attributesUnique = kimTypeService.validateUniqueAttributes( | 
  | 721 |  |                                      role.getKimRoleType().getKimTypeId(), newMemberQualifiers, oldMemberQualifiers); | 
  | 722 | 0 |                      if (!attributesUnique){ | 
  | 723 | 0 |                      GlobalVariables.getMessageMap().putError("document."+errorPath+".qualifiers[0].attrVal", RiceKeyConstants.ERROR_DUPLICATE_ENTRY, new String[] {"Role Qualifier"}); | 
  | 724 | 0 |                      return false; | 
  | 725 |  |                      } | 
  | 726 | 0 |                      i++; | 
  | 727 |  |              } | 
  | 728 |  |   | 
  | 729 | 0 |          if ( kimTypeService != null ) { | 
  | 730 | 0 |                  AttributeSet localErrors = kimTypeService.validateAttributes( role.getKimRoleType().getKimTypeId(), newMemberQualifiers ); | 
  | 731 | 0 |                  validationErrors.putAll( attributeValidationHelper.convertErrors(errorPath, attributeValidationHelper.convertQualifiersToAttrIdxMap(kimDocumentRoleMember.getQualifiers()), localErrors)); | 
  | 732 |  |          } | 
  | 733 |  |   | 
  | 734 | 0 |          GlobalVariables.getMessageMap().addToErrorPath(KNSConstants.DOCUMENT_PROPERTY_NAME); | 
  | 735 | 0 |              if (validationErrors.isEmpty()) { | 
  | 736 | 0 |                      rulePassed = dateValidationSuccess; | 
  | 737 |  |              } else { | 
  | 738 | 0 |                      attributeValidationHelper.moveValidationErrorsToErrorMap(validationErrors); | 
  | 739 | 0 |                      rulePassed = false; | 
  | 740 |  |              } | 
  | 741 | 0 |              return rulePassed; | 
  | 742 |  |          } | 
  | 743 |  |   | 
  | 744 |  |      protected boolean validateDelegationMemberRoleQualifier(List<RoleDocumentDelegationMember> delegationMembers){ | 
  | 745 | 0 |                  AttributeSet validationErrors = new AttributeSet(); | 
  | 746 |  |                  boolean valid; | 
  | 747 | 0 |                  int memberCounter = 0; | 
  | 748 |  |                  AttributeSet errorsTemp; | 
  | 749 |  |                  AttributeSet attributeSetToValidate; | 
  | 750 |  |          KimTypeService kimTypeService; | 
  | 751 | 0 |          GlobalVariables.getMessageMap().removeFromErrorPath(KNSConstants.DOCUMENT_PROPERTY_NAME); | 
  | 752 |  |          RoleMemberImpl roleMember; | 
  | 753 |  |          String errorPath; | 
  | 754 |  |          ArrayList<String> roleIds; | 
  | 755 |  |          KimTypeInfo kimType; | 
  | 756 | 0 |                  for(RoleDocumentDelegationMember delegationMember: delegationMembers) { | 
  | 757 | 0 |                          kimType = delegationMember.getRoleImpl().getKimRoleType(); | 
  | 758 | 0 |                          kimTypeService = KIMServiceLocatorWeb.getKimTypeService(kimType); | 
  | 759 | 0 |                          roleIds = new ArrayList<String>(); | 
  | 760 | 0 |                          roleIds.add(delegationMember.getRoleImpl().getRoleId()); | 
  | 761 | 0 |                          errorPath = "delegationMembers["+memberCounter+"]"; | 
  | 762 | 0 |                          attributeSetToValidate = attributeValidationHelper.convertQualifiersToMap(delegationMember.getQualifiers()); | 
  | 763 | 0 |                          errorsTemp = kimTypeService.validateAttributes(kimType.getKimTypeId(), attributeSetToValidate); | 
  | 764 | 0 |                          validationErrors.putAll( | 
  | 765 |  |                                          attributeValidationHelper.convertErrors(errorPath, attributeValidationHelper.convertQualifiersToAttrIdxMap(delegationMember.getQualifiers()), errorsTemp)); | 
  | 766 |  |   | 
  | 767 | 0 |                          roleMember = getUIDocumentService().getRoleMember(delegationMember.getRoleMemberId()); | 
  | 768 | 0 |                          if(roleMember==null){ | 
  | 769 | 0 |                                  valid = false; | 
  | 770 | 0 |                                  GlobalVariables.getMessageMap().putError("document."+errorPath, RiceKeyConstants.ERROR_DELEGATE_ROLE_MEMBER_ASSOCIATION, new String[]{}); | 
  | 771 |  |                          } else{ | 
  | 772 | 0 |                                  errorsTemp = kimTypeService.validateUnmodifiableAttributes( | 
  | 773 |  |                                                                  kimType.getKimTypeId(), roleMember.getQualifier(), attributeSetToValidate); | 
  | 774 | 0 |                                  validationErrors.putAll( | 
  | 775 |  |                                                  attributeValidationHelper.convertErrors(errorPath, attributeValidationHelper.convertQualifiersToAttrIdxMap(delegationMember.getQualifiers()), errorsTemp)); | 
  | 776 |  |                          } | 
  | 777 | 0 |                  memberCounter++; | 
  | 778 |  |              } | 
  | 779 | 0 |                  GlobalVariables.getMessageMap().addToErrorPath(KNSConstants.DOCUMENT_PROPERTY_NAME); | 
  | 780 | 0 |              if (validationErrors.isEmpty()) { | 
  | 781 | 0 |                      valid = true; | 
  | 782 |  |              } else { | 
  | 783 | 0 |                      attributeValidationHelper.moveValidationErrorsToErrorMap(validationErrors); | 
  | 784 | 0 |                      valid = false; | 
  | 785 |  |              } | 
  | 786 | 0 |              return valid; | 
  | 787 |  |      } | 
  | 788 |  |   | 
  | 789 |  |  } |