1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.impl.identity.personal;
17
18 import org.joda.time.DateTime;
19 import org.joda.time.Years;
20 import org.joda.time.format.DateTimeFormat;
21 import org.kuali.rice.kim.api.KimApiConstants;
22 import org.kuali.rice.kim.api.identity.personal.EntityBioDemographics;
23 import org.kuali.rice.kim.api.identity.personal.EntityBioDemographicsContract;
24 import org.kuali.rice.kim.api.identity.privacy.EntityPrivacyPreferences;
25 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
26 import org.kuali.rice.krad.bo.DataObjectBase;
27
28 import javax.persistence.Column;
29 import javax.persistence.Entity;
30 import javax.persistence.Id;
31 import javax.persistence.Table;
32 import javax.persistence.Temporal;
33 import javax.persistence.TemporalType;
34 import javax.persistence.Transient;
35 import java.text.SimpleDateFormat;
36 import java.util.List;
37
38 @Entity
39 @Table(name = "KRIM_ENTITY_BIO_T")
40 public class EntityBioDemographicsBo extends DataObjectBase implements EntityBioDemographicsContract {
41
42 private static final long serialVersionUID = 1L;
43
44 @Id
45 @Column(name = "ENTITY_ID")
46 private String entityId;
47
48 @Temporal(TemporalType.DATE)
49 @Column(name = "BIRTH_DT")
50 private java.util.Date birthDateValue;
51
52 @Column(name = "GNDR_CD")
53 private String genderCode;
54
55 @Column(name = "GNDR_CHG_CD")
56 private String genderChangeCode;
57
58 @Temporal(TemporalType.DATE)
59 @Column(name = "DECEASED_DT")
60 private java.util.Date deceasedDateValue;
61
62 @Column(name = "MARITAL_STATUS")
63 private String maritalStatusCode;
64
65 @Column(name = "PRIM_LANG_CD")
66 private String primaryLanguageCode;
67
68 @Column(name = "SEC_LANG_CD")
69 private String secondaryLanguageCode;
70
71 @Column(name = "BIRTH_CNTRY_CD")
72 private String birthCountry;
73
74 @Column(name = "BIRTH_STATE_PVC_CD")
75 private String birthStateProvinceCode;
76
77 @Column(name = "BIRTH_CITY")
78 private String birthCity;
79
80 @Column(name = "GEO_ORIGIN")
81 private String geographicOrigin;
82
83 @Column(name = "NOTE_MSG")
84 private String noteMessage;
85
86 @Transient
87 private boolean suppressPersonal;
88
89 public static EntityBioDemographics to(EntityBioDemographicsBo bo) {
90 if (bo == null) {
91 return null;
92 }
93 return EntityBioDemographics.Builder.create(bo).build();
94 }
95
96
97
98
99
100
101
102 public static EntityBioDemographicsBo from(EntityBioDemographics immutable) {
103 if (immutable == null) {
104 return null;
105 }
106 EntityBioDemographicsBo bo = new EntityBioDemographicsBo();
107 bo.entityId = immutable.getEntityId();
108 if (immutable.getBirthDateUnmasked() != null) {
109 bo.birthDateValue = DateTimeFormat.forPattern(EntityBioDemographicsContract.BIRTH_DATE_FORMAT).parseDateTime(immutable.getBirthDateUnmasked()).toDate();
110 }
111 bo.birthStateProvinceCode = immutable.getBirthStateProvinceCodeUnmasked();
112 bo.birthCity = immutable.getBirthCityUnmasked();
113 bo.birthCountry = immutable.getBirthCountryUnmasked();
114 if (immutable.getDeceasedDate() != null) {
115 bo.deceasedDateValue = DateTimeFormat.forPattern(EntityBioDemographicsContract.DECEASED_DATE_FORMAT).parseDateTime(immutable.getDeceasedDate()).toDate();
116 }
117 bo.genderCode = immutable.getGenderCodeUnmasked();
118 bo.geographicOrigin = immutable.getGeographicOriginUnmasked();
119 bo.maritalStatusCode = immutable.getMaritalStatusCodeUnmasked();
120 bo.primaryLanguageCode = immutable.getPrimaryLanguageCodeUnmasked();
121 bo.secondaryLanguageCode = immutable.getSecondaryLanguageCodeUnmasked();
122 bo.noteMessage = immutable.getNoteMessage();
123 bo.suppressPersonal = immutable.isSuppressPersonal();
124 bo.setVersionNumber(immutable.getVersionNumber());
125 bo.setObjectId(immutable.getObjectId());
126 return bo;
127 }
128
129 @Override
130 public String getBirthDate() {
131 if (this.birthDateValue != null) {
132 if (isSuppressPersonal()) {
133 return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
134 }
135 return new SimpleDateFormat(BIRTH_DATE_FORMAT).format(this.birthDateValue);
136 }
137 return null;
138 }
139
140 @Override
141 public Integer getAge() {
142 if (this.birthDateValue != null && !isSuppressPersonal()) {
143 DateTime endDate;
144 if (this.deceasedDateValue != null) {
145 endDate = new DateTime(this.deceasedDateValue);
146 } else {
147 endDate = new DateTime();
148 }
149 return Years.yearsBetween(new DateTime(this.birthDateValue), endDate).getYears();
150 }
151 return null;
152 }
153
154 @Override
155 public String getDeceasedDate() {
156 if (this.deceasedDateValue != null) {
157 return new SimpleDateFormat(DECEASED_DATE_FORMAT).format(this.deceasedDateValue);
158 }
159 return null;
160 }
161
162 @Override
163 public String getBirthDateUnmasked() {
164 if (this.birthDateValue != null) {
165 return new SimpleDateFormat(BIRTH_DATE_FORMAT).format(this.birthDateValue);
166 }
167 return null;
168 }
169
170 @Override
171 public boolean isSuppressPersonal() {
172 try {
173 EntityPrivacyPreferences privacy = KimApiServiceLocator.getIdentityService().getEntityPrivacyPreferences(getEntityId());
174 if (privacy != null) {
175 this.suppressPersonal = privacy.isSuppressPersonal();
176 } else {
177 this.suppressPersonal = false;
178 }
179 } catch (NullPointerException e) {
180 return false;
181 } catch (ClassCastException c) {
182 return false;
183 }
184 return suppressPersonal;
185 }
186
187 @Override
188 public String getGenderCode() {
189 if (isSuppressPersonal()) {
190 return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE;
191 }
192 return this.genderCode;
193 }
194
195 @Override
196 public String getGenderChangeCode() {
197 if (isSuppressPersonal()) {
198 return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE;
199 }
200 return this.genderChangeCode;
201 }
202
203 @Override
204 public String getMaritalStatusCode() {
205 if (isSuppressPersonal()) {
206 return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE;
207 }
208 return this.maritalStatusCode;
209 }
210
211 @Override
212 public String getPrimaryLanguageCode() {
213 if (isSuppressPersonal()) {
214 return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE;
215 }
216 return this.primaryLanguageCode;
217 }
218
219 @Override
220 public String getSecondaryLanguageCode() {
221 if (isSuppressPersonal()) {
222 return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE;
223 }
224 return this.secondaryLanguageCode;
225 }
226
227 @Override
228 public String getBirthCountry() {
229 if (isSuppressPersonal()) {
230 return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE;
231 }
232 return this.birthCountry;
233 }
234
235 @Override
236 public String getBirthStateProvinceCode() {
237 if (isSuppressPersonal()) {
238 return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE;
239 }
240 return this.birthStateProvinceCode;
241 }
242
243 @Override
244 public String getBirthCity() {
245 if (isSuppressPersonal()) {
246 return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE;
247 }
248 return this.birthCity;
249 }
250
251 @Override
252 public String getGeographicOrigin() {
253 if (isSuppressPersonal()) {
254 return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE;
255 }
256 return this.geographicOrigin;
257 }
258
259 @Override
260 public String getGenderCodeUnmasked() {
261 return this.genderCode;
262 }
263
264 @Override
265 public String getGenderChangeCodeUnmasked() {
266 return this.genderChangeCode;
267 }
268
269 @Override
270 public String getMaritalStatusCodeUnmasked() {
271 return this.maritalStatusCode;
272 }
273
274 @Override
275 public String getPrimaryLanguageCodeUnmasked() {
276 return this.primaryLanguageCode;
277 }
278
279 @Override
280 public String getSecondaryLanguageCodeUnmasked() {
281 return this.secondaryLanguageCode;
282 }
283
284 @Override
285 public String getBirthCountryUnmasked() {
286 return this.birthCountry;
287 }
288
289 @Override
290 public String getBirthStateProvinceCodeUnmasked() {
291 return this.birthStateProvinceCode;
292 }
293
294 @Override
295 public String getBirthCityUnmasked() {
296 return this.birthCity;
297 }
298
299 @Override
300 public String getGeographicOriginUnmasked() {
301 return this.geographicOrigin;
302 }
303
304 @Override
305 public String getEntityId() {
306 return entityId;
307 }
308
309 public void setEntityId(String entityId) {
310 this.entityId = entityId;
311 }
312
313 public java.util.Date getBirthDateValue() {
314 return birthDateValue;
315 }
316
317 public void setBirthDateValue(java.util.Date birthDateValue) {
318 this.birthDateValue = birthDateValue;
319 }
320
321 public void setGenderCode(String genderCode) {
322 this.genderCode = genderCode;
323 }
324
325 public void setGenderChangeCode(String genderChangeCode) {
326 this.genderChangeCode = genderChangeCode;
327 }
328
329 public java.util.Date getDeceasedDateValue() {
330 return deceasedDateValue;
331 }
332
333 public void setDeceasedDateValue(java.util.Date deceasedDateValue) {
334 this.deceasedDateValue = deceasedDateValue;
335 }
336
337 public void setMaritalStatusCode(String maritalStatusCode) {
338 this.maritalStatusCode = maritalStatusCode;
339 }
340
341 public void setPrimaryLanguageCode(String primaryLanguageCode) {
342 this.primaryLanguageCode = primaryLanguageCode;
343 }
344
345 public void setSecondaryLanguageCode(String secondaryLanguageCode) {
346 this.secondaryLanguageCode = secondaryLanguageCode;
347 }
348
349 public void setBirthCountry(String birthCountry) {
350 this.birthCountry = birthCountry;
351 }
352
353 public void setBirthStateProvinceCode(String birthStateProvinceCode) {
354 this.birthStateProvinceCode = birthStateProvinceCode;
355 }
356
357 public void setBirthCity(String birthCity) {
358 this.birthCity = birthCity;
359 }
360
361 public void setGeographicOrigin(String geographicOrigin) {
362 this.geographicOrigin = geographicOrigin;
363 }
364
365 @Override
366 public String getNoteMessage() {
367 return noteMessage;
368 }
369
370 public void setNoteMessage(String noteMessage) {
371 this.noteMessage = noteMessage;
372 }
373
374 public void setSuppressPersonal(boolean suppressPersonal) {
375 this.suppressPersonal = suppressPersonal;
376 }
377 }