1 | |
package org.kuali.rice.kim.impl.identity.address |
2 | |
|
3 | |
import javax.persistence.Column |
4 | |
import javax.persistence.Entity |
5 | |
import javax.persistence.FetchType |
6 | |
import javax.persistence.Id |
7 | |
import javax.persistence.JoinColumn |
8 | |
import javax.persistence.ManyToOne |
9 | |
import javax.persistence.Table |
10 | |
import javax.persistence.Transient |
11 | |
import org.hibernate.annotations.Type |
12 | |
import org.kuali.rice.kim.api.KimConstants |
13 | |
import org.kuali.rice.kim.api.identity.address.EntityAddress |
14 | |
import org.kuali.rice.kim.api.identity.address.EntityAddressContract |
15 | |
import org.kuali.rice.kim.api.identity.privacy.EntityPrivacyPreferences |
16 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator |
17 | |
import org.kuali.rice.krad.bo.PersistableBusinessObjectBase |
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
@Entity |
23 | |
@Table(name = "KRIM_ENTITY_ADDR_T") |
24 | |
public class EntityAddressBo extends PersistableBusinessObjectBase implements EntityAddressContract { |
25 | |
private static final long serialVersionUID = 1L; |
26 | |
|
27 | |
@Id |
28 | |
@Column(name = "ENTITY_ADDR_ID") |
29 | |
String id |
30 | |
|
31 | |
@Column(name = "ENTITY_ID") |
32 | |
String entityId |
33 | |
|
34 | |
@Column(name = "ADDR_TYP_CD") |
35 | |
String addressTypeCode |
36 | |
|
37 | |
@Column(name = "ENT_TYP_CD") |
38 | |
String entityTypeCode |
39 | |
|
40 | |
@Column(name = "CITY_NM") |
41 | |
String cityName |
42 | |
|
43 | |
@Column(name = "POSTAL_STATE_CD") |
44 | |
String stateCode |
45 | |
|
46 | |
@Column(name = "POSTAL_CD") |
47 | |
String postalCode |
48 | |
|
49 | |
@Column(name = "POSTAL_CNTRY_CD") |
50 | |
String countryCode |
51 | |
|
52 | |
@Column(name = "ADDR_LINE_1") |
53 | |
String line1 |
54 | |
|
55 | |
@Column(name = "ADDR_LINE_2") |
56 | |
String line2 |
57 | |
|
58 | |
@Column(name = "ADDR_LINE_3") |
59 | |
String line3 |
60 | |
|
61 | |
@Type(type="yes_no") |
62 | |
@Column(name="DFLT_IND") |
63 | |
boolean defaultValue; |
64 | |
|
65 | |
@Type(type="yes_no") |
66 | |
@Column(name="ACTV_IND") |
67 | |
boolean active; |
68 | |
|
69 | |
|
70 | |
@ManyToOne(targetEntity=EntityAddressTypeBo.class, fetch=FetchType.EAGER, cascade=[]) |
71 | |
@JoinColumn(name = "ADDR_TYP_CD", insertable = false, updatable = false) |
72 | |
EntityAddressTypeBo addressType; |
73 | |
|
74 | |
@Transient |
75 | |
boolean suppressAddress; |
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
static EntityAddress to(EntityAddressBo bo) { |
83 | 1 | if (bo == null) { return null } |
84 | 1 | return EntityAddress.Builder.create(bo).build() |
85 | |
} |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
static EntityAddressBo from(EntityAddress immutable) { |
93 | 1 | if (immutable == null) {return null} |
94 | |
|
95 | 1 | EntityAddressBo bo = new EntityAddressBo() |
96 | 1 | bo.active = immutable.active |
97 | 1 | bo.entityTypeCode = immutable.entityTypeCode |
98 | 1 | if (immutable.addressType != null) { |
99 | 0 | bo.addressTypeCode = immutable.addressType.code |
100 | |
} |
101 | 1 | bo.addressType = EntityAddressTypeBo.from(immutable.addressType) |
102 | 1 | bo.defaultValue = immutable.defaultValue |
103 | 1 | bo.line1 = immutable.line1Unmasked |
104 | 1 | bo.line2 = immutable.line2Unmasked |
105 | 1 | bo.line3 = immutable.line3Unmasked |
106 | 1 | bo.cityName = immutable.cityNameUnmasked |
107 | 1 | bo.stateCode = immutable.stateCodeUnmasked |
108 | 1 | bo.countryCode = immutable.countryCodeUnmasked |
109 | 1 | bo.postalCode = immutable.postalCodeUnmasked |
110 | 1 | bo.id = immutable.id |
111 | 1 | bo.entityId = immutable.entityId |
112 | 1 | bo.active = immutable.active |
113 | 1 | bo.versionNumber = immutable.versionNumber |
114 | |
|
115 | 1 | return bo; |
116 | |
} |
117 | |
|
118 | |
|
119 | |
@Override |
120 | |
EntityAddressTypeBo getAddressType() { |
121 | 1 | return addressType |
122 | |
} |
123 | |
|
124 | |
public void setAddressType(EntityAddressTypeBo addressType) { |
125 | 1 | this.addressType = addressType |
126 | |
} |
127 | |
|
128 | |
@Override |
129 | |
boolean isSuppressAddress() { |
130 | 1 | if (this.suppressAddress == null) { |
131 | 0 | EntityPrivacyPreferences privacy = KimApiServiceLocator.getIdentityService().getEntityPrivacyPreferences(getEntityId()) |
132 | 0 | if (privacy != null) { |
133 | 0 | this.suppressAddress = privacy.isSuppressAddress() |
134 | |
} else { |
135 | 0 | this.suppressAddress = false |
136 | |
} |
137 | |
} |
138 | |
|
139 | 1 | return suppressAddress; |
140 | |
} |
141 | |
|
142 | |
@Override |
143 | |
String getLine1() { |
144 | 0 | if (isSuppressAddress()) { |
145 | 0 | return KimConstants.RestrictedMasks.RESTRICTED_DATA_MASK; |
146 | |
} |
147 | 0 | return this.line1; |
148 | |
|
149 | |
} |
150 | |
|
151 | |
@Override |
152 | |
String getLine2() { |
153 | 0 | if (isSuppressAddress()) { |
154 | 0 | return KimConstants.RestrictedMasks.RESTRICTED_DATA_MASK; |
155 | |
} |
156 | 0 | return this.line2; |
157 | |
} |
158 | |
|
159 | |
@Override |
160 | |
String getLine3() { |
161 | 0 | if (isSuppressAddress()) { |
162 | 0 | return KimConstants.RestrictedMasks.RESTRICTED_DATA_MASK; |
163 | |
} |
164 | 0 | return this.line3; |
165 | |
} |
166 | |
|
167 | |
@Override |
168 | |
String getCityName() { |
169 | 0 | if (isSuppressAddress()) { |
170 | 0 | return KimConstants.RestrictedMasks.RESTRICTED_DATA_MASK; |
171 | |
} |
172 | 0 | return this.cityName; |
173 | |
} |
174 | |
|
175 | |
@Override |
176 | |
String getStateCode() { |
177 | 0 | if (isSuppressAddress()) { |
178 | 0 | return KimConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE; |
179 | |
} |
180 | 0 | return this.stateCode; |
181 | |
} |
182 | |
|
183 | |
@Override |
184 | |
String getPostalCode() { |
185 | 0 | if (isSuppressAddress()) { |
186 | 0 | return KimConstants.RestrictedMasks.RESTRICTED_DATA_MASK_ZIP; |
187 | |
} |
188 | 0 | return this.postalCode; |
189 | |
} |
190 | |
|
191 | |
@Override |
192 | |
String getCountryCode() { |
193 | 0 | if (isSuppressAddress()) { |
194 | 0 | return KimConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE; |
195 | |
} |
196 | 0 | return this.countryCode; |
197 | |
} |
198 | |
|
199 | |
@Override |
200 | |
String getLine1Unmasked() { |
201 | 1 | return line1 |
202 | |
} |
203 | |
@Override |
204 | |
String getLine2Unmasked() { |
205 | 1 | return line2 |
206 | |
} |
207 | |
@Override |
208 | |
String getLine3Unmasked() { |
209 | 1 | return line3 |
210 | |
} |
211 | |
@Override |
212 | |
String getCityNameUnmasked() { |
213 | 1 | return cityName |
214 | |
} |
215 | |
@Override |
216 | |
String getStateCodeUnmasked() { |
217 | 1 | return stateCode |
218 | |
} |
219 | |
@Override |
220 | |
String getPostalCodeUnmasked() { |
221 | 1 | return postalCode |
222 | |
} |
223 | |
@Override |
224 | |
String getCountryCodeUnmasked() { |
225 | 1 | return countryCode |
226 | |
} |
227 | |
} |