1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kim.impl.identity.entity;
18
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import javax.persistence.Cacheable;
23 import javax.persistence.CascadeType;
24 import javax.persistence.Column;
25 import javax.persistence.Convert;
26 import javax.persistence.GeneratedValue;
27 import javax.persistence.Id;
28 import javax.persistence.JoinColumn;
29 import javax.persistence.OneToMany;
30 import javax.persistence.OneToOne;
31 import javax.persistence.PrimaryKeyJoinColumn;
32 import javax.persistence.Table;
33
34 import org.apache.commons.collections.CollectionUtils;
35 import org.kuali.rice.kim.api.identity.EntityUtils;
36 import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliation;
37 import org.kuali.rice.kim.api.identity.citizenship.EntityCitizenship;
38 import org.kuali.rice.kim.api.identity.employment.EntityEmployment;
39 import org.kuali.rice.kim.api.identity.entity.Entity;
40 import org.kuali.rice.kim.api.identity.entity.EntityContract;
41 import org.kuali.rice.kim.api.identity.entity.EntityDefault;
42 import org.kuali.rice.kim.api.identity.external.EntityExternalIdentifier;
43 import org.kuali.rice.kim.api.identity.name.EntityName;
44 import org.kuali.rice.kim.api.identity.name.EntityNameContract;
45 import org.kuali.rice.kim.api.identity.personal.EntityEthnicity;
46 import org.kuali.rice.kim.api.identity.principal.Principal;
47 import org.kuali.rice.kim.api.identity.residency.EntityResidency;
48 import org.kuali.rice.kim.api.identity.type.EntityTypeContactInfo;
49 import org.kuali.rice.kim.api.identity.visa.EntityVisa;
50 import org.kuali.rice.kim.impl.identity.affiliation.EntityAffiliationBo;
51 import org.kuali.rice.kim.impl.identity.citizenship.EntityCitizenshipBo;
52 import org.kuali.rice.kim.impl.identity.employment.EntityEmploymentBo;
53 import org.kuali.rice.kim.impl.identity.external.EntityExternalIdentifierBo;
54 import org.kuali.rice.kim.impl.identity.name.EntityNameBo;
55 import org.kuali.rice.kim.impl.identity.personal.EntityBioDemographicsBo;
56 import org.kuali.rice.kim.impl.identity.personal.EntityEthnicityBo;
57 import org.kuali.rice.kim.impl.identity.principal.PrincipalBo;
58 import org.kuali.rice.kim.impl.identity.privacy.EntityPrivacyPreferencesBo;
59 import org.kuali.rice.kim.impl.identity.residency.EntityResidencyBo;
60 import org.kuali.rice.kim.impl.identity.type.EntityTypeContactInfoBo;
61 import org.kuali.rice.kim.impl.identity.visa.EntityVisaBo;
62 import org.kuali.rice.krad.bo.DataObjectBase;
63 import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
64 import org.kuali.rice.krad.data.jpa.converters.BooleanYNConverter;
65
66 @javax.persistence.Entity
67 @Cacheable(false)
68 @Table(name = "KRIM_ENTITY_T")
69 public class EntityBo extends DataObjectBase implements EntityContract {
70
71 private static final long serialVersionUID = -2448541334029932773L;
72
73 @PortableSequenceGenerator(name = "KRIM_ENTITY_ID_S")
74 @GeneratedValue(generator = "KRIM_ENTITY_ID_S")
75 @Id
76 @Column(name = "ENTITY_ID")
77 private String id;
78
79 @OneToMany(targetEntity = EntityNameBo.class, orphanRemoval = true, cascade = CascadeType.ALL)
80 @JoinColumn(name = "ENTITY_ID", referencedColumnName = "ENTITY_ID", insertable = false, updatable = false)
81 private List<EntityNameBo> names = new ArrayList<EntityNameBo>();
82
83 @OneToMany(targetEntity = PrincipalBo.class, orphanRemoval = true, cascade = CascadeType.ALL)
84 @JoinColumn(name = "ENTITY_ID", referencedColumnName = "ENTITY_ID", insertable = false, updatable = false)
85 private List<PrincipalBo> principals = new ArrayList<PrincipalBo>();
86
87 @OneToMany(targetEntity = EntityExternalIdentifierBo.class, orphanRemoval = true, cascade = CascadeType.ALL)
88 @JoinColumn(name = "ENTITY_ID", referencedColumnName = "ENTITY_ID", insertable = false, updatable = false)
89 private List<EntityExternalIdentifierBo> externalIdentifiers = new ArrayList<EntityExternalIdentifierBo>();
90
91 @OneToMany(targetEntity = EntityAffiliationBo.class, orphanRemoval = true, cascade = CascadeType.ALL)
92 @JoinColumn(name = "ENTITY_ID", referencedColumnName = "ENTITY_ID", insertable = false, updatable = false)
93 private List<EntityAffiliationBo> affiliations = new ArrayList<EntityAffiliationBo>();
94
95 @OneToMany(targetEntity = EntityEmploymentBo.class, orphanRemoval = true, cascade = CascadeType.ALL)
96 @JoinColumn(name = "ENTITY_ID", referencedColumnName = "ENTITY_ID", insertable = false, updatable = false)
97 private List<EntityEmploymentBo> employmentInformation = new ArrayList<EntityEmploymentBo>();
98
99 @OneToMany(targetEntity = EntityTypeContactInfoBo.class, orphanRemoval = true, cascade = CascadeType.ALL)
100 @JoinColumn(name = "ENTITY_ID", referencedColumnName = "ENTITY_ID", insertable = false, updatable = false)
101 private List<EntityTypeContactInfoBo> entityTypeContactInfos = new ArrayList<EntityTypeContactInfoBo>();
102
103 @OneToOne(targetEntity = EntityPrivacyPreferencesBo.class, orphanRemoval = true, cascade = CascadeType.ALL)
104 @PrimaryKeyJoinColumn(name = "ENTITY_ID", referencedColumnName = "ENTITY_ID")
105 private EntityPrivacyPreferencesBo privacyPreferences;
106
107 @OneToOne(targetEntity = EntityBioDemographicsBo.class, orphanRemoval = true, cascade = CascadeType.ALL)
108 @PrimaryKeyJoinColumn(name = "ENTITY_ID", referencedColumnName = "ENTITY_ID")
109 private EntityBioDemographicsBo bioDemographics;
110
111 @OneToMany(targetEntity = EntityCitizenshipBo.class, orphanRemoval = true, cascade = CascadeType.ALL)
112 @JoinColumn(name = "ENTITY_ID", referencedColumnName = "ENTITY_ID", insertable = false, updatable = false)
113 private List<EntityCitizenshipBo> citizenships = new ArrayList<EntityCitizenshipBo>();
114
115 @OneToMany(targetEntity = EntityEthnicityBo.class, orphanRemoval = true, cascade = CascadeType.ALL)
116 @JoinColumn(name = "ENTITY_ID", referencedColumnName = "ENTITY_ID", insertable = false, updatable = false)
117 private List<EntityEthnicityBo> ethnicities = new ArrayList<EntityEthnicityBo>();
118
119 @OneToMany(targetEntity = EntityResidencyBo.class, orphanRemoval = true, cascade = CascadeType.ALL)
120 @JoinColumn(name = "ENTITY_ID", referencedColumnName = "ENTITY_ID", insertable = false, updatable = false)
121 private List<EntityResidencyBo> residencies = new ArrayList<EntityResidencyBo>();
122
123 @OneToMany(targetEntity = EntityVisaBo.class, orphanRemoval = true, cascade = CascadeType.ALL)
124 @JoinColumn(name = "ENTITY_ID", referencedColumnName = "ENTITY_ID", insertable = false, updatable = false)
125 private List<EntityVisaBo> visas = new ArrayList<EntityVisaBo>();
126
127 @Column(name = "ACTV_IND")
128 @Convert(converter = BooleanYNConverter.class)
129 private boolean active;
130
131 public static org.kuali.rice.kim.api.identity.entity.Entity to(EntityBo bo) {
132 if (bo == null) {
133 return null;
134 }
135 return Entity.Builder.create(bo).build();
136 }
137
138 public static EntityDefault toDefault(EntityBo bo) {
139 if (bo == null) {
140 return null;
141 }
142 return EntityDefault.Builder.create(bo).build();
143 }
144
145 public static EntityBo from(org.kuali.rice.kim.api.identity.entity.Entity immutable) {
146 return fromAndUpdate(immutable, null);
147 }
148
149
150
151
152
153
154
155 public static EntityBo fromAndUpdate(Entity immutable, EntityBo toUpdate) {
156 if (immutable == null) {
157 return null;
158 }
159 EntityBo bo = toUpdate;
160 if (toUpdate == null) {
161 bo = new EntityBo();
162 }
163 bo.active = immutable.isActive();
164 bo.id = immutable.getId();
165 bo.names = new ArrayList<EntityNameBo>();
166 if (CollectionUtils.isNotEmpty(immutable.getNames())) {
167 for (EntityName name : immutable.getNames()) {
168 bo.names.add(EntityNameBo.from(name));
169 }
170 }
171 bo.principals = new ArrayList<PrincipalBo>();
172 if (CollectionUtils.isNotEmpty(immutable.getPrincipals())) {
173 for (Principal principal : immutable.getPrincipals()) {
174 bo.principals.add(PrincipalBo.from(principal));
175 }
176 }
177 bo.externalIdentifiers = new ArrayList<EntityExternalIdentifierBo>();
178 if (CollectionUtils.isNotEmpty(immutable.getExternalIdentifiers())) {
179 for (EntityExternalIdentifier externalId : immutable.getExternalIdentifiers()) {
180 bo.externalIdentifiers.add(EntityExternalIdentifierBo.from(externalId));
181 }
182 }
183 bo.affiliations = new ArrayList<EntityAffiliationBo>();
184 if (CollectionUtils.isNotEmpty(immutable.getAffiliations())) {
185 for (EntityAffiliation affiliation : immutable.getAffiliations()) {
186 bo.affiliations.add(EntityAffiliationBo.from(affiliation));
187 }
188 }
189 bo.employmentInformation = new ArrayList<EntityEmploymentBo>();
190 if (CollectionUtils.isNotEmpty(immutable.getEmploymentInformation())) {
191 for (EntityEmployment employment : immutable.getEmploymentInformation()) {
192 bo.employmentInformation.add(EntityEmploymentBo.from(employment));
193 }
194 }
195 bo.entityTypeContactInfos = new ArrayList<EntityTypeContactInfoBo>();
196 if (CollectionUtils.isNotEmpty(immutable.getEntityTypeContactInfos())) {
197 for (EntityTypeContactInfo entityType : immutable.getEntityTypeContactInfos()) {
198 bo.entityTypeContactInfos.add(EntityTypeContactInfoBo.from(entityType));
199 }
200 }
201 if (immutable.getPrivacyPreferences() != null) {
202 bo.privacyPreferences = EntityPrivacyPreferencesBo.from(immutable.getPrivacyPreferences());
203 }
204 if (immutable.getBioDemographics() != null) {
205 bo.bioDemographics = EntityBioDemographicsBo.from(immutable.getBioDemographics());
206 }
207 bo.citizenships = new ArrayList<EntityCitizenshipBo>();
208 if (CollectionUtils.isNotEmpty(immutable.getCitizenships())) {
209 for (EntityCitizenship citizenship : immutable.getCitizenships()) {
210 bo.citizenships.add(EntityCitizenshipBo.from(citizenship));
211 }
212 }
213 bo.ethnicities = new ArrayList<EntityEthnicityBo>();
214 if (CollectionUtils.isNotEmpty(immutable.getEthnicities())) {
215 for (EntityEthnicity ethnicity : immutable.getEthnicities()) {
216 bo.ethnicities.add(EntityEthnicityBo.from(ethnicity));
217 }
218 }
219 bo.residencies = new ArrayList<EntityResidencyBo>();
220 if (CollectionUtils.isNotEmpty(immutable.getResidencies())) {
221 for (EntityResidency residency : immutable.getResidencies()) {
222 bo.residencies.add(EntityResidencyBo.from(residency));
223 }
224 }
225 bo.visas = new ArrayList<EntityVisaBo>();
226 if (CollectionUtils.isNotEmpty(immutable.getVisas())) {
227 for (EntityVisa visa : immutable.getVisas()) {
228 bo.visas.add(EntityVisaBo.from(visa));
229 }
230 }
231 bo.setVersionNumber(immutable.getVersionNumber());
232 bo.setObjectId(immutable.getObjectId());
233 return bo;
234 }
235
236 @Override
237 public EntityTypeContactInfoBo getEntityTypeContactInfoByTypeCode(String entityTypeCode) {
238 if (CollectionUtils.isEmpty(this.entityTypeContactInfos)) {
239 return null;
240 }
241 for (EntityTypeContactInfoBo entType : this.entityTypeContactInfos) {
242 if (entType.getEntityTypeCode().equals(entityTypeCode)) {
243 return entType;
244 }
245 }
246 return null;
247 }
248
249 @Override
250 public EntityEmploymentBo getPrimaryEmployment() {
251 if (CollectionUtils.isEmpty(this.employmentInformation)) {
252 return null;
253 }
254 for (EntityEmploymentBo employment : this.employmentInformation) {
255 if (employment.isPrimary() && employment.isActive()) {
256 return employment;
257 }
258 }
259 return null;
260 }
261
262 @Override
263 public EntityAffiliationBo getDefaultAffiliation() {
264 return EntityUtils.getDefaultItem(this.affiliations);
265 }
266
267 @Override
268 public EntityExternalIdentifierBo getEntityExternalIdentifier(String externalIdentifierTypeCode) {
269 if (CollectionUtils.isEmpty(this.externalIdentifiers)) {
270 return null;
271 }
272 for (EntityExternalIdentifierBo externalId : this.externalIdentifiers) {
273 if (externalId.getExternalIdentifierTypeCode().equals(externalIdentifierTypeCode)) {
274 return externalId;
275 }
276 }
277 return null;
278 }
279
280 @Override
281 public EntityNameContract getDefaultName() {
282 return EntityUtils.getDefaultItem(this.names);
283 }
284
285 @Override
286 public EntityPrivacyPreferencesBo getPrivacyPreferences() {
287 return this.privacyPreferences;
288 }
289
290 @Override
291 public EntityBioDemographicsBo getBioDemographics() {
292 return this.bioDemographics;
293 }
294
295 @Override
296 public String getId() {
297 return id;
298 }
299
300 public void setId(String id) {
301 this.id = id;
302 }
303
304 @Override
305 public List<EntityNameBo> getNames() {
306 return names;
307 }
308
309 public void setNames(List<EntityNameBo> names) {
310 this.names = names;
311 }
312
313 @Override
314 public List<PrincipalBo> getPrincipals() {
315 return principals;
316 }
317
318 public void setPrincipals(List<PrincipalBo> principals) {
319 this.principals = principals;
320 }
321
322 @Override
323 public List<EntityExternalIdentifierBo> getExternalIdentifiers() {
324 return externalIdentifiers;
325 }
326
327 public void setExternalIdentifiers(List<EntityExternalIdentifierBo> externalIdentifiers) {
328 this.externalIdentifiers = externalIdentifiers;
329 }
330
331 @Override
332 public List<EntityAffiliationBo> getAffiliations() {
333 return affiliations;
334 }
335
336 public void setAffiliations(List<EntityAffiliationBo> affiliations) {
337 this.affiliations = affiliations;
338 }
339
340 @Override
341 public List<EntityEmploymentBo> getEmploymentInformation() {
342 return employmentInformation;
343 }
344
345 public void setEmploymentInformation(List<EntityEmploymentBo> employmentInformation) {
346 this.employmentInformation = employmentInformation;
347 }
348
349 @Override
350 public List<EntityTypeContactInfoBo> getEntityTypeContactInfos() {
351 return entityTypeContactInfos;
352 }
353
354 public void setEntityTypeContactInfos(List<EntityTypeContactInfoBo> entityTypeContactInfos) {
355 this.entityTypeContactInfos = entityTypeContactInfos;
356 }
357
358 public void setPrivacyPreferences(EntityPrivacyPreferencesBo privacyPreferences) {
359 this.privacyPreferences = privacyPreferences;
360 }
361
362 public void setBioDemographics(EntityBioDemographicsBo bioDemographics) {
363 this.bioDemographics = bioDemographics;
364 }
365
366 @Override
367 public List<EntityCitizenshipBo> getCitizenships() {
368 return citizenships;
369 }
370
371 public void setCitizenships(List<EntityCitizenshipBo> citizenships) {
372 this.citizenships = citizenships;
373 }
374
375 @Override
376 public List<EntityEthnicityBo> getEthnicities() {
377 return ethnicities;
378 }
379
380 public void setEthnicities(List<EntityEthnicityBo> ethnicities) {
381 this.ethnicities = ethnicities;
382 }
383
384 @Override
385 public List<EntityResidencyBo> getResidencies() {
386 return residencies;
387 }
388
389 public void setResidencies(List<EntityResidencyBo> residencies) {
390 this.residencies = residencies;
391 }
392
393 @Override
394 public List<EntityVisaBo> getVisas() {
395 return visas;
396 }
397
398 public void setVisas(List<EntityVisaBo> visas) {
399 this.visas = visas;
400 }
401
402 public boolean getActive() {
403 return active;
404 }
405
406 @Override
407 public boolean isActive() {
408 return active;
409 }
410
411 public void setActive(boolean active) {
412 this.active = active;
413 }
414 }