1 | |
package org.kuali.rice.kim.impl.identity.type |
2 | |
|
3 | |
import javax.persistence.CascadeType |
4 | |
import javax.persistence.Column |
5 | |
import javax.persistence.Entity |
6 | |
import javax.persistence.FetchType |
7 | |
import javax.persistence.Id |
8 | |
import javax.persistence.IdClass |
9 | |
import javax.persistence.JoinColumn |
10 | |
import javax.persistence.JoinColumns |
11 | |
import javax.persistence.ManyToOne |
12 | |
import javax.persistence.OneToMany |
13 | |
import javax.persistence.Table |
14 | |
import org.apache.commons.collections.CollectionUtils |
15 | |
import org.hibernate.annotations.Type |
16 | |
import org.kuali.rice.kim.api.identity.EntityUtils |
17 | |
import org.kuali.rice.kim.api.identity.address.EntityAddress |
18 | |
import org.kuali.rice.kim.api.identity.email.EntityEmail |
19 | |
import org.kuali.rice.kim.api.identity.phone.EntityPhone |
20 | |
import org.kuali.rice.kim.api.identity.type.EntityTypeData |
21 | |
import org.kuali.rice.kim.api.identity.type.EntityTypeDataContract |
22 | |
import org.kuali.rice.kim.impl.identity.EntityTypeBo |
23 | |
import org.kuali.rice.kim.impl.identity.address.EntityAddressBo |
24 | |
import org.kuali.rice.kim.impl.identity.email.EntityEmailBo |
25 | |
import org.kuali.rice.kim.impl.identity.phone.EntityPhoneBo |
26 | |
import org.kuali.rice.krad.bo.PersistableBusinessObjectBase |
27 | |
import org.kuali.rice.kim.api.identity.type.EntityTypeDataDefault |
28 | |
|
29 | |
@Entity |
30 | |
@IdClass(EntityTypeDataId.class) |
31 | |
@Table(name = "KRIM_ENTITY_ENT_TYP_T") |
32 | |
public class EntityTypeDataBo extends PersistableBusinessObjectBase implements EntityTypeDataContract { |
33 | |
|
34 | |
private static final long serialVersionUID = 1L; |
35 | |
|
36 | |
@Id |
37 | |
@Column(name = "ENTITY_ID") |
38 | |
String entityId; |
39 | |
|
40 | |
@Id |
41 | |
@Column(name = "ENT_TYP_CD") |
42 | |
String entityTypeCode; |
43 | |
|
44 | |
@ManyToOne(targetEntity = EntityTypeBo.class, fetch = FetchType.EAGER, cascade = []) |
45 | |
@JoinColumn(name = "ENT_TYP_CD", insertable = false, updatable = false) |
46 | |
EntityTypeBo entityType; |
47 | |
|
48 | |
@OneToMany(targetEntity = EntityTypeDataBo.class, fetch = FetchType.EAGER, cascade = [ CascadeType.ALL ]) |
49 | |
@JoinColumns([ |
50 | |
@JoinColumn(name="ENTITY_ID", insertable = false, updatable = false), |
51 | |
@JoinColumn(name="ENT_TYP_CD", insertable = false, updatable = false) |
52 | |
]) |
53 | |
List<EntityEmailBo> emailAddresses; |
54 | |
|
55 | |
@OneToMany(targetEntity = EntityPhoneBo.class, fetch = FetchType.EAGER, cascade = [ CascadeType.ALL ]) |
56 | |
@JoinColumns([ |
57 | |
@JoinColumn(name="ENTITY_ID", insertable = false, updatable = false), |
58 | |
@JoinColumn(name="ENT_TYP_CD", insertable = false, updatable = false) |
59 | |
]) |
60 | |
List<EntityPhoneBo> phoneNumbers |
61 | |
|
62 | |
@OneToMany(targetEntity = EntityAddressBo.class, fetch = FetchType.EAGER, cascade = [ CascadeType.ALL ]) |
63 | |
@JoinColumns([ |
64 | |
@JoinColumn(name="ENTITY_ID", insertable = false, updatable = false), |
65 | |
@JoinColumn(name="ENT_TYP_CD", insertable = false, updatable = false) |
66 | |
]) |
67 | |
List<EntityAddressBo> addresses; |
68 | |
|
69 | |
@Type(type="yes_no") |
70 | |
@Column(name="ACTV_IND") |
71 | |
boolean active; |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
static EntityTypeData to(EntityTypeDataBo bo) { |
79 | 1 | if (bo == null) { return null } |
80 | 1 | return EntityTypeData.Builder.create(bo).build() |
81 | |
} |
82 | |
|
83 | |
static EntityTypeDataDefault toDefault(EntityTypeDataBo bo) { |
84 | 0 | if (bo == null) { return null } |
85 | 0 | return new EntityTypeDataDefault(bo.getEntityTypeCode(), |
86 | 0 | EntityAddressBo.to(bo.getDefaultAddress()), |
87 | 0 | EntityTypeDataBo.to(bo.getDefaultEmailAddress()), |
88 | 0 | EntityPhoneBo.to(bo.getDefaultPhoneNumber())) |
89 | |
} |
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
static EntityTypeDataBo from(EntityTypeData immutable) { |
97 | 1 | if (immutable == null) {return null} |
98 | |
|
99 | 1 | EntityTypeDataBo bo = new EntityTypeDataBo() |
100 | 1 | bo.active = immutable.active |
101 | |
|
102 | 1 | bo.entityId = immutable.entityId |
103 | 1 | bo.entityTypeCode = immutable.entityTypeCode |
104 | 1 | bo.addresses = new ArrayList<EntityAddressBo>() |
105 | 1 | if (CollectionUtils.isNotEmpty(immutable.addresses)) { |
106 | 0 | for (EntityAddress address : immutable.addresses) { |
107 | 0 | bo.addresses.add(EntityAddressBo.from(address)) |
108 | |
} |
109 | |
} |
110 | 1 | bo.phoneNumbers = new ArrayList<EntityPhoneBo>() |
111 | 1 | if (CollectionUtils.isNotEmpty(immutable.phoneNumbers)) { |
112 | 0 | for (EntityPhone phone : immutable.phoneNumbers) { |
113 | 0 | bo.phoneNumbers.add(EntityPhoneBo.from(phone)) |
114 | |
} |
115 | |
} |
116 | 1 | bo.emailAddresses = new ArrayList<EntityTypeDataBo>() |
117 | 1 | if (CollectionUtils.isNotEmpty(immutable.emailAddresses)) { |
118 | 0 | for (EntityTypeData email : immutable.emailAddresses) { |
119 | 0 | bo.emailAddresses.add(EntityTypeDataBo.from(email)) |
120 | |
} |
121 | |
} |
122 | 1 | bo.versionNumber = immutable.versionNumber |
123 | 1 | bo.objectId = immutable.objectId |
124 | |
|
125 | 1 | return bo; |
126 | |
} |
127 | |
|
128 | |
EntityAddressBo getDefaultAddress() { |
129 | 0 | return EntityUtils.getDefaultItem(this.addresses); |
130 | |
} |
131 | |
EntityEmailBo getDefaultEmailAddress() { |
132 | 0 | return EntityUtils.getDefaultItem(this.emailAddresses); |
133 | |
} |
134 | |
EntityPhoneBo getDefaultPhoneNumber() { |
135 | 0 | return EntityUtils.getDefaultItem(this.phoneNumbers); |
136 | |
} |
137 | |
|
138 | |
EntityTypeBo getEntityType() { |
139 | 1 | return this.entityType |
140 | |
} |
141 | |
|
142 | |
} |