1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.bo.entity.dto;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.kuali.rice.kim.bo.entity.KimEntity;
22 import org.kuali.rice.kim.bo.entity.KimEntityAffiliation;
23 import org.kuali.rice.kim.bo.entity.KimEntityCitizenship;
24 import org.kuali.rice.kim.bo.entity.KimEntityEmploymentInformation;
25 import org.kuali.rice.kim.bo.entity.KimEntityEntityType;
26 import org.kuali.rice.kim.bo.entity.KimEntityEthnicity;
27 import org.kuali.rice.kim.bo.entity.KimEntityExternalIdentifier;
28 import org.kuali.rice.kim.bo.entity.KimEntityName;
29 import org.kuali.rice.kim.bo.entity.KimEntityResidency;
30 import org.kuali.rice.kim.bo.entity.KimEntityVisa;
31 import org.kuali.rice.kim.bo.entity.KimPrincipal;
32
33
34
35
36
37
38
39 public class KimEntityInfo extends KimInactivatableInfo implements KimEntity {
40
41 private static final long serialVersionUID = 1L;
42
43 private List<KimEntityAffiliationInfo> affiliations;
44 private KimEntityBioDemographicsInfo bioDemographics;
45 private List<KimEntityCitizenshipInfo> citizenships;
46 private List<KimEntityEmploymentInformationInfo> employmentInformation;
47 private String entityId;
48 private List<KimEntityEntityTypeInfo> entityTypes;
49 private List<KimEntityExternalIdentifierInfo> externalIdentifiers;
50 private List<KimEntityNameInfo> names;
51 private List<KimPrincipalInfo> principals;
52 private KimEntityPrivacyPreferencesInfo privacyPreferences;
53 private List<KimEntityEthnicityInfo> ethnicities;
54 private List<KimEntityResidencyInfo> residencies;
55 private List<KimEntityVisaInfo> visas;
56
57
58
59
60 public KimEntityInfo() {
61 super();
62 active = true;
63 }
64
65
66
67
68
69
70
71 public KimEntityInfo(KimEntity entity) {
72 this();
73
74 if (entity != null) {
75
76 entityId = entity.getEntityId();
77 active = entity.isActive();
78
79
80
81
82 principals = deriveCollection(entity.getPrincipals(), new XForm<KimPrincipal, KimPrincipalInfo>() {
83 public KimPrincipalInfo xform(KimPrincipal source) {
84 return new KimPrincipalInfo(source);
85 }
86 });
87
88 if (entity.getBioDemographics() != null) {
89 bioDemographics = new KimEntityBioDemographicsInfo(entity.getBioDemographics());
90 }
91
92 if (entity.getPrivacyPreferences() != null) {
93 privacyPreferences = new KimEntityPrivacyPreferencesInfo(entity.getPrivacyPreferences());
94 }
95
96 names = deriveCollection(entity.getNames(), new XForm<KimEntityName, KimEntityNameInfo>() {
97 public KimEntityNameInfo xform(KimEntityName source) {
98 return new KimEntityNameInfo(source);
99 }
100 });
101
102 entityTypes = deriveCollection(entity.getEntityTypes(), new XForm<KimEntityEntityType, KimEntityEntityTypeInfo>() {
103 public KimEntityEntityTypeInfo xform(KimEntityEntityType source) {
104 return new KimEntityEntityTypeInfo(source);
105 }
106 });
107
108 affiliations = deriveCollection(entity.getAffiliations(), new XForm<KimEntityAffiliation, KimEntityAffiliationInfo>() {
109 public KimEntityAffiliationInfo xform(KimEntityAffiliation source) {
110 return new KimEntityAffiliationInfo(source);
111 }
112 });
113
114 employmentInformation = deriveCollection(entity.getEmploymentInformation(),
115 new XForm<KimEntityEmploymentInformation, KimEntityEmploymentInformationInfo>() {
116 public KimEntityEmploymentInformationInfo xform(KimEntityEmploymentInformation source) {
117 return new KimEntityEmploymentInformationInfo(source);
118 }
119 });
120
121 externalIdentifiers = deriveCollection(entity.getExternalIdentifiers(),
122 new XForm<KimEntityExternalIdentifier, KimEntityExternalIdentifierInfo>() {
123 public KimEntityExternalIdentifierInfo xform(KimEntityExternalIdentifier source) {
124 return new KimEntityExternalIdentifierInfo(source);
125 }
126 });
127
128 citizenships = deriveCollection(entity.getCitizenships(), new XForm<KimEntityCitizenship, KimEntityCitizenshipInfo>() {
129 public KimEntityCitizenshipInfo xform(KimEntityCitizenship source) {
130 return new KimEntityCitizenshipInfo(source);
131 }
132 });
133
134 ethnicities = deriveCollection(entity.getEthnicities(), new XForm<KimEntityEthnicity, KimEntityEthnicityInfo>() {
135 public KimEntityEthnicityInfo xform(KimEntityEthnicity source) {
136 return new KimEntityEthnicityInfo(source);
137 }
138 });
139
140 residencies = deriveCollection(entity.getResidencies(), new XForm<KimEntityResidency, KimEntityResidencyInfo>() {
141 public KimEntityResidencyInfo xform(KimEntityResidency source) {
142 return new KimEntityResidencyInfo(source);
143 }
144 });
145
146 visas = deriveCollection(entity.getVisas(), new XForm<KimEntityVisa, KimEntityVisaInfo>() {
147 public KimEntityVisaInfo xform(KimEntityVisa source) {
148 return new KimEntityVisaInfo(source);
149 }
150 });
151 }
152 }
153
154
155
156
157
158 public List<KimEntityAffiliationInfo> getAffiliations() {
159
160 return (affiliations != null) ? affiliations : (affiliations = new ArrayList<KimEntityAffiliationInfo>());
161
162 }
163
164
165
166
167
168 public void setAffiliations(List<KimEntityAffiliationInfo> affiliations) {
169 this.affiliations = affiliations;
170 }
171
172
173
174
175
176 public KimEntityAffiliationInfo getDefaultAffiliation() {
177 KimEntityAffiliationInfo result = null;
178 if (affiliations != null)
179 for (KimEntityAffiliationInfo affiliation : affiliations) {
180 if (result == null) {
181 result = affiliation;
182 }
183 if (affiliation.isDefault()) {
184 result = affiliation;
185 break;
186 }
187 }
188 return result;
189 }
190
191
192
193
194
195 public KimEntityBioDemographicsInfo getBioDemographics() {
196 return bioDemographics;
197 }
198
199
200
201
202
203 public void setBioDemographics(KimEntityBioDemographicsInfo bioDemographics) {
204 this.bioDemographics = bioDemographics;
205 }
206
207
208
209
210
211 public List<KimEntityCitizenshipInfo> getCitizenships() {
212
213 return (citizenships != null) ? citizenships : (citizenships = new ArrayList<KimEntityCitizenshipInfo>());
214
215 }
216
217
218
219
220
221 public void setCitizenships(List<KimEntityCitizenshipInfo> citizenships) {
222 this.citizenships = citizenships;
223 }
224
225
226
227
228
229 public List<KimEntityEmploymentInformationInfo> getEmploymentInformation() {
230
231 return (employmentInformation != null) ? employmentInformation
232 : (employmentInformation = new ArrayList<KimEntityEmploymentInformationInfo>());
233 }
234
235
236
237
238
239 public void setEmploymentInformation(List<KimEntityEmploymentInformationInfo> employmentInformation) {
240 this.employmentInformation = employmentInformation;
241 }
242
243
244
245
246
247 public KimEntityEmploymentInformationInfo getPrimaryEmployment() {
248 KimEntityEmploymentInformationInfo result = null;
249 if (employmentInformation != null)
250 for (KimEntityEmploymentInformationInfo employment : employmentInformation) {
251 if (employment.isPrimary()) {
252 result = employment;
253 }
254 }
255 return result;
256 }
257
258
259
260
261
262 public String getEntityId() {
263 return entityId;
264 }
265
266
267
268
269
270 public void setEntityId(String entityId) {
271 this.entityId = entityId;
272 }
273
274
275
276
277
278 public List<KimEntityEntityTypeInfo> getEntityTypes() {
279
280 return (entityTypes != null) ? entityTypes : (entityTypes = new ArrayList<KimEntityEntityTypeInfo>());
281 }
282
283
284
285
286
287 public void setEntityTypes(List<KimEntityEntityTypeInfo> entityTypes) {
288 this.entityTypes = entityTypes;
289 }
290
291
292
293
294
295 public List<KimEntityExternalIdentifierInfo> getExternalIdentifiers() {
296
297 return (externalIdentifiers != null) ? externalIdentifiers
298 : (externalIdentifiers = new ArrayList<KimEntityExternalIdentifierInfo>());
299 }
300
301
302
303
304
305 public void setExternalIdentifiers(List<KimEntityExternalIdentifierInfo> externalIdentifiers) {
306 this.externalIdentifiers = externalIdentifiers;
307 }
308
309
310
311
312
313 public List<KimEntityNameInfo> getNames() {
314
315 return (names != null) ? names : (names = new ArrayList<KimEntityNameInfo>());
316 }
317
318
319
320
321
322 public void setNames(List<KimEntityNameInfo> names) {
323 this.names = names;
324 }
325
326
327
328
329
330 public KimEntityNameInfo getDefaultName() {
331 KimEntityNameInfo result = null;
332 for (KimEntityNameInfo name : this.getNames()) {
333 if (result == null) {
334 result = name;
335 }
336 if (name.isDefault()) {
337 result = name;
338 break;
339 }
340 }
341 return result;
342 }
343
344
345
346
347
348 public List<KimPrincipalInfo> getPrincipals() {
349
350 return (principals != null) ? principals : (principals = new ArrayList<KimPrincipalInfo>());
351 }
352
353
354
355
356
357 public void setPrincipals(List<KimPrincipalInfo> principals) {
358 this.principals = principals;
359 }
360
361
362
363
364
365 public KimEntityPrivacyPreferencesInfo getPrivacyPreferences() {
366 return privacyPreferences;
367 }
368
369
370
371
372
373 public void setPrivacyPreferences(KimEntityPrivacyPreferencesInfo privacyPreferences) {
374 this.privacyPreferences = privacyPreferences;
375 }
376
377
378
379
380
381 public List<KimEntityEthnicityInfo> getEthnicities() {
382
383 return (ethnicities != null) ? ethnicities : (ethnicities = new ArrayList<KimEntityEthnicityInfo>());
384 }
385
386
387
388
389
390 public void setEthnicities(List<KimEntityEthnicityInfo> ethnicities) {
391 this.ethnicities = ethnicities;
392 }
393
394
395
396
397
398 public List<KimEntityResidencyInfo> getResidencies() {
399
400 return (residencies != null) ? residencies : (residencies = new ArrayList<KimEntityResidencyInfo>());
401 }
402
403
404
405
406
407 public void setResidencies(List<KimEntityResidencyInfo> residencies) {
408 this.residencies = residencies;
409 }
410
411
412
413
414
415 public List<KimEntityVisaInfo> getVisas() {
416
417 return (visas != null) ? visas : (visas = new ArrayList<KimEntityVisaInfo>());
418 }
419
420
421
422
423
424 public void setVisas(List<KimEntityVisaInfo> visas) {
425 this.visas = visas;
426 }
427
428
429
430
431
432 public KimEntityExternalIdentifier getEntityExternalIdentifier(String externalIdentifierTypeCode) {
433 KimEntityExternalIdentifier result = null;
434
435 List<KimEntityExternalIdentifierInfo> externalIdentifiers = getExternalIdentifiers();
436 if (externalIdentifiers != null)
437 for (KimEntityExternalIdentifier eid : externalIdentifiers) {
438 if (eid.getExternalIdentifierTypeCode().equals(externalIdentifierTypeCode)) {
439 result = eid;
440 }
441 }
442 return result;
443 }
444
445
446
447
448
449 public KimEntityEntityType getEntityType(String entityTypeCode) {
450 KimEntityEntityType result = null;
451
452 if (entityTypes != null)
453 for (KimEntityEntityType eType : entityTypes) {
454 if (eType.getEntityTypeCode().equals(entityTypeCode)) {
455 result = eType;
456 }
457 }
458 return result;
459 }
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484 private static <A,B,C> List<B> deriveCollection(List<A> source, XForm<C,B> transformer) {
485 List<B> result = null;
486 if (source != null) {
487 result = new ArrayList<B>(source.size());
488
489 for (A element : source) if (element != null) {
490 B mutant = transformer.xform((C)element);
491 if (mutant != null) {
492 result.add(mutant);
493 }
494 }
495 } else {
496 result = new ArrayList();
497 }
498 return result;
499 }
500
501 private static interface XForm<A,B> {
502 public B xform(A source);
503 }
504
505 }