1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.impl.identity;
17
18 import org.apache.commons.collections.CollectionUtils;
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.rice.core.api.criteria.QueryByCriteria;
21 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
22 import org.kuali.rice.kim.api.identity.CodedAttribute;
23 import org.kuali.rice.kim.api.identity.IdentityService;
24 import org.kuali.rice.kim.api.identity.address.EntityAddress;
25 import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliation;
26 import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliationType;
27 import org.kuali.rice.kim.api.identity.citizenship.EntityCitizenship;
28 import org.kuali.rice.kim.api.identity.email.EntityEmail;
29 import org.kuali.rice.kim.api.identity.employment.EntityEmployment;
30 import org.kuali.rice.kim.api.identity.entity.Entity;
31 import org.kuali.rice.kim.api.identity.entity.EntityDefault;
32 import org.kuali.rice.kim.api.identity.entity.EntityDefaultQueryResults;
33 import org.kuali.rice.kim.api.identity.entity.EntityQueryResults;
34 import org.kuali.rice.kim.api.identity.external.EntityExternalIdentifier;
35 import org.kuali.rice.kim.api.identity.external.EntityExternalIdentifierType;
36 import org.kuali.rice.kim.api.identity.name.EntityName;
37 import org.kuali.rice.kim.api.identity.personal.EntityBioDemographics;
38 import org.kuali.rice.kim.api.identity.personal.EntityEthnicity;
39 import org.kuali.rice.kim.api.identity.phone.EntityPhone;
40 import org.kuali.rice.kim.api.identity.principal.EntityNamePrincipalName;
41 import org.kuali.rice.kim.api.identity.principal.Principal;
42 import org.kuali.rice.kim.api.identity.principal.PrincipalQueryResults;
43 import org.kuali.rice.kim.api.identity.privacy.EntityPrivacyPreferences;
44 import org.kuali.rice.kim.api.identity.residency.EntityResidency;
45 import org.kuali.rice.kim.api.identity.type.EntityTypeContactInfo;
46 import org.kuali.rice.kim.api.identity.visa.EntityVisa;
47
48 import javax.jws.WebParam;
49 import java.util.ArrayList;
50 import java.util.Collection;
51 import java.util.List;
52 import java.util.Map;
53
54
55
56
57
58
59
60
61 public class IdentityCurrentAndArchivedServiceImpl implements IdentityService {
62 private final IdentityArchiveService identityArchiveService;
63 private final IdentityService innerIdentityService;
64
65
66
67
68
69 public IdentityCurrentAndArchivedServiceImpl(IdentityService innerIdentityService,
70 IdentityArchiveService identityArchiveService) {
71 this.innerIdentityService = innerIdentityService;
72 this.identityArchiveService = identityArchiveService;
73 }
74
75
76
77
78 @Override
79 public CodedAttribute getAddressType(String code) {
80 return getInnerIdentityService().getAddressType(code);
81 }
82
83 @Override
84 public List<CodedAttribute> findAllAddressTypes() {
85 return getInnerIdentityService().findAllAddressTypes();
86 }
87
88 @Override
89 public EntityAffiliationType getAffiliationType(String code) {
90 return getInnerIdentityService().getAffiliationType(code);
91 }
92
93 @Override
94 public List<EntityAffiliationType> findAllAffiliationTypes() {
95 return getInnerIdentityService().findAllAffiliationTypes();
96 }
97
98
99
100
101 @Override
102 public CodedAttribute getCitizenshipStatus(String code) {
103 return CodedAttribute.Builder.create(getInnerIdentityService().getCitizenshipStatus(code)).build();
104 }
105
106 @Override
107 public List<CodedAttribute> findAllCitizenshipStatuses() {
108 return getInnerIdentityService().findAllCitizenshipStatuses();
109 }
110
111 @Override
112 public EntityNamePrincipalName getDefaultNamesForPrincipalId(String principalId) {
113 EntityNamePrincipalName name = getInnerIdentityService().getDefaultNamesForPrincipalId(principalId);
114 if(name == null || name.getDefaultName() == null || StringUtils.isBlank(name.getPrincipalName()) || StringUtils.isBlank(name.getDefaultName().getCompositeName())) {
115 EntityDefault defaultEntity = this.getEntityDefaultByPrincipalId(principalId);
116 if (defaultEntity != null) {
117 EntityNamePrincipalName.Builder nameBuilder = EntityNamePrincipalName.Builder.create();
118 for(Principal principal : defaultEntity.getPrincipals()) {
119 nameBuilder.setPrincipalName(principal.getPrincipalName());
120 }
121 nameBuilder.setDefaultName(EntityName.Builder.create(defaultEntity.getName()));
122 if (StringUtils.isBlank(defaultEntity.getName().getCompositeName())) {
123
124 String lastNameTemp = "";
125 String firstNameTemp= "";
126
127 if (StringUtils.isNotBlank(defaultEntity.getName().getLastName())) {
128 lastNameTemp = defaultEntity.getName().getLastName();
129 }
130 if (StringUtils.isNotBlank(defaultEntity.getName().getFirstName())) {
131 firstNameTemp = defaultEntity.getName().getFirstName();
132 }
133 if (StringUtils.isNotBlank(lastNameTemp) && StringUtils.isNotBlank(firstNameTemp)) {
134 lastNameTemp = lastNameTemp + ", ";
135 }
136
137 String formattedName = (lastNameTemp + firstNameTemp + (defaultEntity.getName().getMiddleName()==null?"":" " + defaultEntity.getName().getMiddleName())).trim();
138 nameBuilder.getDefaultName().setCompositeName(formattedName);
139 }
140 return nameBuilder.build();
141 }
142 }
143 return name;
144 }
145
146 @Override
147 public Map<String, EntityNamePrincipalName> getDefaultNamesForPrincipalIds(List<String> principalIds) {
148
149 Map<String, EntityNamePrincipalName> defaultNames = getInnerIdentityService().getDefaultNamesForPrincipalIds(principalIds);
150 if(defaultNames != null && defaultNames.size() != principalIds.size()) {
151
152 Collection<String> missingPrincipalIds = CollectionUtils.subtract(principalIds, defaultNames.keySet());
153
154 for(String principalId : missingPrincipalIds) {
155 defaultNames.put(principalId, getDefaultNamesForPrincipalId(principalId));
156 }
157 }
158 return defaultNames;
159 }
160
161
162
163
164 @Override
165 public EntityPrivacyPreferences getPrivacyPreferencesForPrincipalId(String principalId) {
166 return getInnerIdentityService().getPrivacyPreferencesForPrincipalId(principalId);
167 }
168
169 @Override
170 public EntityName addNameToEntity(EntityName name) {
171 return getInnerIdentityService().addNameToEntity(name);
172 }
173
174 @Override
175 public EntityName updateName(EntityName name) {
176 return getInnerIdentityService().updateName(name);
177 }
178
179 @Override
180 public EntityName inactivateName(String id) {
181 return getInnerIdentityService().inactivateName(id);
182 }
183
184 @Override
185 public EntityEmployment addEmploymentToEntity(EntityEmployment employment) {
186 return getInnerIdentityService().addEmploymentToEntity(employment);
187 }
188
189 @Override
190 public EntityEmployment updateEmployment(EntityEmployment employment) {
191 return getInnerIdentityService().updateEmployment(employment);
192 }
193
194 @Override
195 public EntityEmployment inactivateEmployment(String id) {
196 return getInnerIdentityService().inactivateEmployment(id);
197 }
198
199 @Override
200 public EntityBioDemographics addBioDemographicsToEntity(EntityBioDemographics bioDemographics) {
201 return getInnerIdentityService().addBioDemographicsToEntity(bioDemographics);
202 }
203
204 @Override
205 public EntityBioDemographics updateBioDemographics(EntityBioDemographics bioDemographics) {
206 return getInnerIdentityService().updateBioDemographics(bioDemographics);
207 }
208
209
210
211
212 @Override
213 public CodedAttribute getEmailType(String code) {
214 return getInnerIdentityService().getEmailType(code);
215 }
216
217 @Override
218 public List<CodedAttribute> findAllEmailTypes() {
219 return getInnerIdentityService().findAllEmailTypes();
220 }
221
222 @Override
223 public PrincipalQueryResults findPrincipals(QueryByCriteria query) throws RiceIllegalArgumentException {
224 return getInnerIdentityService().findPrincipals(query);
225 }
226
227
228
229
230 @Override
231 public CodedAttribute getEmploymentStatus(String code) {
232 return getInnerIdentityService().getEmploymentStatus(code);
233 }
234
235 @Override
236 public List<CodedAttribute> findAllEmploymentStatuses() {
237 return getInnerIdentityService().findAllEmploymentStatuses();
238 }
239
240
241
242
243 @Override
244 public CodedAttribute getEmploymentType(String code) {
245 return getInnerIdentityService().getEmploymentType(code);
246 }
247
248 @Override
249 public List<CodedAttribute> findAllEmploymentTypes() {
250 return getInnerIdentityService().findAllEmploymentTypes();
251 }
252
253
254
255
256
257 @Override
258 public EntityDefault getEntityDefault(String entityId) {
259 EntityDefault entity = getInnerIdentityService().getEntityDefault(entityId);
260 if ( entity == null ) {
261 entity = getIdentityArchiveService().getEntityDefaultFromArchive(entityId);
262 } else {
263 getIdentityArchiveService().saveEntityDefaultToArchive(entity);
264 }
265 return entity;
266 }
267
268
269
270
271
272 @Override
273 public EntityDefault getEntityDefaultByPrincipalId(String principalId) {
274 EntityDefault entity = getInnerIdentityService().getEntityDefaultByPrincipalId(principalId);
275 if ( entity == null ) {
276 entity = getIdentityArchiveService().getEntityDefaultFromArchiveByPrincipalId(principalId);
277 } else {
278 getIdentityArchiveService().saveEntityDefaultToArchive(entity);
279 }
280 return entity;
281 }
282
283
284
285
286
287 @Override
288 public EntityDefault getEntityDefaultByPrincipalName(String principalName) {
289 EntityDefault entity = getInnerIdentityService().getEntityDefaultByPrincipalName(principalName);
290 if ( entity == null ) {
291 entity = getIdentityArchiveService().getEntityDefaultFromArchiveByPrincipalName(principalName);
292 } else {
293 getIdentityArchiveService().saveEntityDefaultToArchive(entity);
294 }
295 return entity;
296 }
297
298
299
300
301
302 @Override
303 public EntityDefault getEntityDefaultByEmployeeId(String employeeId) {
304 EntityDefault entity = getInnerIdentityService().getEntityDefaultByEmployeeId(employeeId);
305 if ( entity == null ) {
306 entity = getIdentityArchiveService().getEntityDefaultFromArchiveByEmployeeId( employeeId );
307 } else {
308 getIdentityArchiveService().saveEntityDefaultToArchive(entity);
309 }
310 return entity;
311 }
312
313 @Override
314 public EntityDefaultQueryResults findEntityDefaults( QueryByCriteria queryByCriteria) {
315 return getInnerIdentityService().findEntityDefaults(queryByCriteria);
316 }
317
318 @Override
319 public EntityQueryResults findEntities(QueryByCriteria queryByCriteria) {
320 return getInnerIdentityService().findEntities(queryByCriteria);
321 }
322
323 @Override
324 public Entity getEntity(String entityId) {
325 return getInnerIdentityService().getEntity(entityId);
326 }
327
328 @Override
329 public Entity getEntityByPrincipalId(String principalId) {
330 return getInnerIdentityService().getEntityByPrincipalId(principalId);
331 }
332
333 @Override
334 public Entity getEntityByPrincipalName(String principalName) {
335 return getInnerIdentityService().getEntityByPrincipalName(principalName);
336 }
337
338 @Override
339 public Entity getEntityByEmployeeId(String employeeId) {
340 return getInnerIdentityService().getEntityByEmployeeId(employeeId);
341 }
342
343 @Override
344 public Entity createEntity(Entity entity) {
345 return getInnerIdentityService().createEntity(entity);
346 }
347
348 @Override
349 public Entity updateEntity(Entity entity) {
350 return getInnerIdentityService().updateEntity(entity);
351 }
352
353 @Override
354 public Entity inactivateEntity(String entityId) {
355 return getInnerIdentityService().inactivateEntity(entityId);
356 }
357
358
359
360
361 @Override
362 public CodedAttribute getNameType(String code) {
363 return getInnerIdentityService().getNameType(code);
364 }
365
366 @Override
367 public List<CodedAttribute> findAllNameTypes() {
368 return getInnerIdentityService().findAllNameTypes();
369 }
370
371 @Override
372 public EntityPrivacyPreferences getEntityPrivacyPreferences(
373 String entityId) {
374 return getInnerIdentityService().getEntityPrivacyPreferences(entityId);
375 }
376
377 @Override
378 public EntityPrivacyPreferences addPrivacyPreferencesToEntity(EntityPrivacyPreferences privacyPreferences) {
379 return getInnerIdentityService().addPrivacyPreferencesToEntity(privacyPreferences);
380 }
381
382 @Override
383 public EntityPrivacyPreferences updatePrivacyPreferences(EntityPrivacyPreferences privacyPreferences) {
384 return getInnerIdentityService().updatePrivacyPreferences(privacyPreferences);
385 }
386
387 @Override
388 public EntityCitizenship addCitizenshipToEntity(EntityCitizenship citizenship) {
389 return getInnerIdentityService().addCitizenshipToEntity(citizenship);
390 }
391
392 @Override
393 public EntityCitizenship updateCitizenship(EntityCitizenship citizenship) {
394 return getInnerIdentityService().updateCitizenship(citizenship);
395 }
396
397 @Override
398 public EntityCitizenship inactivateCitizenship(String id) {
399 return getInnerIdentityService().inactivateCitizenship(id);
400 }
401
402 @Override
403 public EntityEthnicity addEthnicityToEntity(EntityEthnicity ethnicity) {
404 return getInnerIdentityService().addEthnicityToEntity(ethnicity);
405 }
406
407 @Override
408 public EntityEthnicity updateEthnicity(EntityEthnicity ethnicity) {
409 return getInnerIdentityService().updateEthnicity(ethnicity);
410 }
411
412 @Override
413 public EntityResidency addResidencyToEntity(EntityResidency residency) {
414 return getInnerIdentityService().addResidencyToEntity(residency);
415 }
416
417 @Override
418 public EntityResidency updateResidency(EntityResidency residency) {
419 return getInnerIdentityService().updateResidency(residency);
420 }
421
422 @Override
423 public EntityVisa addVisaToEntity(EntityVisa visa) {
424 return getInnerIdentityService().addVisaToEntity(visa);
425 }
426
427 @Override
428 public EntityVisa updateVisa(EntityVisa visa) {
429 return getInnerIdentityService().updateVisa(visa);
430 }
431
432
433
434
435 @Override
436 public CodedAttribute getEntityType(String code) {
437 return getInnerIdentityService().getEntityType(code);
438 }
439
440 @Override
441 public List<CodedAttribute> findAllEntityTypes() {
442 return getInnerIdentityService().findAllEntityTypes();
443 }
444
445 @Override
446 public EntityExternalIdentifierType getExternalIdentifierType(String code) {
447 return getInnerIdentityService().getExternalIdentifierType(code);
448 }
449
450 @Override
451 public List<EntityExternalIdentifierType> findAllExternalIdendtifierTypes() {
452 return getInnerIdentityService().findAllExternalIdendtifierTypes();
453 }
454
455
456
457
458 @Override
459 public CodedAttribute getPhoneType(String code) {
460 return getInnerIdentityService().getPhoneType(code);
461 }
462
463 @Override
464 public List<CodedAttribute> findAllPhoneTypes() {
465 return getInnerIdentityService().findAllPhoneTypes();
466 }
467
468 @Override
469 public Principal getPrincipal(String principalId) {
470 Principal principal = getInnerIdentityService().getPrincipal(principalId);
471 if ( principal == null ) {
472 EntityDefault entity = getEntityDefaultByPrincipalId(principalId);
473 if ( entity != null ) {
474 List<Principal> principals = entity.getPrincipals();
475 if ( principals != null && !principals.isEmpty() ) {
476 principal = principals.get(0);
477 }
478 }
479 }
480 return principal;
481 }
482
483
484
485
486
487
488
489
490
491
492
493
494 @Override
495 public List<Principal> getPrincipals(@WebParam(name = "principalIds") List<String> principalIds) {
496 List<Principal> ret = new ArrayList<Principal>();
497 for(String p: principalIds) {
498 Principal principalInfo = getPrincipal(p);
499
500 if (principalInfo != null) {
501 ret.add(principalInfo) ;
502 }
503 }
504 if (!ret.isEmpty()) {
505 return ret;
506 } else {
507 return null;
508 }
509 }
510
511 @Override
512 public Principal getPrincipalByPrincipalName(String principalName) {
513 Principal principal = getInnerIdentityService().getPrincipalByPrincipalName(principalName);
514 if ( principal == null ) {
515 EntityDefault entity = getEntityDefaultByPrincipalName(principalName);
516 if ( entity != null ) {
517 List<Principal> principals = entity.getPrincipals();
518 if ( principals != null && !principals.isEmpty() ) {
519 principal = principals.get(0);
520 }
521 }
522 }
523 return principal;
524 }
525
526 @Override
527 public List<Principal> getPrincipalsByEntityId(String entityId) {
528 List<Principal> principals = getInnerIdentityService().getPrincipalsByEntityId(entityId);
529 if ( principals == null ) {
530 EntityDefault entity = getIdentityArchiveService().getEntityDefaultFromArchive(entityId);
531 if (entity != null && entity.getPrincipals() != null && !entity.getPrincipals().isEmpty() ) {
532 principals = entity.getPrincipals();
533 }
534 }
535 return principals;
536 }
537
538 @Override
539 public List<Principal> getPrincipalsByEmployeeId(String employeeId) {
540 List<Principal> principals = getInnerIdentityService().getPrincipalsByEmployeeId(employeeId);
541 if ( principals == null ) {
542 EntityDefault entity = getIdentityArchiveService().getEntityDefaultFromArchive(employeeId);
543 if (entity != null && entity.getPrincipals() != null && !entity.getPrincipals().isEmpty() ) {
544 principals = entity.getPrincipals();
545 }
546 }
547 return principals;
548 }
549
550 @Override
551 public Principal getPrincipalByPrincipalNameAndPassword(
552 String principalName, String password) {
553 return getInnerIdentityService().getPrincipalByPrincipalNameAndPassword(
554 principalName, password);
555 }
556
557 @Override
558 public Principal addPrincipalToEntity(Principal principal) {
559 return getInnerIdentityService().addPrincipalToEntity(principal);
560 }
561
562 @Override
563 public Principal updatePrincipal(Principal principal) {
564 return getInnerIdentityService().updatePrincipal(principal);
565 }
566
567 @Override
568 public Principal inactivatePrincipal(String principalId) {
569 return getInnerIdentityService().inactivatePrincipal(principalId);
570 }
571
572 @Override
573 public Principal inactivatePrincipalByName(String principalName) {
574 return getInnerIdentityService().inactivatePrincipalByName(principalName);
575 }
576
577 @Override
578 public EntityTypeContactInfo addEntityTypeContactInfoToEntity(EntityTypeContactInfo entityTypeContactInfo) {
579 return getInnerIdentityService().addEntityTypeContactInfoToEntity(entityTypeContactInfo);
580 }
581
582 @Override
583 public EntityTypeContactInfo updateEntityTypeContactInfo(EntityTypeContactInfo entityTypeContactInfo) {
584 return getInnerIdentityService().updateEntityTypeContactInfo(entityTypeContactInfo);
585 }
586
587 @Override
588 public EntityTypeContactInfo inactivateEntityTypeContactInfo(String entityId, String entityTypeCode) {
589 return getInnerIdentityService().inactivateEntityTypeContactInfo(entityId, entityTypeCode);
590 }
591
592 @Override
593 public EntityAddress addAddressToEntity(EntityAddress address) {
594 return getInnerIdentityService().addAddressToEntity(address);
595 }
596
597 @Override
598 public EntityAddress updateAddress(EntityAddress address) {
599 return getInnerIdentityService().updateAddress(address);
600 }
601
602 @Override
603 public EntityAddress inactivateAddress(String addressId) {
604 return getInnerIdentityService().inactivateAddress(addressId);
605 }
606
607 @Override
608 public EntityEmail addEmailToEntity(EntityEmail email) {
609 return getInnerIdentityService().addEmailToEntity(email);
610 }
611
612 @Override
613 public EntityEmail updateEmail(EntityEmail email) {
614 return getInnerIdentityService().updateEmail(email);
615 }
616
617 @Override
618 public EntityEmail inactivateEmail(String emailId) {
619 return getInnerIdentityService().inactivateEmail(emailId);
620 }
621
622 @Override
623 public EntityPhone addPhoneToEntity(EntityPhone phone) {
624 return getInnerIdentityService().addPhoneToEntity(phone);
625 }
626
627 @Override
628 public EntityPhone updatePhone(EntityPhone phone) {
629 return getInnerIdentityService().updatePhone(phone);
630 }
631
632 @Override
633 public EntityPhone inactivatePhone(String phoneId) {
634 return getInnerIdentityService().inactivatePhone(phoneId);
635 }
636
637 @Override
638 public EntityExternalIdentifier addExternalIdentifierToEntity(EntityExternalIdentifier externalId) {
639 return getInnerIdentityService().addExternalIdentifierToEntity(externalId);
640 }
641
642 @Override
643 public EntityExternalIdentifier updateExternalIdentifier(EntityExternalIdentifier externalId) {
644 return getInnerIdentityService().updateExternalIdentifier(externalId);
645 }
646
647 @Override
648 public EntityAffiliation addAffiliationToEntity(EntityAffiliation affiliation) {
649 return getInnerIdentityService().addAffiliationToEntity(affiliation);
650 }
651
652 @Override
653 public EntityAffiliation updateAffiliation(EntityAffiliation affiliation) {
654 return getInnerIdentityService().updateAffiliation(affiliation);
655 }
656
657 @Override
658 public EntityAffiliation inactivateAffiliation(String id) {
659 return getInnerIdentityService().inactivateAffiliation(id);
660 }
661
662
663 private IdentityService getInnerIdentityService() {
664 return innerIdentityService;
665 }
666
667 private IdentityArchiveService getIdentityArchiveService() {
668 return identityArchiveService;
669 }
670 }