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