View Javadoc

1   /**
2    * Copyright 2005-2013 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.api.identity.entity;
17  
18  import org.apache.commons.collections.CollectionUtils;
19  import org.apache.commons.lang.StringUtils;
20  import org.kuali.rice.core.api.CoreConstants;
21  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
22  import org.kuali.rice.core.api.mo.ModelBuilder;
23  import org.kuali.rice.core.api.mo.ModelObjectUtils;
24  import org.kuali.rice.kim.api.KimConstants;
25  import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliation;
26  import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliationContract;
27  import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliationHistory;
28  import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliationHistoryContract;
29  import org.kuali.rice.kim.api.identity.citizenship.EntityCitizenship;
30  import org.kuali.rice.kim.api.identity.citizenship.EntityCitizenshipContract;
31  import org.kuali.rice.kim.api.identity.citizenship.EntityCitizenshipHistory;
32  import org.kuali.rice.kim.api.identity.citizenship.EntityCitizenshipHistoryContract;
33  import org.kuali.rice.kim.api.identity.employment.EntityEmployment;
34  import org.kuali.rice.kim.api.identity.employment.EntityEmploymentContract;
35  import org.kuali.rice.kim.api.identity.employment.EntityEmploymentHistory;
36  import org.kuali.rice.kim.api.identity.employment.EntityEmploymentHistoryContract;
37  import org.kuali.rice.kim.api.identity.external.EntityExternalIdentifier;
38  import org.kuali.rice.kim.api.identity.external.EntityExternalIdentifierContract;
39  import org.kuali.rice.kim.api.identity.external.EntityExternalIdentifierHistory;
40  import org.kuali.rice.kim.api.identity.external.EntityExternalIdentifierHistoryContract;
41  import org.kuali.rice.kim.api.identity.name.EntityName;
42  import org.kuali.rice.kim.api.identity.name.EntityNameContract;
43  import org.kuali.rice.kim.api.identity.name.EntityNameHistory;
44  import org.kuali.rice.kim.api.identity.name.EntityNameHistoryContract;
45  import org.kuali.rice.kim.api.identity.personal.EntityBioDemographics;
46  import org.kuali.rice.kim.api.identity.personal.EntityBioDemographicsHistory;
47  import org.kuali.rice.kim.api.identity.personal.EntityEthnicity;
48  import org.kuali.rice.kim.api.identity.personal.EntityEthnicityContract;
49  import org.kuali.rice.kim.api.identity.personal.EntityEthnicityHistory;
50  import org.kuali.rice.kim.api.identity.personal.EntityEthnicityHistoryContract;
51  import org.kuali.rice.kim.api.identity.principal.Principal;
52  import org.kuali.rice.kim.api.identity.principal.PrincipalContract;
53  import org.kuali.rice.kim.api.identity.principal.PrincipalHistory;
54  import org.kuali.rice.kim.api.identity.principal.PrincipalHistoryContract;
55  import org.kuali.rice.kim.api.identity.privacy.EntityPrivacyHistory;
56  import org.kuali.rice.kim.api.identity.privacy.EntityPrivacyPreferences;
57  import org.kuali.rice.kim.api.identity.residency.EntityResidency;
58  import org.kuali.rice.kim.api.identity.residency.EntityResidencyContract;
59  import org.kuali.rice.kim.api.identity.residency.EntityResidencyHistory;
60  import org.kuali.rice.kim.api.identity.residency.EntityResidencyHistoryContract;
61  import org.kuali.rice.kim.api.identity.type.EntityTypeContactInfo;
62  import org.kuali.rice.kim.api.identity.type.EntityTypeContactInfoContract;
63  import org.kuali.rice.kim.api.identity.type.EntityTypeContactInfoHistory;
64  import org.kuali.rice.kim.api.identity.type.EntityTypeContactInfoHistoryContract;
65  import org.kuali.rice.kim.api.identity.visa.EntityVisa;
66  import org.kuali.rice.kim.api.identity.visa.EntityVisaContract;
67  import org.kuali.rice.kim.api.identity.visa.EntityVisaHistory;
68  import org.kuali.rice.kim.api.identity.visa.EntityVisaHistoryContract;
69  import org.w3c.dom.Element;
70  
71  import javax.xml.bind.annotation.XmlAccessType;
72  import javax.xml.bind.annotation.XmlAccessorType;
73  import javax.xml.bind.annotation.XmlAnyElement;
74  import javax.xml.bind.annotation.XmlElement;
75  import javax.xml.bind.annotation.XmlElementWrapper;
76  import javax.xml.bind.annotation.XmlRootElement;
77  import javax.xml.bind.annotation.XmlType;
78  import java.io.Serializable;
79  import java.util.ArrayList;
80  import java.util.Collection;
81  import java.util.List;
82  
83  @XmlRootElement(name = EntityHistory.Constants.ROOT_ELEMENT_NAME)
84  @XmlAccessorType(XmlAccessType.NONE)
85  @XmlType(name = EntityHistory.Constants.TYPE_NAME, propOrder = {
86      EntityHistory.Elements.ID,
87      EntityHistory.Elements.PRINCIPALS,
88      EntityHistory.Elements.ENTITY_TYPE_CONTACT_INFOS,
89      EntityHistory.Elements.EXTERNAL_IDENTIFIERS,
90      EntityHistory.Elements.AFFILIATIONS,
91      EntityHistory.Elements.NAMES,
92      EntityHistory.Elements.EMPLOYMENT_INFORMATION,
93      EntityHistory.Elements.PRIVACY_PREFERENCES,
94      EntityHistory.Elements.BIO_DEMOGRAPHICS,
95      EntityHistory.Elements.CITIZENSHIPS,
96      EntityHistory.Elements.PRIMARY_EMPLOYMENT,
97      EntityHistory.Elements.DEFAULT_AFFILIATION,
98      EntityHistory.Elements.DEFAULT_NAME,
99      EntityHistory.Elements.ETHNICITIES,
100     EntityHistory.Elements.RESIDENCIES,
101     EntityHistory.Elements.VISAS,
102     CoreConstants.CommonElements.VERSION_NUMBER,
103     CoreConstants.CommonElements.OBJECT_ID,
104     EntityHistory.Elements.ACTIVE,
105     CoreConstants.CommonElements.FUTURE_ELEMENTS
106 })
107 public final class EntityHistory extends AbstractDataTransferObject
108     implements EntityContract
109 {
110     private static final long serialVersionUID = 6506056736804182758L;
111     @XmlElement(name = Elements.ID, required = false)
112     private final String id;
113 
114     @XmlElementWrapper(name = Elements.PRINCIPALS, required = false)
115     @XmlElement(name = Elements.PRINCIPAL, required = false)
116     private final List<PrincipalHistory> principals;
117 
118     @XmlElementWrapper(name = Elements.ENTITY_TYPE_CONTACT_INFOS, required = false)
119     @XmlElement(name = Elements.ENTITY_TYPE_CONTACT_INFO, required = false)
120     private final List<EntityTypeContactInfoHistory> entityTypeContactInfos;
121 
122     @XmlElementWrapper(name = Elements.EXTERNAL_IDENTIFIERS, required = false)
123     @XmlElement(name = Elements.EXTERNAL_IDENTIFIER, required = false)
124     private final List<EntityExternalIdentifierHistory> externalIdentifiers;
125 
126     @XmlElementWrapper(name = Elements.AFFILIATIONS, required = false)
127     @XmlElement(name = Elements.AFFILIATION, required = false)
128     private final List<EntityAffiliationHistory> affiliations;
129 
130     @XmlElementWrapper(name = Elements.NAMES, required = false)
131     @XmlElement(name = Elements.NAME, required = false)
132     private final List<EntityNameHistory> names;
133 
134     @XmlElementWrapper(name = Elements.EMPLOYMENT_INFORMATION, required = false)
135     @XmlElement(name = Elements.EMPLOYMENT, required = false)
136     private final List<EntityEmploymentHistory> employmentInformation;
137 
138     @XmlElement(name = Elements.PRIVACY_PREFERENCES, required = false)
139     private final EntityPrivacyHistory privacyPreferences;
140 
141     @XmlElement(name = Elements.BIO_DEMOGRAPHICS, required = false)
142     private final EntityBioDemographicsHistory bioDemographics;
143 
144     @XmlElementWrapper(name = Elements.CITIZENSHIPS, required = false)
145     @XmlElement(name = Elements.CITIZENSHIP, required = false)
146     private final List<EntityCitizenshipHistory> citizenships;
147 
148     @XmlElement(name = Elements.PRIMARY_EMPLOYMENT, required = false)
149     private final EntityEmploymentHistory primaryEmployment;
150 
151     @XmlElement(name = Elements.DEFAULT_AFFILIATION, required = false)
152     private final EntityAffiliationHistory defaultAffiliation;
153 
154     @XmlElement(name = Elements.DEFAULT_NAME, required = false)
155     private final EntityNameHistory defaultName;
156 
157     @XmlElementWrapper(name = Elements.ETHNICITIES, required = false)
158     @XmlElement(name = Elements.ETHNICITY, required = false)
159     private final List<EntityEthnicityHistory> ethnicities;
160 
161     @XmlElementWrapper(name = Elements.RESIDENCIES, required = false)
162     @XmlElement(name = Elements.RESIDENCY, required = false)
163     private final List<EntityResidencyHistory> residencies;
164 
165     @XmlElementWrapper(name = Elements.VISAS, required = false)
166     @XmlElement(name = Elements.VISA, required = false)
167     private final List<EntityVisaHistory> visas;
168 
169     @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
170     private final Long versionNumber;
171 
172     @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
173     private final String objectId;
174 
175     @XmlElement(name = Elements.ACTIVE, required = false)
176     private final boolean active;
177 
178     @SuppressWarnings("unused")
179     @XmlAnyElement
180     private final Collection<Element> _futureElements = null;
181 
182     /**
183      * Private constructor used only by JAXB.
184      *
185      */
186     private EntityHistory() {
187         this.principals = null;
188         this.entityTypeContactInfos = null;
189         this.externalIdentifiers = null;
190         this.affiliations = null;
191         this.names = null;
192         this.employmentInformation = null;
193         this.privacyPreferences = null;
194         this.bioDemographics = null;
195         this.citizenships = null;
196         this.primaryEmployment = null;
197         this.defaultAffiliation = null;
198         this.defaultName = null;
199         this.ethnicities = null;
200         this.residencies = null;
201         this.visas = null;
202         this.versionNumber = null;
203         this.objectId = null;
204         this.active = false;
205         this.id = null;
206     }
207 
208     private EntityHistory(Builder builder) {
209         this.principals = ModelObjectUtils.buildImmutableCopy(builder.getPrincipals());
210         this.entityTypeContactInfos = ModelObjectUtils.buildImmutableCopy(builder.getEntityTypeContactInfos());
211         this.externalIdentifiers = ModelObjectUtils.buildImmutableCopy(builder.getExternalIdentifiers());
212         this.affiliations = ModelObjectUtils.buildImmutableCopy(builder.getAffiliations());
213         this.names = ModelObjectUtils.buildImmutableCopy(builder.getNames());
214         this.employmentInformation = ModelObjectUtils.buildImmutableCopy(builder.getEmploymentInformation());
215         this.privacyPreferences = ModelObjectUtils.buildImmutable(builder.getPrivacyPreferences());
216         this.bioDemographics = ModelObjectUtils.buildImmutable(builder.getBioDemographics());
217         this.citizenships = ModelObjectUtils.buildImmutableCopy(builder.getCitizenships());
218         this.primaryEmployment = ModelObjectUtils.buildImmutable(builder.getPrimaryEmployment());
219         this.defaultAffiliation = ModelObjectUtils.buildImmutable(builder.getDefaultAffiliation());
220         this.defaultName = ModelObjectUtils.buildImmutable(builder.getDefaultName());
221         this.ethnicities = ModelObjectUtils.buildImmutableCopy(builder.getEthnicities());
222         this.residencies = ModelObjectUtils.buildImmutableCopy(builder.getResidencies());
223         this.visas = ModelObjectUtils.buildImmutableCopy(builder.getVisas());
224         this.versionNumber = builder.getVersionNumber();
225         this.objectId = builder.getObjectId();
226         this.active = builder.isActive();
227         this.id = builder.getId();
228     }
229 
230     @Override
231     public List<PrincipalHistory> getPrincipals() {
232         return this.principals;
233     }
234 
235     @Override
236     public List<EntityTypeContactInfoHistory> getEntityTypeContactInfos() {
237         return this.entityTypeContactInfos;
238     }
239 
240     @Override
241     public List<EntityExternalIdentifierHistory> getExternalIdentifiers() {
242         return this.externalIdentifiers;
243     }
244 
245     @Override
246     public List<EntityAffiliationHistory> getAffiliations() {
247         return this.affiliations;
248     }
249 
250     @Override
251     public List<EntityNameHistory> getNames() {
252         return this.names;
253     }
254 
255     @Override
256     public List<EntityEmploymentHistory> getEmploymentInformation() {
257         return this.employmentInformation;
258     }
259 
260     @Override
261     public EntityPrivacyHistory getPrivacyPreferences() {
262         return this.privacyPreferences;
263     }
264 
265     @Override
266     public EntityBioDemographicsHistory getBioDemographics() {
267         return this.bioDemographics;
268     }
269 
270     @Override
271     public List<EntityCitizenshipHistory> getCitizenships() {
272         return this.citizenships;
273     }
274 
275     @Override
276     public EntityEmploymentHistory getPrimaryEmployment() {
277         return this.primaryEmployment;
278     }
279 
280     @Override
281     public EntityAffiliationHistory getDefaultAffiliation() {
282         return this.defaultAffiliation;
283     }
284 
285     @Override
286     public EntityExternalIdentifierHistory getEntityExternalIdentifier(String externalIdentifierTypeCode) {
287         if (externalIdentifiers == null) {
288             return null;
289         }
290         for (EntityExternalIdentifierHistory externalId : externalIdentifiers) {
291             if (externalId.getExternalIdentifierTypeCode().equals(externalIdentifierTypeCode)) {
292                 return externalId;
293             }
294         }
295         return null;
296     }
297 
298     @Override
299     public EntityNameHistory getDefaultName() {
300         return this.defaultName;
301     }
302 
303     @Override
304     public List<EntityEthnicityHistory> getEthnicities() {
305         return this.ethnicities;
306     }
307 
308     @Override
309     public List<EntityResidencyHistory> getResidencies() {
310         return this.residencies;
311     }
312 
313     @Override
314     public List<EntityVisaHistory> getVisas() {
315         return this.visas;
316     }
317 
318     @Override
319     public Long getVersionNumber() {
320         return this.versionNumber;
321     }
322 
323     @Override
324     public String getObjectId() {
325         return this.objectId;
326     }
327 
328     @Override
329     public boolean isActive() {
330         return this.active;
331     }
332 
333     @Override
334     public String getId() {
335         return this.id;
336     }
337 
338     public EntityTypeContactInfoHistory getEntityTypeContactInfoByTypeCode(String entityTypeCode) {
339         if (entityTypeContactInfos == null) {
340             return null;
341         }
342         for (EntityTypeContactInfoHistory entType : entityTypeContactInfos) {
343             if (entType.getEntityTypeCode().equals(entityTypeCode)) {
344                 return entType;
345             }
346         }
347         return null;
348     }
349 
350     /**
351      * A builder which can be used to construct {@link org.kuali.rice.kim.api.identity.entity.EntityHistory} instances.  Enforces the constraints of the {@link org.kuali.rice.kim.api.identity.entity.EntityContract}.
352      *
353      */
354     public final static class Builder
355         implements Serializable, ModelBuilder, EntityContract
356     {
357 
358         private List<PrincipalHistory.Builder> principals;
359         private List<EntityTypeContactInfoHistory.Builder> entityTypeContactInfos;
360         private List<EntityExternalIdentifierHistory.Builder> externalIdentifiers;
361         private List<EntityAffiliationHistory.Builder> affiliations;
362         private List<EntityNameHistory.Builder> names;
363         private List<EntityEmploymentHistory.Builder> employmentInformation;
364         private EntityPrivacyHistory.Builder privacyPreferences;
365         private EntityBioDemographicsHistory.Builder bioDemographics;
366         private List<EntityCitizenshipHistory.Builder> citizenships;
367         private List<EntityEthnicityHistory.Builder> ethnicities;
368         private List<EntityResidencyHistory.Builder> residencies;
369         private List<EntityVisaHistory.Builder> visas;
370         private Long versionNumber;
371         private String objectId;
372         private boolean active;
373         private String id;
374 
375         private Builder() { }
376 
377         public static Builder create() {
378             return new Builder();
379         }
380 
381         public static Builder create(EntityHistoryContract contract) {
382             if (contract == null) {
383                 throw new IllegalArgumentException("contract was null");
384             }
385             Builder builder = create();
386             if (contract.getPrincipals() != null) {
387                 List<PrincipalHistory.Builder> tempPrincipals = new ArrayList<PrincipalHistory.Builder>();
388                 for (PrincipalHistoryContract principal : contract.getPrincipals()) {
389                     tempPrincipals.add(PrincipalHistory.Builder.create(principal));
390                 }
391                 builder.setPrincipals(tempPrincipals);
392             }
393             if (contract.getEntityTypeContactInfos() != null) {
394                 List<EntityTypeContactInfoHistory.Builder> tempTypeData = new ArrayList<EntityTypeContactInfoHistory.Builder>();
395                 for (EntityTypeContactInfoHistoryContract typeData : contract.getEntityTypeContactInfos()) {
396                     tempTypeData.add(EntityTypeContactInfoHistory.Builder.create(typeData));
397                 }
398                 builder.setEntityTypes(tempTypeData);
399             }
400             if (contract.getExternalIdentifiers() != null) {
401                 List<EntityExternalIdentifierHistory.Builder> externalIds = new ArrayList<EntityExternalIdentifierHistory.Builder>();
402                 for (EntityExternalIdentifierHistoryContract externalId : contract.getExternalIdentifiers()) {
403                     externalIds.add(EntityExternalIdentifierHistory.Builder.create(externalId));
404                 }
405                 builder.setExternalIdentifiers(externalIds);
406             }
407             if (contract.getAffiliations() != null) {
408                 List<EntityAffiliationHistory.Builder> affils = new ArrayList<EntityAffiliationHistory.Builder>();
409                 for (EntityAffiliationHistoryContract affil : contract.getAffiliations()) {
410                     affils.add(EntityAffiliationHistory.Builder.create(affil));
411                 }
412                 builder.setAffiliations(affils);
413             }
414             if (contract.getNames() != null) {
415                 List<EntityNameHistory.Builder> nms = new ArrayList<EntityNameHistory.Builder>();
416                 for (EntityNameHistoryContract nm : contract.getNames()) {
417                     nms.add(EntityNameHistory.Builder.create(nm));
418                 }
419                 builder.setNames(nms);
420             }
421             if (contract.getEmploymentInformation() != null) {
422                 List<EntityEmploymentHistory.Builder> emps = new ArrayList<EntityEmploymentHistory.Builder>();
423                 for (EntityEmploymentHistoryContract emp : contract.getEmploymentInformation()) {
424                     emps.add(EntityEmploymentHistory.Builder.create(emp));
425                 }
426                 builder.setEmploymentInformation(emps);
427             }
428             builder.setPrivacyPreferences(contract.getPrivacyPreferences() == null ? null : EntityPrivacyHistory.Builder.create(contract.getPrivacyPreferences()));
429             builder.setBioDemographics(contract.getBioDemographics() == null ? null : EntityBioDemographicsHistory.Builder.create(contract.getBioDemographics()));
430             if (contract.getCitizenships() != null) {
431                 List<EntityCitizenshipHistory.Builder> cits = new ArrayList<EntityCitizenshipHistory.Builder>();
432                 for (EntityCitizenshipHistoryContract cit : contract.getCitizenships()) {
433                     cits.add(EntityCitizenshipHistory.Builder.create(cit));
434                 }
435                 builder.setCitizenships(cits);
436             }
437             if (contract.getEthnicities() != null) {
438                 List<EntityEthnicityHistory.Builder> ethnctys = new ArrayList<EntityEthnicityHistory.Builder>();
439                 for (EntityEthnicityHistoryContract ethncty : contract.getEthnicities()) {
440                     ethnctys.add(EntityEthnicityHistory.Builder.create(ethncty));
441                 }
442                 builder.setEthnicities(ethnctys);
443             }
444             if (contract.getResidencies() != null) {
445                 List<EntityResidencyHistory.Builder> residencyBuilders = new ArrayList<EntityResidencyHistory.Builder>();
446                 for (EntityResidencyHistoryContract residency : contract.getResidencies()) {
447                     residencyBuilders.add(EntityResidencyHistory.Builder.create(residency));
448                 }
449                 builder.setResidencies(residencyBuilders);
450             }
451             if (contract.getVisas() != null) {
452                 List<EntityVisaHistory.Builder> visaBuilders = new ArrayList<EntityVisaHistory.Builder>();
453                 for (EntityVisaHistoryContract visa : contract.getVisas()) {
454                     visaBuilders.add(EntityVisaHistory.Builder.create(visa));
455                 }
456                 builder.setVisas(visaBuilders);
457             }
458             builder.setVersionNumber(contract.getVersionNumber());
459             builder.setObjectId(contract.getObjectId());
460             builder.setActive(contract.isActive());
461             builder.setId(contract.getId());
462             return builder;
463         }
464 
465         public EntityHistory build() {
466             return new EntityHistory(this);
467         }
468 
469         @Override
470         public List<PrincipalHistory.Builder> getPrincipals() {
471             return this.principals;
472         }
473 
474         @Override
475         public List<EntityTypeContactInfoHistory.Builder> getEntityTypeContactInfos() {
476             return this.entityTypeContactInfos;
477         }
478 
479         @Override
480         public List<EntityExternalIdentifierHistory.Builder> getExternalIdentifiers() {
481             return this.externalIdentifiers;
482         }
483 
484         @Override
485         public List<EntityAffiliationHistory.Builder> getAffiliations() {
486             return this.affiliations;
487         }
488 
489         @Override
490         public List<EntityNameHistory.Builder> getNames() {
491             return this.names;
492         }
493 
494         @Override
495         public List<EntityEmploymentHistory.Builder> getEmploymentInformation() {
496             return this.employmentInformation;
497         }
498 
499         @Override
500         public EntityPrivacyHistory.Builder getPrivacyPreferences() {
501             return this.privacyPreferences;
502         }
503 
504         @Override
505         public EntityBioDemographicsHistory.Builder getBioDemographics() {
506             return this.bioDemographics;
507         }
508 
509         @Override
510         public List<EntityCitizenshipHistory.Builder> getCitizenships() {
511             return this.citizenships;
512         }
513 
514         @Override
515         public EntityTypeContactInfoHistory.Builder getEntityTypeContactInfoByTypeCode(String entityTypeCode) {
516             if (CollectionUtils.isEmpty(this.entityTypeContactInfos)) {
517                 return null;
518             }
519             for (EntityTypeContactInfoHistory.Builder builder : this.entityTypeContactInfos) {
520                 if (builder.getEntityTypeCode().equals(entityTypeCode) && builder.isActive()) {
521                     return builder;
522                 }
523             }
524             return null;
525         }
526 
527         @Override
528         public EntityEmploymentHistory.Builder getPrimaryEmployment() {
529             if (CollectionUtils.isEmpty(this.employmentInformation)) {
530                 return null;
531             }
532             for (EntityEmploymentHistory.Builder builder : this.employmentInformation) {
533                 if (builder.isPrimary()
534                         && builder.isActive()) {
535                     return builder;
536                 }
537             }
538             return null;
539         }
540 
541         @Override
542         public EntityAffiliationHistory.Builder getDefaultAffiliation() {
543             if (CollectionUtils.isEmpty(this.affiliations)) {
544                 return null;
545             }
546             for (EntityAffiliationHistory.Builder builder : this.affiliations) {
547                 if (builder.isDefaultValue()
548                         && builder.isActive()) {
549                     return builder;
550                 }
551             }
552             return null;
553         }
554 
555         @Override
556         public EntityExternalIdentifierHistory.Builder getEntityExternalIdentifier(String externalIdentifierTypeCode) {
557             if (CollectionUtils.isEmpty(this.externalIdentifiers)) {
558                 return null;
559             }
560             for (EntityExternalIdentifierHistory.Builder builder : this.externalIdentifiers) {
561                 if (builder.getExternalIdentifierTypeCode().equals(externalIdentifierTypeCode)) {
562                     return builder;
563                 }
564             }
565             return null;
566         }
567 
568         @Override
569         public EntityNameHistory.Builder getDefaultName() {
570             if (CollectionUtils.isEmpty(this.names)) {
571                 return null;
572             }
573             for (EntityNameHistory.Builder builder : this.names) {
574                 if (builder.isDefaultValue()
575                         && builder.isActive()) {
576                     return builder;
577                 }
578             }
579             return null;
580         }
581 
582         @Override
583         public List<EntityEthnicityHistory.Builder> getEthnicities() {
584             return this.ethnicities;
585         }
586 
587         @Override
588         public List<EntityResidencyHistory.Builder> getResidencies() {
589             return this.residencies;
590         }
591 
592         @Override
593         public List<EntityVisaHistory.Builder> getVisas() {
594             return this.visas;
595         }
596 
597         @Override
598         public Long getVersionNumber() {
599             return this.versionNumber;
600         }
601 
602         @Override
603         public String getObjectId() {
604             return this.objectId;
605         }
606 
607         @Override
608         public boolean isActive() {
609             return this.active;
610         }
611 
612         @Override
613         public String getId() {
614             return this.id;
615         }
616 
617         public void setPrincipals(List<PrincipalHistory.Builder> principals) {
618             this.principals = principals;
619         }
620 
621         public void setEntityTypes(List<EntityTypeContactInfoHistory.Builder> entityTypeContactInfos) {
622             this.entityTypeContactInfos = entityTypeContactInfos;
623         }
624 
625         public void setExternalIdentifiers(List<EntityExternalIdentifierHistory.Builder> externalIdentifiers) {
626             this.externalIdentifiers = externalIdentifiers;
627         }
628 
629         public void setAffiliations(List<EntityAffiliationHistory.Builder> affiliations) {
630             this.affiliations = affiliations;
631         }
632 
633         public void setNames(List<EntityNameHistory.Builder> names) {
634             this.names = names;
635         }
636 
637         public void setEmploymentInformation(List<EntityEmploymentHistory.Builder> employmentInformation) {
638             this.employmentInformation = employmentInformation;
639         }
640 
641         public void setPrivacyPreferences(EntityPrivacyHistory.Builder privacyPreferences) {
642             this.privacyPreferences = privacyPreferences;
643         }
644 
645         public void setBioDemographics(EntityBioDemographicsHistory.Builder bioDemographics) {
646             this.bioDemographics = bioDemographics;
647         }
648 
649         public void setCitizenships(List<EntityCitizenshipHistory.Builder> citizenships) {
650             this.citizenships = citizenships;
651         }
652 
653         public void setEthnicities(List<EntityEthnicityHistory.Builder> ethnicities) {
654             this.ethnicities = ethnicities;
655         }
656 
657         public void setResidencies(List<EntityResidencyHistory.Builder> residencies) {
658             this.residencies = residencies;
659         }
660 
661         public void setVisas(List<EntityVisaHistory.Builder> visas) {
662             this.visas = visas;
663         }
664 
665         public void setVersionNumber(Long versionNumber) {
666             this.versionNumber = versionNumber;
667         }
668 
669         public void setObjectId(String objectId) {
670             this.objectId = objectId;
671         }
672 
673         public void setActive(boolean active) {
674             this.active = active;
675         }
676 
677         public void setId(String id) {
678             if (StringUtils.isWhitespace(id)) {
679                 throw new IllegalArgumentException("id is blank");
680             }
681             this.id = id;
682         }
683 
684     }
685 
686 
687     /**
688      * Defines some internal constants used on this class.
689      *
690      */
691     static class Constants {
692 
693         final static String ROOT_ELEMENT_NAME = "entity";
694         final static String TYPE_NAME = "EntityType";
695         final static String[] HASH_CODE_EQUALS_EXCLUDE = new String[] {CoreConstants.CommonElements.FUTURE_ELEMENTS };
696 
697     }
698 
699 
700     /**
701      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
702      *
703      */
704     static class Elements {
705 
706         final static String PRINCIPALS = "principals";
707         final static String PRINCIPAL = "principal";
708         final static String ENTITY_TYPE_CONTACT_INFOS = "entityTypeContactInfos";
709         final static String ENTITY_TYPE_CONTACT_INFO = "entityTypeContactInfo";
710         final static String EXTERNAL_IDENTIFIERS = "externalIdentifiers";
711         final static String EXTERNAL_IDENTIFIER = "externalIdentifier";
712         final static String AFFILIATIONS = "affiliations";
713         final static String AFFILIATION = "affiliation";
714         final static String NAMES = "names";
715         final static String NAME = "name";
716         final static String EMPLOYMENT_INFORMATION = "employmentInformation";
717         final static String EMPLOYMENT = "employment";
718         final static String PRIVACY_PREFERENCES = "privacyPreferences";
719         final static String BIO_DEMOGRAPHICS = "bioDemographics";
720         final static String CITIZENSHIPS = "citizenships";
721         final static String CITIZENSHIP = "citizenship";
722         final static String PRIMARY_EMPLOYMENT = "primaryEmployment";
723         final static String DEFAULT_AFFILIATION = "defaultAffiliation";
724         final static String DEFAULT_NAME = "defaultName";
725         final static String ETHNICITIES = "ethnicities";
726         final static String ETHNICITY = "ethnicity";
727         final static String RESIDENCIES = "residencies";
728         final static String RESIDENCY = "residency";
729         final static String VISAS = "visas";
730         final static String VISA = "visa";
731         final static String ACTIVE = "active";
732         final static String ID = "id";
733 
734     }
735 
736     public static class Cache {
737         public static final String NAME = KimConstants.Namespaces.KIM_NAMESPACE_2_0 + "/" + EntityHistory.Constants.TYPE_NAME;
738     }
739 }