001/** 002 * Copyright 2005-2014 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.kim.service.impl; 017 018import static org.junit.Assert.assertEquals; 019import static org.junit.Assert.assertFalse; 020import static org.junit.Assert.assertNotNull; 021import static org.junit.Assert.assertTrue; 022 023import java.lang.reflect.Field; 024import java.sql.Timestamp; 025import java.util.ArrayList; 026import java.util.Arrays; 027import java.util.HashMap; 028import java.util.List; 029import java.util.Map; 030import java.util.UUID; 031 032import org.joda.time.DateTime; 033import org.joda.time.format.DateTimeFormat; 034import org.joda.time.format.DateTimeFormatter; 035import org.junit.BeforeClass; 036import org.junit.Test; 037import org.kuali.rice.core.api.membership.MemberType; 038import org.kuali.rice.core.api.util.type.KualiDecimal; 039import org.kuali.rice.kew.api.WorkflowDocument; 040import org.kuali.rice.kew.api.WorkflowDocumentFactory; 041import org.kuali.rice.kim.api.KimConstants; 042import org.kuali.rice.kim.api.identity.IdentityService; 043import org.kuali.rice.kim.api.identity.Person; 044import org.kuali.rice.kim.api.identity.address.EntityAddressContract; 045import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliation; 046import org.kuali.rice.kim.api.identity.email.EntityEmailContract; 047import org.kuali.rice.kim.api.identity.employment.EntityEmploymentContract; 048import org.kuali.rice.kim.api.identity.entity.Entity; 049import org.kuali.rice.kim.api.identity.entity.EntityDefault; 050import org.kuali.rice.kim.api.identity.name.EntityNameContract; 051import org.kuali.rice.kim.api.identity.phone.EntityPhoneContract; 052import org.kuali.rice.kim.api.identity.principal.PrincipalContract; 053import org.kuali.rice.kim.api.identity.type.EntityTypeContactInfo; 054import org.kuali.rice.kim.api.role.RoleMember; 055import org.kuali.rice.kim.api.role.RoleMemberContract; 056import org.kuali.rice.kim.api.services.KimApiServiceLocator; 057import org.kuali.rice.kim.api.type.KimType; 058import org.kuali.rice.kim.bo.ui.KimDocumentRoleMember; 059import org.kuali.rice.kim.bo.ui.PersonDocumentAddress; 060import org.kuali.rice.kim.bo.ui.PersonDocumentAffiliation; 061import org.kuali.rice.kim.bo.ui.PersonDocumentEmail; 062import org.kuali.rice.kim.bo.ui.PersonDocumentEmploymentInfo; 063import org.kuali.rice.kim.bo.ui.PersonDocumentName; 064import org.kuali.rice.kim.bo.ui.PersonDocumentPhone; 065import org.kuali.rice.kim.bo.ui.PersonDocumentPrivacy; 066import org.kuali.rice.kim.bo.ui.PersonDocumentRole; 067import org.kuali.rice.kim.document.IdentityManagementPersonDocument; 068import org.kuali.rice.kim.document.IdentityManagementRoleDocument; 069import org.kuali.rice.kim.framework.type.KimTypeService; 070import org.kuali.rice.kim.impl.common.delegate.DelegateMemberBo; 071import org.kuali.rice.kim.impl.identity.address.EntityAddressTypeBo; 072import org.kuali.rice.kim.impl.identity.affiliation.EntityAffiliationTypeBo; 073import org.kuali.rice.kim.impl.identity.email.EntityEmailTypeBo; 074import org.kuali.rice.kim.impl.identity.name.EntityNameTypeBo; 075import org.kuali.rice.kim.impl.identity.phone.EntityPhoneTypeBo; 076import org.kuali.rice.kim.impl.identity.privacy.EntityPrivacyPreferencesBo; 077import org.kuali.rice.kim.impl.role.RoleMemberBo; 078import org.kuali.rice.kim.impl.type.KimTypeAttributeBo; 079import org.kuali.rice.kim.impl.type.KimTypeBo; 080import org.kuali.rice.kim.service.KIMServiceLocatorInternal; 081import org.kuali.rice.kim.service.UiDocumentService; 082import org.kuali.rice.kim.test.KIMTestCase; 083import org.kuali.rice.kns.kim.type.DataDictionaryTypeServiceBase; 084import org.kuali.rice.krad.bo.DocumentHeader; 085import org.kuali.rice.krad.data.KradDataServiceLocator; 086import org.kuali.rice.krad.data.PersistenceOption; 087import org.kuali.rice.krad.service.KRADServiceLocatorWeb; 088import org.kuali.rice.test.BaselineTestCase; 089 090/** 091 * This is a description of what this class does - shyu don't forget to fill this in. 092 * 093 * @author Kuali Rice Team (rice.collab@kuali.org) 094 * 095 */ 096@BaselineTestCase.BaselineMode(BaselineTestCase.Mode.ROLLBACK_CLEAR_DB) 097public class UiDocumentServiceImplTest extends KIMTestCase { 098 099 private UiDocumentService uiDocumentService; 100 static Person adminPerson = null; 101 102 @BeforeClass 103 public static void beforeClassSetup() { 104 adminPerson = KimApiServiceLocator.getPersonService().getPersonByPrincipalName("admin"); 105 } 106 107 @Override 108 public void setUp() throws Exception { 109 super.setUp(); 110 uiDocumentService = KIMServiceLocatorInternal.getUiDocumentService(); 111 } 112 113 protected EntityDefault createTestingEntity() { 114 IdentityManagementPersonDocument personDoc = initPersonDoc(); 115 116 WorkflowDocument document = WorkflowDocumentFactory.createDocument(adminPerson.getPrincipalId(),"TestDocumentType"); 117 DocumentHeader documentHeader = new DocumentHeader(); 118 documentHeader.setWorkflowDocument(document); 119 documentHeader.setDocumentNumber(document.getDocumentId()); 120 personDoc.setDocumentHeader(documentHeader); 121 122 // first - save them so we can inactivate them 123 uiDocumentService.saveEntityPerson(personDoc); 124 // verify that the record was saved 125 EntityDefault entity = KimApiServiceLocator.getIdentityService().getEntityDefault(personDoc.getEntityId()); 126 assertNotNull( "Entity was not saved: " + personDoc, entity); 127 assertNotNull( "Principal list was null on retrieved record", entity.getPrincipals() ); 128 assertEquals( "Principal list was incorrect length", 1, entity.getPrincipals().size() ); 129 assertTrue( "Principal is not active on saved record", entity.getPrincipals().get(0).isActive() ); 130 return entity; 131 } 132 133 @Test 134 public void testInactiveRoleMemberOnly() { 135 136 KimType.Builder ktBuilder = KimType.Builder.create(); 137 ktBuilder.setId("1"); 138 ktBuilder.setNamespaceCode("KUALI"); 139 ktBuilder.setName("Default"); 140 Long version = new Long(1) ; 141 ktBuilder.setVersionNumber(version); 142 KimType kt = ktBuilder.build() ; 143 144 IdentityManagementRoleDocument identityManagementRoleDocument = new IdentityManagementRoleDocument(); 145 identityManagementRoleDocument.setKimType(kt); 146 identityManagementRoleDocument.setRoleId("KRSAP10003"); 147 identityManagementRoleDocument.setRoleTypeId("1"); 148 identityManagementRoleDocument.setRoleName("Default"); 149 identityManagementRoleDocument.setRoleNamespace("KR_SAP"); 150 identityManagementRoleDocument.setRoleName("Sample App Admin"); 151 152 RoleMemberBo roleMemberBo = new RoleMemberBo(); 153 roleMemberBo.setId("KRSAP10003"); 154 roleMemberBo.setRoleId("KRSAP1003"); 155 roleMemberBo.setMemberId("dev1"); 156 roleMemberBo.setTypeCode("P"); 157 158 // make the role member inactive 159 Timestamp timestamp = new Timestamp(System.currentTimeMillis()); 160 roleMemberBo.setActiveToDateValue(timestamp); 161 ArrayList<RoleMemberBo> roleMemberBos = new ArrayList<RoleMemberBo>(); 162 roleMemberBos.add(roleMemberBo); 163 164 // We've got one role member, and it is inactive. 165 UiDocumentServiceImpl uiDocumentServiceImpl = new UiDocumentServiceImpl() ; 166 List<KimDocumentRoleMember> kimDocumentRoleMembers = uiDocumentServiceImpl.loadRoleMembers(identityManagementRoleDocument, roleMemberBos); 167 assertEquals("KimDocuemtnRoleMember size is incorrect", 0, kimDocumentRoleMembers.size()); 168 } 169 170 171 @Test 172 public void testInactivatePrincipal() { 173 createTestingEntity(); 174 // create a new person document and inactivate the record we just created 175 IdentityManagementPersonDocument personDoc = initPersonDoc(); 176 177 WorkflowDocument document = WorkflowDocumentFactory.createDocument(adminPerson.getPrincipalId(),"TestDocumentType"); 178 DocumentHeader documentHeader = new DocumentHeader(); 179 documentHeader.setWorkflowDocument(document); 180 documentHeader.setDocumentNumber(document.getDocumentId()); 181 personDoc.setDocumentHeader(documentHeader); 182 183 personDoc.setActive(false); 184 uiDocumentService.saveEntityPerson(personDoc); 185 EntityDefault entity = KimApiServiceLocator.getIdentityService().getEntityDefault(personDoc.getEntityId()); 186 187 assertNotNull( "Entity missing after inactivation: " + personDoc, entity); 188 assertNotNull( "Principal list was null on retrieved record", entity.getPrincipals() ); 189 assertEquals( "Principal list was incorrect length", 1, entity.getPrincipals().size() ); 190 assertFalse( "Principal is active on saved record (after inactivation)", entity.getPrincipals().get(0).isActive() ); 191 } 192 193 @Test 194 public void testInactivatePrincipalDelegations() { 195 EntityDefault entity = createTestingEntity(); 196 197 // create a delegation for the system to inactivate 198 String delegateMemberId = UUID.randomUUID().toString(); 199 DelegateMemberBo delegateMemberBo = new DelegateMemberBo(); 200 delegateMemberBo.setMemberId(entity.getPrincipals().get(0).getPrincipalId()); 201 delegateMemberBo.setType(MemberType.PRINCIPAL); 202 delegateMemberBo.setDelegationMemberId(delegateMemberId); 203 KradDataServiceLocator.getDataObjectService().save(delegateMemberBo,PersistenceOption.FLUSH); 204 205 // attempt to reload - to make sure it's all working 206 delegateMemberBo = KradDataServiceLocator.getDataObjectService().find(DelegateMemberBo.class, delegateMemberId); 207 assertNotNull( "Unable to find delegate member bo", delegateMemberBo); 208 assertTrue( "delegate member should be active", delegateMemberBo.isActive() ); 209 210 // create a new person document and inactivate the record we just created 211 IdentityManagementPersonDocument personDoc = initPersonDoc(); 212 213 WorkflowDocument document = WorkflowDocumentFactory.createDocument(adminPerson.getPrincipalId(),"TestDocumentType"); 214 DocumentHeader documentHeader = new DocumentHeader(); 215 documentHeader.setWorkflowDocument(document); 216 documentHeader.setDocumentNumber(document.getDocumentId()); 217 personDoc.setDocumentHeader(documentHeader); 218 219 personDoc.setActive(false); 220 uiDocumentService.saveEntityPerson(personDoc); 221 222 delegateMemberBo = KradDataServiceLocator.getDataObjectService().find(DelegateMemberBo.class, delegateMemberId); 223 assertNotNull( "Unable to find delegate member bo", delegateMemberBo); 224 assertFalse( "delegate member should be inactive: " + delegateMemberBo, delegateMemberBo.isActive() ); 225 } 226 227 @Test 228 public void testSaveToEntity() { 229 Person adminPerson = KimApiServiceLocator.getPersonService().getPersonByPrincipalName("admin"); 230 IdentityManagementPersonDocument personDoc = initPersonDoc(); 231 232 WorkflowDocument document = WorkflowDocumentFactory.createDocument(adminPerson.getPrincipalId(),"TestDocumentType"); 233 DocumentHeader documentHeader = new DocumentHeader(); 234 documentHeader.setWorkflowDocument(document); 235 documentHeader.setDocumentNumber(document.getDocumentId()); 236 personDoc.setDocumentHeader(documentHeader); 237 238 uiDocumentService.saveEntityPerson(personDoc); 239 240 Entity entity = KimApiServiceLocator.getIdentityService().getEntity(personDoc.getEntityId()); 241 EntityTypeContactInfo entityType = entity.getEntityTypeContactInfos().get(0); 242 personDoc.getExternalIdentifiers(); 243 assertAddressTrue(personDoc.getAddrs().get(0), entityType.getAddresses().get(0)); 244 assertPhoneTrue(personDoc.getPhones().get(0), entityType.getPhoneNumbers().get(0)); 245 assertEmailTrue(personDoc.getEmails().get(0), entityType.getEmailAddresses().get(0)); 246 assertNameTrue(personDoc.getNames().get(0), entity.getNames().get(0)); 247 assertPrincipalTrue(personDoc, entity.getPrincipals().get(0)); 248 249 assertAffiliationTrue(personDoc.getAffiliations().get(0), entity.getAffiliations().get(0)); 250 assertEmpInfoTrue(personDoc.getAffiliations().get(0).getEmpInfos().get(0), entity.getEmploymentInformation().get(0)); 251 252 //verify that update doesn't cause external identifier to be encrypted twice 253 // and that update doesn't cause any problems 254 uiDocumentService.saveEntityPerson(personDoc); 255 Entity entity2 = ((IdentityService) KIMServiceLocatorInternal.getService("kimIdentityDelegateService")).getEntity( 256 personDoc.getEntityId()); 257 EntityTypeContactInfo entityType2 = entity2.getEntityTypeContactInfos().get(0); 258 personDoc.getExternalIdentifiers(); 259 assertAddressTrue(personDoc.getAddrs().get(0), entityType2.getAddresses().get(0)); 260 assertPhoneTrue(personDoc.getPhones().get(0), entityType2.getPhoneNumbers().get(0)); 261 assertEmailTrue(personDoc.getEmails().get(0), entityType2.getEmailAddresses().get(0)); 262 assertNameTrue(personDoc.getNames().get(0), entity2.getNames().get(0)); 263 assertPrincipalTrue(personDoc, entity2.getPrincipals().get(0)); 264 265 266 267 // List<String> groupIds = groupService.getDirectMemberGroupIds("g1"); 268// System.out.println( groupIds ); 269// assertTrue( "g1 must contain group g2", groupIds.contains( "g2" ) ); 270// assertFalse( "g1 must not contain group g3", groupIds.contains( "g3" ) ); 271// 272// groupIds = groupService.getDirectMemberGroupIds("g2"); 273// System.out.println( groupIds ); 274// assertTrue( "g2 must contain group g3", groupIds.contains( "g3" ) ); 275// assertFalse( "g2 must not contain group g4 (inactive)", groupIds.contains( "g4" ) ); 276 277 } 278 279 @Test 280 public void testLoadToPersonDocument() { 281 282 Entity entity = KimApiServiceLocator.getIdentityService().getEntity("entity123eId"); 283 assertNotNull(entity); 284 IdentityManagementPersonDocument personDoc = new IdentityManagementPersonDocument(); 285 uiDocumentService.loadEntityToPersonDoc(personDoc, "entity123pId"); 286 EntityTypeContactInfo entityType = entity.getEntityTypeContactInfos().get(0); 287 personDoc.getExternalIdentifiers(); 288 assertAddressTrue(personDoc.getAddrs().get(0), entityType.getAddresses().get(0)); 289 assertPhoneTrue(personDoc.getPhones().get(0), entityType.getPhoneNumbers().get(0)); 290 assertEmailTrue(personDoc.getEmails().get(0), entityType.getEmailAddresses().get(0)); 291 assertNameTrue(personDoc.getNames().get(0), entity.getNames().get(0)); 292 //assertPrincipalTrue(personDoc, identity.getPrincipals().get(0)); 293 assertAffiliationTrue(personDoc.getAffiliations().get(0), entity.getAffiliations().get(0)); 294 assertEmpInfoTrue(personDoc.getAffiliations().get(0).getEmpInfos().get(0), entity.getEmploymentInformation().get(0)); 295 296 } 297 298 // test principal membership 299 @Test 300 public void testSetAttributeEntry() throws Exception { 301 PersonDocumentRole personDocRole = initPersonDocRole(); 302 KimTypeService kimTypeService = (DataDictionaryTypeServiceBase) KIMServiceLocatorInternal.getService(personDocRole.getKimRoleType().getServiceName()); 303 personDocRole.setDefinitions(kimTypeService.getAttributeDefinitions(personDocRole.getKimTypeId())); 304 305 personDocRole.setAttributeEntry( uiDocumentService.getAttributeEntries( personDocRole.getDefinitions() ) ); 306 for (Object key : personDocRole.getAttributeEntry().keySet()) { 307 if (key.equals(KimConstants.AttributeConstants.NAMESPACE_CODE)) { 308 Map value = (Map)personDocRole.getAttributeEntry().get(key); 309 assertEquals("Parameter Namespace Code", value.get("label")); 310 assertEquals("Nmspc Cd", value.get("shortLabel")); 311 assertEquals(new Integer(20), value.get("maxLength")); 312 } else if (key.equals("campusCode")) { 313 Map value = (Map)personDocRole.getAttributeEntry().get(key); 314 assertEquals("Campus Code", value.get("label")); 315 assertEquals("Campus Code", value.get("shortLabel")); 316 assertEquals(new Integer(2), value.get("maxLength")); 317 } else { 318 assertFalse("Should not have this key "+key, true); 319 } 320 } 321 } 322 323 private PersonDocumentRole initPersonDocRole() throws Exception { 324// Map pkMap = new HashMap(); 325// pkMap.put("roleId", "r1"); 326// PersonDocumentRole docRole = (PersonDocumentRole)uiDocumentService.getBusinessObjectService().findByPrimaryKey(PersonDocumentRole.class, pkMap); 327 PersonDocumentRole docRole = new PersonDocumentRole(); 328 docRole.setKimTypeId("roleType1"); 329 docRole.setRoleId("r1"); 330 KimTypeBo kimType = new KimTypeBo(); 331 kimType.setId("roleType1"); 332 kimType.setServiceName("kimRoleTypeService"); 333 List<KimTypeAttributeBo> attributeDefinitions = new ArrayList<KimTypeAttributeBo>(); 334 KimTypeAttributeBo attr1 = KradDataServiceLocator.getDataObjectService().find(KimTypeAttributeBo.class, "kimAttr3"); 335 336// attr1.setKimAttributeId("kimAttrDefn2"); 337// attr1.setSortCode("a"); 338// attr1.setKimTypeAttributeId("kimAttr3"); 339 340 attributeDefinitions.add(attr1); 341// attr1 = new KimTypeAttributeBo(); 342// attr1.setKimAttributeId("kimAttrDefn3"); 343// attr1.setSortCode("b"); 344// attr1.setKimTypeAttributeId("kimAttr4"); 345 346 KimTypeAttributeBo attr2 = KradDataServiceLocator.getDataObjectService().find(KimTypeAttributeBo.class, "kimAttr4"); 347 348 attributeDefinitions.add(attr2); 349 kimType.setAttributeDefinitions(attributeDefinitions); 350 351 Field fld = PersonDocumentRole.class.getDeclaredField("kimRoleType"); 352 fld.setAccessible(true); 353 fld.set(docRole, kimType); 354 355 return docRole; 356 } 357 358 // init section 359 private IdentityManagementPersonDocument initPersonDoc() { 360 IdentityManagementPersonDocument personDoc = new IdentityManagementPersonDocument(); 361 personDoc.setEntityId("ent123"); 362 personDoc.setDocumentNumber("1"); 363 personDoc.setPrincipalId("pid123"); 364 personDoc.setPrincipalName("quickTest"); 365// personDoc.setUnivId("1234567890"); 366 personDoc.setAffiliations(initAffiliations()); 367 personDoc.setNames(initNames()); 368 personDoc.setAddrs(initAddresses()); 369 //personDoc.setRoles(initRoles()); 370 //personDoc.setGroups(); 371 personDoc.setPhones(initPhones()); 372 personDoc.setEmails(initEmails()); 373 return personDoc; 374 } 375 376 private List<PersonDocumentName> initNames() { 377 List<PersonDocumentName> docNames = new ArrayList<PersonDocumentName>(); 378 PersonDocumentName docName = new PersonDocumentName(); 379 docName.setEntityNameId("nameId123"); 380 docName.setNameCode("PRFR"); 381 docName.setEntityNameType( 382 EntityNameTypeBo.from(KimApiServiceLocator.getIdentityService().getNameType("PRFR"))); 383 docName.setFirstName("John"); 384 docName.setLastName("Doe"); 385 docName.setMiddleName("M"); 386 docName.setNamePrefix("Mr"); 387 docName.setNameSuffix("Jr"); 388 docName.setActive(true); 389 docName.setDflt(true); 390 docNames.add(docName); 391 return docNames; 392 } 393 394 private List<PersonDocumentAffiliation> initAffiliations() { 395 List<PersonDocumentAffiliation> docAffiliations = new ArrayList<PersonDocumentAffiliation>(); 396 PersonDocumentAffiliation docAffiliation = new PersonDocumentAffiliation(); 397 docAffiliation.setAffiliationTypeCode("FCLTY"); 398 docAffiliation.setAffiliationType( 399 EntityAffiliationTypeBo.from(KimApiServiceLocator.getIdentityService().getAffiliationType("FCLTY"))); 400 docAffiliation.setEntityAffiliationId("aflID123"); 401 docAffiliation.setCampusCode("BL"); 402 docAffiliation.setActive(true); 403 docAffiliation.setDflt(true); 404 405 // EntityAffiliationImpl does not define empinfos as collection 406 docAffiliations.add(docAffiliation); 407 List<PersonDocumentEmploymentInfo> docEmploymentInformations = new ArrayList<PersonDocumentEmploymentInfo>(); 408 PersonDocumentEmploymentInfo docEmpInfo = new PersonDocumentEmploymentInfo(); 409 docEmpInfo.setEmployeeId("12345"); 410 docEmpInfo.setEntityAffiliationId(docAffiliation.getEntityAffiliationId()); 411 docEmpInfo.setEntityEmploymentId("empId123"); 412 docEmpInfo.setEmploymentRecordId("1"); 413 docEmpInfo.setBaseSalaryAmount(new KualiDecimal(8000)); 414 docEmpInfo.setPrimaryDepartmentCode("BL-CHEM"); 415 docEmpInfo.setEmploymentStatusCode("A"); 416 docEmpInfo.setEmploymentTypeCode("P"); 417 docEmpInfo.setActive(true); 418 docEmploymentInformations.add(docEmpInfo); 419 docAffiliation.setEmpInfos(docEmploymentInformations); 420 421 return docAffiliations; 422 423 } 424 425 private PersonDocumentPrivacy initPrivacyReferences(EntityPrivacyPreferencesBo privacyPreferences) { 426 PersonDocumentPrivacy docPrivacy = new PersonDocumentPrivacy(); 427 docPrivacy.setSuppressAddress(true); 428 docPrivacy.setSuppressEmail(false); 429 docPrivacy.setSuppressName(false); 430 docPrivacy.setSuppressPhone(false); 431 docPrivacy.setSuppressPersonal(true); 432 return docPrivacy; 433 } 434 private List<PersonDocumentPhone> initPhones() { 435 List<PersonDocumentPhone> docPhones = new ArrayList<PersonDocumentPhone>(); 436 PersonDocumentPhone docPhone = new PersonDocumentPhone(); 437 docPhone.setPhoneTypeCode("HM"); 438 docPhone.setPhoneType(EntityPhoneTypeBo.from(KimApiServiceLocator.getIdentityService().getPhoneType("HM"))); 439 docPhone.setEntityPhoneId("phoneId123"); 440 docPhone.setEntityTypeCode("PERSON"); 441 docPhone.setPhoneNumber("123-45'6789"); 442 docPhone.setExtensionNumber("123"); 443 docPhone.setActive(true); 444 docPhone.setDflt(true); 445 docPhones.add(docPhone); 446 return docPhones; 447 448 } 449 450 private List<PersonDocumentEmail> initEmails() { 451 List<PersonDocumentEmail> emails = new ArrayList<PersonDocumentEmail>(); 452 PersonDocumentEmail docEmail = new PersonDocumentEmail(); 453 //docEmail.setEntityId(email.getEntityId()); 454 docEmail.setEntityEmailId("emailId123"); 455 docEmail.setEntityTypeCode("PERSON"); 456 docEmail.setEmailTypeCode("HM"); 457 docEmail.setEmailType( 458 EntityEmailTypeBo.from(KimApiServiceLocator.getIdentityService().getEmailType("HM"))); 459 docEmail.setEmailAddress("test@abc.com"); 460 docEmail.setActive(true); 461 docEmail.setDflt(true); 462 emails.add(docEmail); 463 return emails; 464 } 465 466 private List<PersonDocumentAddress> initAddresses() { 467 List<PersonDocumentAddress> docAddresses = new ArrayList<PersonDocumentAddress>(); 468 PersonDocumentAddress docAddress = new PersonDocumentAddress(); 469 docAddress.setEntityTypeCode("PERSON"); 470 docAddress.setEntityAddressId("addrId123"); 471 docAddress.setAddressTypeCode("HM"); 472 docAddress.setAddressType(EntityAddressTypeBo.from(KimApiServiceLocator.getIdentityService().getAddressType("HM"))); 473 docAddress.setLine1("PO box 123"); 474 docAddress.setStateProvinceCode("IN"); 475 docAddress.setPostalCode("46123"); 476 docAddress.setCountryCode("US"); 477 docAddress.setCity("Indianapolis"); 478 docAddress.setActive(true); 479 docAddress.setDflt(true); 480 docAddresses.add(docAddress); 481 return docAddresses; 482 } 483 484// assert section 485 486 private void assertPrincipalTrue(IdentityManagementPersonDocument personDoc, PrincipalContract principal) { 487 assertEquals(personDoc.getPrincipalId(), principal.getPrincipalId()); 488 assertEquals(personDoc.getPrincipalName(), principal.getPrincipalName()); 489 } 490 491 private void assertAddressTrue(PersonDocumentAddress docAddress, EntityAddressContract entityAddress) { 492 493 assertEquals(docAddress.getAddressTypeCode(), entityAddress.getAddressType().getCode()); 494 assertEquals(docAddress.getCountryCode(), entityAddress.getCountryCode()); 495 assertEquals(docAddress.getLine1(), entityAddress.getLine1()); 496 assertEquals(docAddress.getCity(), entityAddress.getCity()); 497 assertEquals(docAddress.getPostalCode(), entityAddress.getPostalCode()); 498 assertEquals(docAddress.getStateProvinceCode(), entityAddress.getStateProvinceCode()); 499 } 500 501 private void assertEmailTrue(PersonDocumentEmail docEmail, EntityEmailContract entityEmail) { 502 assertEquals(docEmail.getEntityEmailId(), entityEmail.getId()); 503 assertEquals(docEmail.getEmailAddress(), entityEmail.getEmailAddressUnmasked()); 504 assertEquals(docEmail.getEmailTypeCode(), entityEmail.getEmailType().getCode()); 505 } 506 507 private void assertPhoneTrue(PersonDocumentPhone docPhone, EntityPhoneContract entityPhone) { 508 assertEquals(docPhone.getEntityPhoneId(), entityPhone.getId()); 509 assertEquals(docPhone.getCountryCode(), entityPhone.getCountryCode()); 510 assertEquals(docPhone.getPhoneNumber(), entityPhone.getPhoneNumber()); 511 assertEquals(docPhone.getExtensionNumber(), entityPhone.getExtensionNumber()); 512 assertEquals(docPhone.getPhoneTypeCode(), entityPhone.getPhoneType().getCode()); 513 } 514 515 private void assertNameTrue(PersonDocumentName docName, EntityNameContract entityName) { 516 assertEquals(docName.getEntityNameId(), entityName.getId()); 517 assertEquals(docName.getFirstName(), entityName.getFirstName()); 518 assertEquals(docName.getLastName(), entityName.getLastName()); 519 assertEquals(docName.getNameCode(), entityName.getNameType().getCode()); 520 assertEquals(docName.getNameSuffix(), entityName.getNameSuffix()); 521 assertEquals(docName.getNamePrefix(), entityName.getNamePrefix()); 522 } 523 524 private void assertAffiliationTrue(PersonDocumentAffiliation docAffln, EntityAffiliation entityAffln) { 525 assertEquals(docAffln.getAffiliationTypeCode(), entityAffln.getAffiliationType().getCode()); 526 assertEquals(docAffln.getCampusCode(), entityAffln.getCampusCode()); 527 assertEquals(docAffln.getEntityAffiliationId(), entityAffln.getId()); 528 } 529 530 private void assertEmpInfoTrue(PersonDocumentEmploymentInfo docEmpInfo, EntityEmploymentContract entityEmpInfo) { 531 assertEquals(docEmpInfo.getEmployeeId(), entityEmpInfo.getEmployeeId()); 532 assertEquals(docEmpInfo.getEmploymentTypeCode(), entityEmpInfo.getEmployeeType().getCode()); 533 assertEquals(docEmpInfo.getEmploymentStatusCode(), entityEmpInfo.getEmployeeStatus().getCode()); 534 assertEquals(docEmpInfo.getEmploymentRecordId(), entityEmpInfo.getEmploymentRecordId()); 535 assertEquals(docEmpInfo.getBaseSalaryAmount(), entityEmpInfo.getBaseSalaryAmount()); 536 } 537 538 @Test 539 public void test_KimDocumentRoleMember_copyProperties() { 540 // 541 // KimDocumentRoleMember.copyProperties is called by the UiDocumentServiceImpl.getRoleMembers 542 // method. This test verifies that KimDocumentRoleMember.copyProperties is working as 543 // expected and also will fail if fields are added to KimDocumentRoleMember to ensure that 544 // KimDocumentRoleMember.copyProperties is kept up to date. 545 // 546 547 DateTimeFormatter FORMATTER = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); 548 String ROLE_MEMBER_ID = "1"; 549 String ROLE_ID = "23"; 550 Map<String, String> ATTRIBUTES = new HashMap<String, String>(); 551 String MEMBER_NAME = "WorkflowAdmin"; 552 String MEMBER_NAMESPACE_CODE = "KR-WKFLW"; 553 String MEMBER_ID = "1"; 554 MemberType MEMBER_TYPE = MemberType.GROUP; 555 String ACTIVE_FROM_STRING = "2011-01-01 12:00:00"; 556 DateTime ACTIVE_FROM = new DateTime(FORMATTER.parseDateTime(ACTIVE_FROM_STRING)); 557 String ACTIVE_TO_STRING = "2115-01-01 12:00:00"; 558 DateTime ACTIVE_TO = new DateTime(FORMATTER.parseDateTime(ACTIVE_TO_STRING)); 559 String OBJ_ID = "123"; 560 long VER_NUM = 4; 561 562 KimDocumentRoleMember newKimDocumentRoleMember = new KimDocumentRoleMember(); 563 564 RoleMemberContract rmc = RoleMember.Builder.create(ROLE_ID, ROLE_MEMBER_ID, MEMBER_ID, MEMBER_TYPE, ACTIVE_FROM, 565 ACTIVE_TO, ATTRIBUTES, MEMBER_NAME, MEMBER_NAMESPACE_CODE).build(); 566 RoleMember rm = RoleMember.Builder.create(rmc).build(); 567 RoleMemberBo roleMemberBo = RoleMemberBo.from(rm); 568 roleMemberBo.setObjectId(OBJ_ID); 569 roleMemberBo.setVersionNumber(VER_NUM); 570 571 KimDocumentRoleMember.copyProperties(newKimDocumentRoleMember, roleMemberBo); 572 573 assertTrue("newKimDocumentRoleMember should have a roleId of " + ROLE_ID, 574 newKimDocumentRoleMember.getRoleId().equals(ROLE_ID)); 575 assertTrue("newKimDocumentRoleMember should have a MemberId of " + MEMBER_ID, 576 newKimDocumentRoleMember.getMemberId().equals(MEMBER_ID)); 577 assertTrue("newKimDocumentRoleMember should have a MemberName of " + MEMBER_NAME, 578 newKimDocumentRoleMember.getMemberName().equals(MEMBER_NAME)); 579 assertTrue("newKimDocumentRoleMember should have a MemberNamespaceCode of " + MEMBER_NAMESPACE_CODE, 580 newKimDocumentRoleMember.getMemberNamespaceCode().equals(MEMBER_NAMESPACE_CODE)); 581 assertTrue("newKimDocumentRoleMember should be active.", 582 newKimDocumentRoleMember.isActive()); 583 assertTrue("newKimDocumentRoleMember should have a ActiveToDate of " + MEMBER_NAMESPACE_CODE, 584 newKimDocumentRoleMember.getActiveToDate().equals(roleMemberBo.getActiveToDateValue())); 585 assertTrue("newKimDocumentRoleMember should have a ActiveFromDate of " + ACTIVE_FROM_STRING, 586 newKimDocumentRoleMember.getActiveFromDate().equals(roleMemberBo.getActiveFromDateValue())); 587 assertTrue("newKimDocumentRoleMember should have a VersionNumber of " + VER_NUM, 588 newKimDocumentRoleMember.getVersionNumber().equals(VER_NUM)); 589 assertTrue("newKimDocumentRoleMember should have a ObjectId of " + OBJ_ID, 590 newKimDocumentRoleMember.getObjectId().equals(OBJ_ID)); 591 592 Class<?> c = newKimDocumentRoleMember.getClass(); 593 Field[] fields = c.getDeclaredFields(); 594 List<Field> fieldsList = Arrays.asList(fields); 595 596 int numberOfFieldsInKimDocumentRoleMember = 11; 597 assertTrue("KimDocumentRoleMember.copyProperties may need to be updated if the number of fields" 598 + "in KimDocumentRoleMember does not equal " + numberOfFieldsInKimDocumentRoleMember + ". Size is " + 599 fieldsList.size(), fieldsList.size() == numberOfFieldsInKimDocumentRoleMember); 600 } 601}