View Javadoc

1   /**
2    * Copyright 2005-2012 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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.kim.api.identity.IdentityService;
21  import org.kuali.rice.kim.api.identity.CodedAttribute;
22  import org.kuali.rice.kim.api.identity.address.EntityAddress;
23  import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliation;
24  import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliationType;
25  import org.kuali.rice.kim.api.identity.citizenship.EntityCitizenship;
26  import org.kuali.rice.kim.api.identity.email.EntityEmail;
27  import org.kuali.rice.kim.api.identity.employment.EntityEmployment;
28  import org.kuali.rice.kim.api.identity.entity.Entity;
29  import org.kuali.rice.kim.api.identity.entity.EntityDefault;
30  import org.kuali.rice.kim.api.identity.entity.EntityDefaultQueryResults;
31  import org.kuali.rice.kim.api.identity.entity.EntityQueryResults;
32  import org.kuali.rice.kim.api.identity.external.EntityExternalIdentifier;
33  import org.kuali.rice.kim.api.identity.external.EntityExternalIdentifierType;
34  import org.kuali.rice.kim.api.identity.name.EntityName;
35  import org.kuali.rice.kim.api.identity.personal.EntityBioDemographics;
36  import org.kuali.rice.kim.api.identity.personal.EntityEthnicity;
37  import org.kuali.rice.kim.api.identity.phone.EntityPhone;
38  import org.kuali.rice.kim.api.identity.principal.EntityNamePrincipalName;
39  import org.kuali.rice.kim.api.identity.principal.Principal;
40  import org.kuali.rice.kim.api.identity.privacy.EntityPrivacyPreferences;
41  import org.kuali.rice.kim.api.identity.residency.EntityResidency;
42  import org.kuali.rice.kim.api.identity.type.EntityTypeContactInfo;
43  import org.kuali.rice.kim.api.identity.visa.EntityVisa;
44  import org.kuali.rice.krad.util.ObjectUtils;
45  
46  import java.util.List;
47  import java.util.Map;
48  
49  /**
50   * This IdentityService implementation is largely just a knee-jerk delegator, except for
51   * getters returning {@link EntityDefault} in which case the IdentityArchiveService
52   * will be invoked if the inner IndentityService impl returns null.
53   * 
54   * @author Kuali Rice Team (rice.collab@kuali.org)
55   */
56  public class IdentityCurrentAndArchivedServiceImpl implements IdentityService {
57  	private final IdentityArchiveService identityArchiveService;
58  	private final IdentityService innerIdentityService;
59  	
60  	/**
61  	 * This constructs a IdentityCurrentAndArchivedServiceImpl, injecting the
62  	 * needed services.
63  	 */
64  	public IdentityCurrentAndArchivedServiceImpl(IdentityService innerIdentityService, 
65  			IdentityArchiveService identityArchiveService) {
66  		this.innerIdentityService = innerIdentityService;
67  		this.identityArchiveService = identityArchiveService;
68  	}
69  	
70  	/**
71  	 * @see org.kuali.rice.kim.api.identity.IdentityService#getAddressType(java.lang.String)
72  	 */
73      @Override
74  	public CodedAttribute getAddressType(String code) {
75  		return getInnerIdentityService().getAddressType(code);
76  	}
77  
78      @Override
79  	public EntityAffiliationType getAffiliationType(String code) {
80  		return getInnerIdentityService().getAffiliationType(code);
81  	}
82  
83      /**
84  	 * @see org.kuali.rice.kim.api.identity.IdentityService#getCitizenshipStatus(java.lang.String)
85  	 */       
86      @Override
87  	public CodedAttribute getCitizenshipStatus(String code) {
88  		return CodedAttribute.Builder.create(getInnerIdentityService().getCitizenshipStatus(code)).build();
89  	}
90      
91      @Override
92  	public EntityNamePrincipalName getDefaultNamesForPrincipalId(String principalId) {
93      	EntityNamePrincipalName name = getInnerIdentityService().getDefaultNamesForPrincipalId(principalId);
94      	if(name == null || ObjectUtils.isNull(name.getDefaultName()) || StringUtils.isBlank(name.getPrincipalName()) || StringUtils.isBlank(name.getDefaultName().getCompositeName())) {
95      		EntityDefault defaultEntity = this.getEntityDefaultByPrincipalId(principalId);
96  			EntityNamePrincipalName.Builder nameBuilder = EntityNamePrincipalName.Builder.create();
97  			for(Principal principal : defaultEntity.getPrincipals()) {
98  				nameBuilder.setPrincipalName(principal.getPrincipalName());
99  			}
100 			nameBuilder.setDefaultName(EntityName.Builder.create(defaultEntity.getName()));
101 			if (StringUtils.isBlank(defaultEntity.getName().getCompositeName())) {
102 				String formattedName = defaultEntity.getName().getLastName() + ", " + defaultEntity.getName().getFirstName() + (defaultEntity.getName().getMiddleName()==null?"":" " + defaultEntity.getName().getMiddleName());
103 				nameBuilder.getDefaultName().setCompositeName(formattedName);
104 			}
105 			return nameBuilder.build();
106     	}
107 		return name;
108 	}
109 
110     @Override
111     public EntityName addNameToEntity(EntityName name) {
112         return getInnerIdentityService().addNameToEntity(name);
113     }
114 
115     @Override
116     public EntityName updateName(EntityName name) {
117         return getInnerIdentityService().updateName(name);
118     }
119 
120     @Override
121     public EntityName inactivateName(String id) {
122         return getInnerIdentityService().inactivateName(id);
123     }
124 
125     @Override
126     public EntityEmployment addEmploymentToEntity(EntityEmployment employment) {
127         return getInnerIdentityService().addEmploymentToEntity(employment);
128     }
129 
130     @Override
131     public EntityEmployment updateEmployment(EntityEmployment employment) {
132         return getInnerIdentityService().updateEmployment(employment);
133     }
134 
135     @Override
136     public EntityEmployment inactivateEmployment(String id) {
137         return getInnerIdentityService().inactivateEmployment(id);
138     }
139 
140     @Override
141     public EntityBioDemographics addBioDemographicsToEntity(EntityBioDemographics bioDemographics) {
142         return getInnerIdentityService().addBioDemographicsToEntity(bioDemographics);
143     }
144 
145     @Override
146     public EntityBioDemographics updateBioDemographics(EntityBioDemographics bioDemographics) {
147         return getInnerIdentityService().updateBioDemographics(bioDemographics);
148     }
149 
150 	/**
151 	 * @see org.kuali.rice.kim.api.identity.IdentityService#getEmailType(java.lang.String)
152 	 */
153     @Override
154 	public CodedAttribute getEmailType(String code) {
155 		return getInnerIdentityService().getEmailType(code);
156 	}
157 
158     /**
159 	 * @see org.kuali.rice.kim.api.identity.IdentityService#getEmploymentStatus(java.lang.String)
160 	 */
161     @Override
162 	public CodedAttribute getEmploymentStatus(String code) {
163 		return getInnerIdentityService().getEmploymentStatus(code);
164 	}
165 
166 
167     /**
168 	 * @see org.kuali.rice.kim.api.identity.IdentityService#getEmploymentType(java.lang.String)
169 	 */
170     @Override
171 	public CodedAttribute getEmploymentType(String code) {
172 		return getInnerIdentityService().getEmploymentType(code);
173 	}
174 
175 
176     /**
177 	 * This method first tries the inner IdentityService impl, and resorts to
178 	 * the IdentityArchiveService if need be.
179 	 */
180     @Override
181 	public EntityDefault getEntityDefault(String entityId) {
182 		EntityDefault entity = getInnerIdentityService().getEntityDefault(entityId);
183     	if ( entity == null ) {
184     		entity = getIdentityArchiveService().getEntityDefaultFromArchive(entityId);
185     	} else {
186 			getIdentityArchiveService().saveEntityDefaultToArchive(entity);
187     	}
188 		return entity;
189 	}
190 
191 	/**
192 	 * This method first tries the inner IdentityService impl, and resorts to
193 	 * the IdentityArchiveService if need be.
194 	 */
195     @Override
196 	public EntityDefault getEntityDefaultByPrincipalId(String principalId) {
197 		EntityDefault entity = getInnerIdentityService().getEntityDefaultByPrincipalId(principalId);
198     	if ( entity == null ) {
199     		entity = getIdentityArchiveService().getEntityDefaultFromArchiveByPrincipalId(principalId);
200     	} else {
201 			getIdentityArchiveService().saveEntityDefaultToArchive(entity);
202     	}
203     	return entity;
204 	}
205 
206 	/**
207 	 * This method first tries the inner IdentityService impl, and resorts to
208 	 * the IdentityArchiveService if need be.
209 	 */
210     @Override
211 	public EntityDefault getEntityDefaultByPrincipalName(String principalName) {
212 		EntityDefault entity = getInnerIdentityService().getEntityDefaultByPrincipalName(principalName);
213     	if ( entity == null ) {
214     		entity = getIdentityArchiveService().getEntityDefaultFromArchiveByPrincipalName(principalName);
215     	} else {
216 			getIdentityArchiveService().saveEntityDefaultToArchive(entity);
217     	}
218     	return entity;
219 	}
220 
221     /**
222      * This method first tries the inner IdentityService impl, and resorts to
223      * the IdentityArchiveService if need be.
224      */
225     @Override
226     public EntityDefault getEntityDefaultByEmployeeId(String employeeId) {
227         EntityDefault entity = getInnerIdentityService().getEntityDefaultByEmployeeId(employeeId);
228         if ( entity == null ) {
229             entity = getIdentityArchiveService().getEntityDefaultFromArchiveByEmployeeId( employeeId );
230         } else {
231             getIdentityArchiveService().saveEntityDefaultToArchive(entity);
232         }
233         return entity;
234     }
235 
236     @Override
237     public EntityDefaultQueryResults findEntityDefaults( QueryByCriteria queryByCriteria) {
238         return getInnerIdentityService().findEntityDefaults(queryByCriteria);
239     }
240 
241     @Override
242     public EntityQueryResults findEntities(QueryByCriteria queryByCriteria) {
243         return getInnerIdentityService().findEntities(queryByCriteria);
244     }
245 
246     @Override
247 	public Entity getEntity(String entityId) {
248 		return getInnerIdentityService().getEntity(entityId);
249 	}
250 
251     @Override
252 	public Entity getEntityByPrincipalId(String principalId) {
253 		return getInnerIdentityService().getEntityByPrincipalId(principalId);
254 	}
255 
256     @Override
257 	public Entity getEntityByPrincipalName(String principalName) {
258 		return getInnerIdentityService().getEntityByPrincipalName(principalName);
259 	}
260     
261     @Override
262 	public Entity getEntityByEmployeeId(String employeeId) {
263 		return getInnerIdentityService().getEntityByEmployeeId(employeeId);
264 	}
265 
266     @Override
267     public Entity createEntity(Entity entity) {
268         return getInnerIdentityService().createEntity(entity);
269     }
270 
271     @Override
272     public Entity updateEntity(Entity entity) {
273         return getInnerIdentityService().updateEntity(entity);
274     }
275 
276     @Override
277     public Entity inactivateEntity(String entityId) {
278         return getInnerIdentityService().inactivateEntity(entityId);
279     }
280 
281     /**
282 	 * @see org.kuali.rice.kim.api.identity.IdentityService#getNameType(java.lang.String)
283 	 */
284     @Override
285 	public CodedAttribute getNameType(String code) {
286 		return getInnerIdentityService().getNameType(code);
287 	}
288 
289     @Override
290 	public EntityPrivacyPreferences getEntityPrivacyPreferences(
291 			String entityId) {
292 		return getInnerIdentityService().getEntityPrivacyPreferences(entityId);
293 	}
294 
295     @Override
296     public EntityPrivacyPreferences addPrivacyPreferencesToEntity(EntityPrivacyPreferences privacyPreferences) {
297         return getInnerIdentityService().addPrivacyPreferencesToEntity(privacyPreferences);
298     }
299 
300     @Override
301     public EntityPrivacyPreferences updatePrivacyPreferences(EntityPrivacyPreferences privacyPreferences) {
302         return getInnerIdentityService().updatePrivacyPreferences(privacyPreferences);
303     }
304 
305     @Override
306     public EntityCitizenship addCitizenshipToEntity(EntityCitizenship citizenship) {
307         return getInnerIdentityService().addCitizenshipToEntity(citizenship);
308     }
309 
310     @Override
311     public EntityCitizenship updateCitizenship(EntityCitizenship citizenship) {
312         return getInnerIdentityService().updateCitizenship(citizenship);
313     }
314 
315     @Override
316     public EntityCitizenship inactivateCitizenship(String id) {
317         return getInnerIdentityService().inactivateCitizenship(id);
318     }
319 
320     @Override
321     public EntityEthnicity addEthnicityToEntity(EntityEthnicity ethnicity) {
322         return getInnerIdentityService().addEthnicityToEntity(ethnicity);
323     }
324 
325     @Override
326     public EntityEthnicity updateEthnicity(EntityEthnicity ethnicity) {
327         return getInnerIdentityService().updateEthnicity(ethnicity);
328     }
329 
330     @Override
331     public EntityResidency addResidencyToEntity(EntityResidency residency) {
332         return getInnerIdentityService().addResidencyToEntity(residency);
333     }
334 
335     @Override
336     public EntityResidency updateResidency(EntityResidency residency) {
337         return getInnerIdentityService().updateResidency(residency);
338     }
339 
340     @Override
341     public EntityVisa addVisaToEntity(EntityVisa visa) {
342         return getInnerIdentityService().addVisaToEntity(visa);
343     }
344 
345     @Override
346     public EntityVisa updateVisa(EntityVisa visa) {
347         return getInnerIdentityService().updateVisa(visa);
348     }
349 
350     /**
351 	 * @see org.kuali.rice.kim.api.identity.IdentityService#getEntityType(java.lang.String)
352 	 */
353     @Override
354 	public CodedAttribute getEntityType(String code) {
355 		return getInnerIdentityService().getEntityType(code);
356 	}
357 
358     @Override
359 	public EntityExternalIdentifierType getExternalIdentifierType(String code) {
360 		return getInnerIdentityService().getExternalIdentifierType(code);
361 	}
362 
363 
364 	/**
365 	 * @see org.kuali.rice.kim.api.identity.IdentityService#getPhoneType(java.lang.String)
366 	 */
367     @Override
368 	public CodedAttribute getPhoneType(String code) {
369 		return getInnerIdentityService().getPhoneType(code);
370 	}
371 
372     @Override
373 	public Principal getPrincipal(String principalId) {
374 		return getInnerIdentityService().getPrincipal(principalId);
375 	}
376 
377     @Override
378 	public Principal getPrincipalByPrincipalName(String principalName) {
379 		return getInnerIdentityService().getPrincipalByPrincipalName(principalName);
380 	}
381 
382     @Override
383 	public Principal getPrincipalByPrincipalNameAndPassword(
384 			String principalName, String password) {
385 		return getInnerIdentityService().getPrincipalByPrincipalNameAndPassword(
386 				principalName, password);
387 	}
388 
389     @Override
390     public Principal addPrincipalToEntity(Principal principal) {
391         return getInnerIdentityService().addPrincipalToEntity(principal);
392     }
393 
394     @Override
395     public Principal updatePrincipal(Principal principal) {
396         return getInnerIdentityService().updatePrincipal(principal);
397     }
398 
399     @Override
400     public Principal inactivatePrincipal(String principalId) {
401         return getInnerIdentityService().inactivatePrincipal(principalId);
402     }
403 
404     @Override
405     public Principal inactivatePrincipalByName(String principalName) {
406         return getInnerIdentityService().inactivatePrincipalByName(principalName);
407     }
408 
409     @Override
410     public EntityTypeContactInfo addEntityTypeContactInfoToEntity(EntityTypeContactInfo entityTypeContactInfo) {
411         return getInnerIdentityService().addEntityTypeContactInfoToEntity(entityTypeContactInfo);
412     }
413 
414     @Override
415     public EntityTypeContactInfo updateEntityTypeContactInfo(EntityTypeContactInfo entityTypeContactInfo) {
416         return getInnerIdentityService().updateEntityTypeContactInfo(entityTypeContactInfo);
417     }
418 
419     @Override
420     public EntityTypeContactInfo inactivateEntityTypeContactInfo(String entityId, String entityTypeCode) {
421         return getInnerIdentityService().inactivateEntityTypeContactInfo(entityId, entityTypeCode);
422     }
423 
424     @Override
425     public EntityAddress addAddressToEntity(EntityAddress address) {
426         return getInnerIdentityService().addAddressToEntity(address);
427     }
428 
429     @Override
430     public EntityAddress updateAddress(EntityAddress address) {
431         return getInnerIdentityService().updateAddress(address);
432     }
433 
434     @Override
435     public EntityAddress inactivateAddress(String addressId) {
436         return getInnerIdentityService().inactivateAddress(addressId);
437     }
438 
439     @Override
440     public EntityEmail addEmailToEntity(EntityEmail email) {
441         return getInnerIdentityService().addEmailToEntity(email);
442     }
443 
444     @Override
445     public EntityEmail updateEmail(EntityEmail email) {
446         return getInnerIdentityService().updateEmail(email);
447     }
448 
449     @Override
450     public EntityEmail inactivateEmail(String emailId) {
451         return getInnerIdentityService().inactivateEmail(emailId);
452     }
453 
454     @Override
455     public EntityPhone addPhoneToEntity(EntityPhone phone) {
456         return getInnerIdentityService().addPhoneToEntity(phone);
457     }
458 
459     @Override
460     public EntityPhone updatePhone(EntityPhone phone) {
461         return getInnerIdentityService().updatePhone(phone);
462     }
463 
464     @Override
465     public EntityPhone inactivatePhone(String phoneId) {
466         return getInnerIdentityService().inactivatePhone(phoneId);
467     }
468 
469     @Override
470     public EntityExternalIdentifier addExternalIdentifierToEntity(EntityExternalIdentifier externalId) {
471         return getInnerIdentityService().addExternalIdentifierToEntity(externalId);
472     }
473 
474     @Override
475     public EntityExternalIdentifier updateExternalIdentifier(EntityExternalIdentifier externalId) {
476         return getInnerIdentityService().updateExternalIdentifier(externalId);
477     }
478 
479     @Override
480     public EntityAffiliation addAffiliationToEntity(EntityAffiliation affiliation) {
481         return getInnerIdentityService().addAffiliationToEntity(affiliation);
482     }
483 
484     @Override
485     public EntityAffiliation updateAffiliation(EntityAffiliation affiliation) {
486         return getInnerIdentityService().updateAffiliation(affiliation);
487     }
488 
489     @Override
490     public EntityAffiliation inactivateAffiliation(String id) {
491         return getInnerIdentityService().inactivateAffiliation(id);
492     }
493 
494 
495 	private IdentityService getInnerIdentityService() {
496 		return innerIdentityService;
497 	}
498 	
499 	private IdentityArchiveService getIdentityArchiveService() {
500 		return identityArchiveService;
501 	}
502 }