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