1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.test.service;
17
18 import org.junit.Ignore;
19 import org.junit.Test;
20 import org.kuali.rice.core.api.util.type.KualiDecimal;
21 import org.kuali.rice.kew.api.WorkflowDocument;
22 import org.kuali.rice.kew.api.WorkflowDocumentFactory;
23 import org.kuali.rice.kim.api.KimConstants;
24 import org.kuali.rice.kim.api.identity.IdentityService;
25 import org.kuali.rice.kim.api.identity.Person;
26 import org.kuali.rice.kim.api.identity.address.EntityAddressContract;
27 import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliation;
28 import org.kuali.rice.kim.api.identity.email.EntityEmailContract;
29 import org.kuali.rice.kim.api.identity.employment.EntityEmploymentContract;
30 import org.kuali.rice.kim.api.identity.entity.Entity;
31 import org.kuali.rice.kim.api.identity.name.EntityNameContract;
32 import org.kuali.rice.kim.api.identity.phone.EntityPhoneContract;
33 import org.kuali.rice.kim.api.identity.principal.PrincipalContract;
34 import org.kuali.rice.kim.api.identity.type.EntityTypeContactInfo;
35 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
36 import org.kuali.rice.kim.bo.ui.PersonDocumentAddress;
37 import org.kuali.rice.kim.bo.ui.PersonDocumentAffiliation;
38 import org.kuali.rice.kim.bo.ui.PersonDocumentEmail;
39 import org.kuali.rice.kim.bo.ui.PersonDocumentEmploymentInfo;
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.document.IdentityManagementPersonDocument;
45 import org.kuali.rice.kim.framework.type.KimTypeService;
46 import org.kuali.rice.kim.impl.identity.address.EntityAddressTypeBo;
47 import org.kuali.rice.kim.impl.identity.affiliation.EntityAffiliationTypeBo;
48 import org.kuali.rice.kim.impl.identity.email.EntityEmailTypeBo;
49 import org.kuali.rice.kim.impl.identity.name.EntityNameTypeBo;
50 import org.kuali.rice.kim.impl.identity.phone.EntityPhoneTypeBo;
51 import org.kuali.rice.kim.impl.identity.privacy.EntityPrivacyPreferencesBo;
52 import org.kuali.rice.kim.impl.type.KimTypeAttributeBo;
53 import org.kuali.rice.kim.impl.type.KimTypeBo;
54 import org.kuali.rice.kim.service.KIMServiceLocatorInternal;
55 import org.kuali.rice.kim.service.UiDocumentService;
56 import org.kuali.rice.kim.test.KIMTestCase;
57 import org.kuali.rice.kns.kim.type.DataDictionaryTypeServiceBase;
58 import org.kuali.rice.krad.service.KRADServiceLocator;
59 import org.kuali.rice.test.BaselineTestCase;
60
61 import java.lang.reflect.Field;
62 import java.util.ArrayList;
63 import java.util.HashMap;
64 import java.util.List;
65 import java.util.Map;
66
67 import static org.junit.Assert.*;
68
69
70
71
72
73
74
75 @BaselineTestCase.BaselineMode(BaselineTestCase.Mode.CLEAR_DB)
76 public class UiDocumentServiceImplTest extends KIMTestCase {
77
78 private UiDocumentService uiDocumentService;
79
80 @Override
81 public void setUp() throws Exception {
82 super.setUp();
83 uiDocumentService = KIMServiceLocatorInternal.getUiDocumentService();
84 }
85
86 @Test
87 public void testSaveToEntity() {
88 Person adminPerson = KimApiServiceLocator.getPersonService().getPersonByPrincipalName("admin");
89 IdentityManagementPersonDocument personDoc = initPersonDoc();
90
91
92
93 WorkflowDocument document = WorkflowDocumentFactory.createDocument(adminPerson.getPrincipalId(),"TestDocumentType");
94 personDoc.getDocumentHeader().setWorkflowDocument(document);
95
96
97
98 uiDocumentService.saveEntityPerson(personDoc);
99 Map<String, String> criteria = new HashMap<String, String>();
100 criteria.put("id", "entity124eId");
101 criteria.put("entityTypeCode", "PERSON");
102
103 Entity entity = KimApiServiceLocator.getIdentityService().getEntity(personDoc.getEntityId());
104 EntityTypeContactInfo entityType = entity.getEntityTypeContactInfos().get(0);
105 personDoc.getExternalIdentifiers();
106 assertAddressTrue((PersonDocumentAddress)personDoc.getAddrs().get(0), entityType.getAddresses().get(0));
107 assertPhoneTrue((PersonDocumentPhone)personDoc.getPhones().get(0), entityType.getPhoneNumbers().get(0));
108 assertEmailTrue((PersonDocumentEmail)personDoc.getEmails().get(0), entityType.getEmailAddresses().get(0));
109 assertNameTrue((PersonDocumentName) personDoc.getNames().get(0), entity.getNames().get(0));
110 assertPrincipalTrue(personDoc, entity.getPrincipals().get(0));
111
112 assertAffiliationTrue(personDoc.getAffiliations().get(0), entity.getAffiliations().get(0));
113 assertEmpInfoTrue(personDoc.getAffiliations().get(0).getEmpInfos().get(0), entity.getEmploymentInformation().get(0));
114
115
116
117 uiDocumentService.saveEntityPerson(personDoc);
118 Entity entity2 = ((IdentityService) KIMServiceLocatorInternal.getService("kimIdentityDelegateService")).getEntity(
119 personDoc.getEntityId());
120 EntityTypeContactInfo entityType2 = entity2.getEntityTypeContactInfos().get(0);
121 personDoc.getExternalIdentifiers();
122 assertAddressTrue((PersonDocumentAddress)personDoc.getAddrs().get(0), entityType2.getAddresses().get(0));
123 assertPhoneTrue((PersonDocumentPhone)personDoc.getPhones().get(0), entityType2.getPhoneNumbers().get(0));
124 assertEmailTrue((PersonDocumentEmail)personDoc.getEmails().get(0), entityType2.getEmailAddresses().get(0));
125 assertNameTrue((PersonDocumentName)personDoc.getNames().get(0), entity2.getNames().get(0));
126 assertPrincipalTrue(personDoc, entity2.getPrincipals().get(0));
127
128
129
130
131
132
133
134
135
136
137
138
139
140 }
141
142 @Test
143 public void testLoadToPersonDocument() {
144
145 Entity entity = KimApiServiceLocator.getIdentityService().getEntity("entity123eId");
146 assertNotNull(entity);
147 IdentityManagementPersonDocument personDoc = new IdentityManagementPersonDocument();
148 uiDocumentService.loadEntityToPersonDoc(personDoc, "entity123pId");
149 EntityTypeContactInfo entityType = entity.getEntityTypeContactInfos().get(0);
150 personDoc.getExternalIdentifiers();
151 assertAddressTrue((PersonDocumentAddress)personDoc.getAddrs().get(0), entityType.getAddresses().get(0));
152 assertPhoneTrue((PersonDocumentPhone)personDoc.getPhones().get(0), entityType.getPhoneNumbers().get(0));
153 assertEmailTrue((PersonDocumentEmail)personDoc.getEmails().get(0), entityType.getEmailAddresses().get(0));
154 assertNameTrue((PersonDocumentName)personDoc.getNames().get(0), entity.getNames().get(0));
155
156 assertAffiliationTrue(personDoc.getAffiliations().get(0), entity.getAffiliations().get(0));
157 assertEmpInfoTrue(personDoc.getAffiliations().get(0).getEmpInfos().get(0), entity.getEmploymentInformation().get(0));
158
159 }
160
161
162 @Test
163 @Ignore
164 public void testSetAttributeEntry() throws Exception {
165 PersonDocumentRole personDocRole = initPersonDocRole();
166 KimTypeService kimTypeService = (DataDictionaryTypeServiceBase) KIMServiceLocatorInternal.getService(personDocRole.getKimRoleType().getServiceName());
167 personDocRole.setDefinitions(kimTypeService.getAttributeDefinitions(personDocRole.getKimTypeId()));
168
169 personDocRole.setAttributeEntry( uiDocumentService.getAttributeEntries( personDocRole.getDefinitions() ) );
170 for (Object key : personDocRole.getAttributeEntry().keySet()) {
171 if (key.equals(KimConstants.AttributeConstants.NAMESPACE_CODE)) {
172 Map value = (Map)personDocRole.getAttributeEntry().get(key);
173 assertEquals("Parameter Namespace Code", value.get("label"));
174 assertEquals("Nmspc Cd", value.get("shortLabel"));
175 assertEquals(new Integer(20), value.get("maxLength"));
176 } else if (key.equals("campusCode")) {
177 Map value = (Map)personDocRole.getAttributeEntry().get(key);
178 assertEquals("Campus Code", value.get("label"));
179 assertEquals("Campus Code", value.get("shortLabel"));
180 assertEquals(new Integer(2), value.get("maxLength"));
181 } else {
182 assertFalse("Should not have this key "+key, true);
183 }
184 }
185 }
186
187 private PersonDocumentRole initPersonDocRole() throws Exception {
188
189
190
191 PersonDocumentRole docRole = new PersonDocumentRole();
192 docRole.setKimTypeId("roleType1");
193 docRole.setRoleId("r1");
194 KimTypeBo kimType = new KimTypeBo();
195 kimType.setId("roleType1");
196 kimType.setServiceName("kimRoleTypeService");
197 List<KimTypeAttributeBo> attributeDefinitions = new ArrayList<KimTypeAttributeBo>();
198 Map pkMap = new HashMap();
199 pkMap.put("kimTypeAttributeId", "kimAttr3");
200 KimTypeAttributeBo attr1 = (KimTypeAttributeBo) KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(KimTypeAttributeBo.class, pkMap);
201
202
203
204
205
206 attributeDefinitions.add(attr1);
207
208
209
210
211
212 pkMap.put("kimTypeAttributeId", "kimAttr4");
213 KimTypeAttributeBo attr2 = (KimTypeAttributeBo) KRADServiceLocator.getBusinessObjectService().findByPrimaryKey(KimTypeAttributeBo.class, pkMap);
214
215 attributeDefinitions.add(attr2);
216 kimType.setAttributeDefinitions(attributeDefinitions);
217
218 Field fld = PersonDocumentRole.class.getField("kimRoleType");
219 fld.set(docRole, kimType);
220
221 return docRole;
222 }
223
224
225 private IdentityManagementPersonDocument initPersonDoc() {
226 IdentityManagementPersonDocument personDoc = new IdentityManagementPersonDocument();
227 personDoc.setEntityId("ent123");
228 personDoc.setDocumentNumber("1");
229 personDoc.setPrincipalId("pid123");
230 personDoc.setPrincipalName("test");
231
232 personDoc.setAffiliations(initAffiliations());
233 personDoc.setNames(initNames());
234 personDoc.setAddrs(initAddresses());
235
236
237 personDoc.setPhones(initPhones());
238 personDoc.setEmails(initEmails());
239 return personDoc;
240 }
241
242 private List<PersonDocumentName> initNames() {
243 List<PersonDocumentName> docNames = new ArrayList<PersonDocumentName>();
244 PersonDocumentName docName = new PersonDocumentName();
245 docName.setEntityNameId("nameId123");
246 docName.setNameCode("PRFR");
247 docName.setEntityNameType(
248 EntityNameTypeBo.from(KimApiServiceLocator.getIdentityService().getNameType("PRFR")));
249 docName.setFirstName("John");
250 docName.setLastName("Doe");
251 docName.setMiddleName("M");
252 docName.setNamePrefix("Mr");
253 docName.setNameSuffix("Jr");
254 docName.setActive(true);
255 docName.setDflt(true);
256 docNames.add(docName);
257 return docNames;
258 }
259
260 private List<PersonDocumentAffiliation> initAffiliations() {
261 List<PersonDocumentAffiliation> docAffiliations = new ArrayList<PersonDocumentAffiliation>();
262 PersonDocumentAffiliation docAffiliation = new PersonDocumentAffiliation();
263 docAffiliation.setAffiliationTypeCode("FCLTY");
264 docAffiliation.setAffiliationType(
265 EntityAffiliationTypeBo.from(KimApiServiceLocator.getIdentityService().getAffiliationType("FCLTY")));
266 docAffiliation.setEntityAffiliationId("aflID123");
267 docAffiliation.setCampusCode("BL");
268 docAffiliation.setActive(true);
269 docAffiliation.setDflt(true);
270
271
272 docAffiliations.add(docAffiliation);
273 List<PersonDocumentEmploymentInfo> docEmploymentInformations = new ArrayList<PersonDocumentEmploymentInfo>();
274 PersonDocumentEmploymentInfo docEmpInfo = new PersonDocumentEmploymentInfo();
275 docEmpInfo.setEmployeeId("12345");
276 docEmpInfo.setEntityAffiliationId(docAffiliation.getEntityAffiliationId());
277 docEmpInfo.setEntityEmploymentId("empId123");
278 docEmpInfo.setEmploymentRecordId("1");
279 docEmpInfo.setBaseSalaryAmount(new KualiDecimal(8000));
280 docEmpInfo.setPrimaryDepartmentCode("BL-CHEM");
281 docEmpInfo.setEmploymentStatusCode("A");
282 docEmpInfo.setEmploymentTypeCode("P");
283 docEmpInfo.setActive(true);
284 docEmploymentInformations.add(docEmpInfo);
285 docAffiliation.setEmpInfos(docEmploymentInformations);
286
287 return docAffiliations;
288
289 }
290
291 private PersonDocumentPrivacy initPrivacyReferences(EntityPrivacyPreferencesBo privacyPreferences) {
292 PersonDocumentPrivacy docPrivacy = new PersonDocumentPrivacy();
293 docPrivacy.setSuppressAddress(true);
294 docPrivacy.setSuppressEmail(false);
295 docPrivacy.setSuppressName(false);
296 docPrivacy.setSuppressPhone(false);
297 docPrivacy.setSuppressPersonal(true);
298 return docPrivacy;
299 }
300 private List<PersonDocumentPhone> initPhones() {
301 List<PersonDocumentPhone> docPhones = new ArrayList<PersonDocumentPhone>();
302 PersonDocumentPhone docPhone = new PersonDocumentPhone();
303 docPhone.setPhoneTypeCode("HM");
304 docPhone.setPhoneType(EntityPhoneTypeBo.from(KimApiServiceLocator.getIdentityService().getPhoneType("HM")));
305 docPhone.setEntityPhoneId("phoneId123");
306 docPhone.setEntityTypeCode("PERSON");
307 docPhone.setPhoneNumber("123-45'6789");
308 docPhone.setExtensionNumber("123");
309 docPhone.setActive(true);
310 docPhone.setDflt(true);
311 docPhones.add(docPhone);
312 return docPhones;
313
314 }
315
316 private List<PersonDocumentEmail> initEmails() {
317 List<PersonDocumentEmail> emails = new ArrayList<PersonDocumentEmail>();
318 PersonDocumentEmail docEmail = new PersonDocumentEmail();
319
320 docEmail.setEntityEmailId("emailId123");
321 docEmail.setEntityTypeCode("PERSON");
322 docEmail.setEmailTypeCode("HM");
323 docEmail.setEmailType(
324 EntityEmailTypeBo.from(KimApiServiceLocator.getIdentityService().getEmailType("HM")));
325 docEmail.setEmailAddress("test@abc.com");
326 docEmail.setActive(true);
327 docEmail.setDflt(true);
328 emails.add(docEmail);
329 return emails;
330 }
331
332 private List<PersonDocumentAddress> initAddresses() {
333 List<PersonDocumentAddress> docAddresses = new ArrayList<PersonDocumentAddress>();
334 PersonDocumentAddress docAddress = new PersonDocumentAddress();
335 docAddress.setEntityTypeCode("PERSON");
336 docAddress.setEntityAddressId("addrId123");
337 docAddress.setAddressTypeCode("HM");
338 docAddress.setAddressType(EntityAddressTypeBo.from(KimApiServiceLocator.getIdentityService().getAddressType("HM")));
339 docAddress.setLine1("PO box 123");
340 docAddress.setStateProvinceCode("IN");
341 docAddress.setPostalCode("46123");
342 docAddress.setCountryCode("US");
343 docAddress.setCity("Indianapolis");
344 docAddress.setActive(true);
345 docAddress.setDflt(true);
346 docAddresses.add(docAddress);
347 return docAddresses;
348 }
349
350
351
352 private void assertPrincipalTrue(IdentityManagementPersonDocument personDoc, PrincipalContract principal) {
353 assertEquals(personDoc.getPrincipalId(), principal.getPrincipalId());
354 assertEquals(personDoc.getPrincipalName(), principal.getPrincipalName());
355 }
356
357 private void assertAddressTrue(PersonDocumentAddress docAddress, EntityAddressContract entityAddress) {
358
359 assertEquals(docAddress.getAddressTypeCode(), entityAddress.getAddressType().getCode());
360 assertEquals(docAddress.getCountryCode(), entityAddress.getCountryCode());
361 assertEquals(docAddress.getLine1(), entityAddress.getLine1());
362 assertEquals(docAddress.getCity(), entityAddress.getCity());
363 assertEquals(docAddress.getPostalCode(), entityAddress.getPostalCode());
364 assertEquals(docAddress.getStateProvinceCode(), entityAddress.getStateProvinceCode());
365 }
366
367 private void assertEmailTrue(PersonDocumentEmail docEmail, EntityEmailContract entityEmail) {
368 assertEquals(docEmail.getEntityEmailId(), entityEmail.getId());
369 assertEquals(docEmail.getEmailAddress(), entityEmail.getEmailAddressUnmasked());
370 assertEquals(docEmail.getEmailTypeCode(), entityEmail.getEmailType().getCode());
371 }
372
373 private void assertPhoneTrue(PersonDocumentPhone docPhone, EntityPhoneContract entityPhone) {
374 assertEquals(docPhone.getEntityPhoneId(), entityPhone.getId());
375 assertEquals(docPhone.getCountryCode(), entityPhone.getCountryCode());
376 assertEquals(docPhone.getPhoneNumber(), entityPhone.getPhoneNumber());
377 assertEquals(docPhone.getExtensionNumber(), entityPhone.getExtensionNumber());
378 assertEquals(docPhone.getPhoneTypeCode(), entityPhone.getPhoneType().getCode());
379 }
380
381 private void assertNameTrue(PersonDocumentName docName, EntityNameContract entityName) {
382 assertEquals(docName.getEntityNameId(), entityName.getId());
383 assertEquals(docName.getFirstName(), entityName.getFirstName());
384 assertEquals(docName.getLastName(), entityName.getLastName());
385 assertEquals(docName.getNameCode(), entityName.getNameType().getCode());
386 assertEquals(docName.getNameSuffix(), entityName.getNameSuffix());
387 assertEquals(docName.getNamePrefix(), entityName.getNamePrefix());
388 }
389
390 private void assertAffiliationTrue(PersonDocumentAffiliation docAffln, EntityAffiliation entityAffln) {
391 assertEquals(docAffln.getAffiliationTypeCode(), entityAffln.getAffiliationType().getCode());
392 assertEquals(docAffln.getCampusCode(), entityAffln.getCampusCode());
393 assertEquals(docAffln.getEntityAffiliationId(), entityAffln.getId());
394 }
395
396 private void assertEmpInfoTrue(PersonDocumentEmploymentInfo docEmpInfo, EntityEmploymentContract entityEmpInfo) {
397 assertEquals(docEmpInfo.getEmployeeId(), entityEmpInfo.getEmployeeId());
398 assertEquals(docEmpInfo.getEmploymentTypeCode(), entityEmpInfo.getEmployeeType().getCode());
399 assertEquals(docEmpInfo.getEmploymentStatusCode(), entityEmpInfo.getEmployeeStatus().getCode());
400 assertEquals(docEmpInfo.getEmploymentRecordId(), entityEmpInfo.getEmploymentRecordId());
401 assertEquals(docEmpInfo.getBaseSalaryAmount(), entityEmpInfo.getBaseSalaryAmount());
402 }
403
404
405 }