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