1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.api.identity.personal;
17
18 import org.apache.commons.collections.CollectionUtils;
19 import org.apache.commons.lang.StringUtils;
20 import org.joda.time.DateTime;
21 import org.kuali.rice.core.api.CoreConstants;
22 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
23 import org.kuali.rice.core.api.mo.ModelBuilder;
24 import org.kuali.rice.core.api.mo.common.active.InactivatableFromToUtils;
25 import org.kuali.rice.core.api.util.jaxb.DateTimeAdapter;
26 import org.kuali.rice.kim.api.KimApiConstants;
27 import org.kuali.rice.kim.api.identity.CodedAttribute;
28 import org.kuali.rice.kim.api.identity.CodedAttributeContract;
29 import org.kuali.rice.kim.api.identity.CodedAttributeHistory;
30 import org.kuali.rice.kim.api.identity.CodedAttributeHistoryContract;
31 import org.w3c.dom.Element;
32
33 import javax.xml.bind.annotation.XmlAccessType;
34 import javax.xml.bind.annotation.XmlAccessorType;
35 import javax.xml.bind.annotation.XmlAnyElement;
36 import javax.xml.bind.annotation.XmlElement;
37 import javax.xml.bind.annotation.XmlElementWrapper;
38 import javax.xml.bind.annotation.XmlRootElement;
39 import javax.xml.bind.annotation.XmlType;
40 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
41 import java.io.Serializable;
42 import java.util.ArrayList;
43 import java.util.Collection;
44 import java.util.Collections;
45 import java.util.List;
46
47 @XmlRootElement(name = EntityEthnicityHistory.Constants.ROOT_ELEMENT_NAME)
48 @XmlAccessorType(XmlAccessType.NONE)
49 @XmlType(name = EntityEthnicityHistory.Constants.TYPE_NAME, propOrder = {
50 EntityEthnicityHistory.Elements.ID,
51 EntityEthnicityHistory.Elements.ENTITY_ID,
52 EntityEthnicityHistory.Elements.ETHNICITY_CODE,
53 EntityEthnicityHistory.Elements.ETHNICITY_CODE_UNMASKED,
54 EntityEthnicityHistory.Elements.SUB_ETHNICITY_CODE,
55 EntityEthnicityHistory.Elements.SUB_ETHNICITY_CODE_UNMASKED,
56 EntityEthnicityHistory.Elements.SUPPRESS_PERSONAL,
57 EntityEthnicityHistory.Elements.HISPANIC_OR_LATINO,
58 EntityEthnicityHistory.Elements.RACE_ETHNICITY_CODE,
59 EntityEthnicityHistory.Elements.RACE_ETHNICITY_CODE_UNMASKED,
60 EntityEthnicityHistory.Elements.LOCAL_RACE_ETHNICITY_CODE,
61 EntityEthnicityHistory.Elements.LOCAL_RACE_ETHNICITY_CODE_UNMASKED,
62 CoreConstants.CommonElements.HISTORY_ID,
63 CoreConstants.CommonElements.ACTIVE_FROM_DATE,
64 CoreConstants.CommonElements.ACTIVE_TO_DATE,
65 CoreConstants.CommonElements.VERSION_NUMBER,
66 CoreConstants.CommonElements.OBJECT_ID,
67 EntityEthnicityHistory.Elements.PERCENTAGE,
68 EntityEthnicityHistory.Elements.PERCENTAGE_UNMASKED,
69 CoreConstants.CommonElements.FUTURE_ELEMENTS
70 })
71 public final class EntityEthnicityHistory extends AbstractDataTransferObject
72 implements EntityEthnicityHistoryContract
73 {
74
75 @XmlElement(name = Elements.ENTITY_ID, required = false)
76 private final String entityId;
77 @XmlElement(name = Elements.ETHNICITY_CODE, required = false)
78 private final String ethnicityCode;
79 @XmlElement(name = Elements.ETHNICITY_CODE_UNMASKED, required = false)
80 private final String ethnicityCodeUnmasked;
81 @XmlElement(name = Elements.SUB_ETHNICITY_CODE, required = false)
82 private final String subEthnicityCode;
83 @XmlElement(name = Elements.SUB_ETHNICITY_CODE_UNMASKED, required = false)
84 private final String subEthnicityCodeUnmasked;
85 @XmlElement(name = Elements.SUPPRESS_PERSONAL, required = false)
86 private final boolean suppressPersonal;
87 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
88 private final Long versionNumber;
89 @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
90 private final String objectId;
91 @XmlElement(name = Elements.ID, required = false)
92 private final String id;
93 @XmlElement(name = Elements.HISPANIC_OR_LATINO, required = false)
94 private final boolean hispanicOrLatino;
95 @XmlElementWrapper(name = Elements.RACE_ETHNICITY_CODE, required = false)
96 @XmlElement(name = Elements.RACE_ETHNICITY_CODE, required = false)
97 private final CodedAttributeHistory raceEthnicityCode;
98 @XmlElement(name = Elements.RACE_ETHNICITY_CODE_UNMASKED, required = false)
99 private final CodedAttributeHistory raceEthnicityCodeUnmasked;
100 @XmlElement(name = Elements.LOCAL_RACE_ETHNICITY_CODE, required = false)
101 private final String localRaceEthnicityCode;
102 @XmlElement(name = Elements.LOCAL_RACE_ETHNICITY_CODE_UNMASKED, required = false)
103 private final String localRaceEthnicityCodeUnmasked;
104 @XmlElement(name = CoreConstants.CommonElements.HISTORY_ID, required = false)
105 private final Long historyId;
106 @XmlElement(name = CoreConstants.CommonElements.ACTIVE_FROM_DATE, required = false)
107 @XmlJavaTypeAdapter(DateTimeAdapter.class)
108 private final DateTime activeFromDate;
109 @XmlElement(name = CoreConstants.CommonElements.ACTIVE_TO_DATE, required = false)
110 @XmlJavaTypeAdapter(DateTimeAdapter.class)
111 private final DateTime activeToDate;
112 @XmlElement(name = Elements.PERCENTAGE, required = false)
113 private final Double percentage;
114 @XmlElement(name = Elements.PERCENTAGE_UNMASKED, required = false)
115 private final Double percentageUnmasked;
116 @SuppressWarnings("unused")
117 @XmlAnyElement
118 private final Collection<Element> _futureElements = null;
119
120
121
122
123
124 private EntityEthnicityHistory() {
125 this.entityId = null;
126 this.ethnicityCode = null;
127 this.ethnicityCodeUnmasked = null;
128 this.subEthnicityCode = null;
129 this.subEthnicityCodeUnmasked = null;
130 this.suppressPersonal = false;
131 this.versionNumber = null;
132 this.objectId = null;
133 this.id = null;
134 this.hispanicOrLatino = false;
135 this.raceEthnicityCode = null;
136 this.raceEthnicityCodeUnmasked = null;
137 this.localRaceEthnicityCode = null;
138 this.localRaceEthnicityCodeUnmasked = null;
139 this.historyId = null;
140 this.activeFromDate = null;
141 this.activeToDate = null;
142 this.percentage = null;
143 this.percentageUnmasked = null;
144 }
145
146 private EntityEthnicityHistory(Builder builder) {
147 this.entityId = builder.getEntityId();
148 this.ethnicityCode = builder.getEthnicityCode();
149 this.ethnicityCodeUnmasked = builder.getEthnicityCodeUnmasked();
150 this.subEthnicityCode = builder.getSubEthnicityCode();
151 this.subEthnicityCodeUnmasked = builder.getSubEthnicityCodeUnmasked();
152 this.suppressPersonal = builder.isSuppressPersonal();
153 this.versionNumber = builder.getVersionNumber();
154 this.objectId = builder.getObjectId();
155 this.id = builder.getId();
156 this.hispanicOrLatino = builder.isHispanicOrLatino();
157 this.raceEthnicityCode = builder.getRaceEthnicityCode() != null ? builder.getRaceEthnicityCode().build() : null;
158 this.raceEthnicityCodeUnmasked = builder.getRaceEthnicityCodeUnmasked() != null ? builder.getRaceEthnicityCodeUnmasked().build() : null;
159 this.localRaceEthnicityCode = builder.getLocalRaceEthnicityCode();
160 this.localRaceEthnicityCodeUnmasked = builder.getLocalRaceEthnicityCodeUnmasked();
161 this.historyId = builder.getHistoryId();
162 this.activeFromDate = builder.getActiveFromDate();
163 this.activeToDate = builder.getActiveToDate();
164 this.percentage = builder.getPercentage();
165 this.percentageUnmasked = builder.getPercentageUnmasked();
166 }
167
168 @Override
169 public String getEntityId() {
170 return this.entityId;
171 }
172
173 @Override
174 public String getEthnicityCode() {
175 return this.ethnicityCode;
176 }
177
178 @Override
179 public String getEthnicityCodeUnmasked() {
180 return this.ethnicityCodeUnmasked;
181 }
182
183 @Override
184 public String getSubEthnicityCode() {
185 return this.subEthnicityCode;
186 }
187
188 @Override
189 public String getSubEthnicityCodeUnmasked() {
190 return this.subEthnicityCodeUnmasked;
191 }
192
193 @Override
194 public boolean isSuppressPersonal() {
195 return this.suppressPersonal;
196 }
197
198 @Override
199 public Long getVersionNumber() {
200 return this.versionNumber;
201 }
202
203 @Override
204 public String getObjectId() {
205 return this.objectId;
206 }
207
208 @Override
209 public String getId() {
210 return this.id;
211 }
212
213 @Override
214 public boolean isHispanicOrLatino() {
215 return this.hispanicOrLatino;
216 }
217
218 @Override
219 public CodedAttributeHistory getRaceEthnicityCode() {
220 return this.raceEthnicityCode;
221 }
222
223 @Override
224 public CodedAttributeHistory getRaceEthnicityCodeUnmasked() {
225 return this.raceEthnicityCodeUnmasked;
226 }
227
228 @Override
229 public String getLocalRaceEthnicityCode() {
230 return this.localRaceEthnicityCode;
231 }
232
233 @Override
234 public String getLocalRaceEthnicityCodeUnmasked() {
235 return this.localRaceEthnicityCodeUnmasked;
236 }
237
238 @Override
239 public Long getHistoryId() {
240 return this.historyId;
241 }
242
243 @Override
244 public DateTime getActiveFromDate() {
245 return this.activeFromDate;
246 }
247
248 @Override
249 public DateTime getActiveToDate() {
250 return this.activeToDate;
251 }
252
253 @Override
254 public boolean isActiveNow() {
255 return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, null);
256 }
257
258 @Override
259 public boolean isActive() {
260 return isActiveNow();
261 }
262
263 @Override
264 public boolean isActive(DateTime activeAsOf) {
265 return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, activeAsOf);
266 }
267
268 @Override
269 public Double getPercentage() {
270 return this.percentage;
271 }
272
273 @Override
274 public Double getPercentageUnmasked() {
275 return this.percentageUnmasked;
276 }
277
278
279
280
281
282
283 public final static class Builder
284 implements Serializable, ModelBuilder, EntityEthnicityHistoryContract
285 {
286
287 private String entityId;
288 private String ethnicityCode;
289 private String subEthnicityCode;
290 private boolean suppressPersonal;
291 private Long versionNumber;
292 private String objectId;
293 private String id;
294 private boolean hispanicOrLatino;
295 private CodedAttributeHistory.Builder raceEthnicityCode;
296 private String localRaceEthnicityCode;
297 private Long historyId;
298 private DateTime activeFromDate;
299 private DateTime activeToDate;
300 private Double percentage;
301
302 private Builder() { }
303
304 public static Builder create() {
305 return new Builder();
306 }
307
308 public static Builder create(EntityEthnicityHistoryContract contract) {
309 if (contract == null) {
310 throw new IllegalArgumentException("contract was null");
311 }
312 Builder builder = create();
313 builder.setEntityId(contract.getEntityId());
314 builder.setEthnicityCode(contract.getEthnicityCodeUnmasked());
315 builder.setSubEthnicityCode(contract.getSubEthnicityCodeUnmasked());
316 builder.setSuppressPersonal(contract.isSuppressPersonal());
317 builder.setVersionNumber(contract.getVersionNumber());
318 builder.setObjectId(contract.getObjectId());
319 builder.setId(contract.getId());
320 builder.setHispanicOrLatino(contract.isHispanicOrLatino());
321 if (contract.getRaceEthnicityCode() != null) {
322 builder.setRaceEthnicityCodes(CodedAttributeHistory.Builder.create(contract.getRaceEthnicityCode()));
323 }
324 builder.setLocalRaceEthnicityCode(contract.getLocalRaceEthnicityCodeUnmasked());
325 builder.setHistoryId(contract.getHistoryId());
326 builder.setActiveFromDate(contract.getActiveFromDate());
327 builder.setActiveToDate(contract.getActiveToDate());
328 builder.setPercentage(contract.getPercentageUnmasked());
329 return builder;
330 }
331
332 @Override
333 public EntityEthnicityHistory build() {
334 return new EntityEthnicityHistory(this);
335 }
336
337 @Override
338 public String getEntityId() {
339 return this.entityId;
340 }
341
342 @Override
343 public String getEthnicityCode() {
344 if (isSuppressPersonal()) {
345 return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
346 }
347 return this.ethnicityCode;
348 }
349
350 @Override
351 public String getEthnicityCodeUnmasked() {
352 return this.ethnicityCode;
353 }
354
355 @Override
356 public String getSubEthnicityCode() {
357 if (isSuppressPersonal()) {
358 return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
359 }
360 return this.subEthnicityCode;
361 }
362
363 @Override
364 public String getSubEthnicityCodeUnmasked() {
365 return this.subEthnicityCode;
366 }
367
368 @Override
369 public boolean isSuppressPersonal() {
370 return this.suppressPersonal;
371 }
372
373 @Override
374 public Long getVersionNumber() {
375 return this.versionNumber;
376 }
377
378 @Override
379 public String getObjectId() {
380 return this.objectId;
381 }
382
383 @Override
384 public String getId() {
385 return this.id;
386 }
387
388 @Override
389 public boolean isHispanicOrLatino() {
390 return this.hispanicOrLatino;
391 }
392
393 @Override
394 public CodedAttributeHistory.Builder getRaceEthnicityCode() {
395 if (isSuppressPersonal()) {
396 return null;
397 }
398 return this.raceEthnicityCode;
399 }
400
401 @Override
402 public CodedAttributeHistory.Builder getRaceEthnicityCodeUnmasked() {
403 return this.raceEthnicityCode;
404 }
405
406 @Override
407 public String getLocalRaceEthnicityCode() {
408 if (isSuppressPersonal()) {
409 return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
410 }
411 return this.localRaceEthnicityCode;
412 }
413
414 @Override
415 public String getLocalRaceEthnicityCodeUnmasked() {
416 return this.localRaceEthnicityCode;
417 }
418
419 @Override
420 public Long getHistoryId() {
421 return this.historyId;
422 }
423
424 @Override
425 public boolean isActiveNow() {
426 return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, null);
427 }
428
429 @Override
430 public boolean isActive() {
431 return isActiveNow();
432 }
433
434 @Override
435 public boolean isActive(DateTime activeAsOf) {
436 return InactivatableFromToUtils.isActive(activeFromDate, activeToDate, activeAsOf);
437 }
438
439 @Override
440 public DateTime getActiveFromDate() {
441 return this.activeFromDate;
442 }
443
444 @Override
445 public DateTime getActiveToDate() {
446 return this.activeToDate;
447 }
448
449 @Override
450 public Double getPercentage() {
451 if (isSuppressPersonal()) {
452 return null;
453 }
454 return this.percentage;
455 }
456
457 @Override
458 public Double getPercentageUnmasked() {
459 return this.percentage;
460 }
461
462 public void setHistoryId(Long historyId) {
463 this.historyId = historyId;
464 }
465
466 public void setActiveFromDate(DateTime activeFromDate) {
467 this.activeFromDate = activeFromDate;
468 }
469
470 public void setActiveToDate(DateTime activeToDate) {
471 this.activeToDate = activeToDate;
472 }
473
474 public void setHispanicOrLatino(boolean hispanicOrLatino) {
475 this.hispanicOrLatino = hispanicOrLatino;
476 }
477
478 public void setRaceEthnicityCodes(CodedAttributeHistory.Builder raceEthnicityCode) {
479 this.raceEthnicityCode = raceEthnicityCode;
480 }
481
482 public void setLocalRaceEthnicityCode(String localRaceEthnicityCode) {
483 this.localRaceEthnicityCode = localRaceEthnicityCode;
484 }
485
486 public void setEntityId(String entityId) {
487 this.entityId = entityId;
488 }
489
490 public void setEthnicityCode(String ethnicityCode) {
491 this.ethnicityCode = ethnicityCode;
492 }
493
494 public void setSubEthnicityCode(String subEthnicityCode) {
495 this.subEthnicityCode = subEthnicityCode;
496 }
497
498 private void setSuppressPersonal(boolean suppressPersonal) {
499 this.suppressPersonal = suppressPersonal;
500 }
501
502 public void setVersionNumber(Long versionNumber) {
503 this.versionNumber = versionNumber;
504 }
505
506 public void setObjectId(String objectId) {
507 this.objectId = objectId;
508 }
509
510 public void setId(String id) {
511 if (StringUtils.isWhitespace(id)) {
512 throw new IllegalArgumentException("id is blank");
513 }
514 this.id = id;
515 }
516
517 public void setPercentage(Double percentage) {
518 this.percentage = percentage;
519 }
520
521 }
522
523
524
525
526
527
528 static class Constants {
529
530 final static String ROOT_ELEMENT_NAME = "entityEthnicity";
531 final static String TYPE_NAME = "EntityEthnicityType";
532 }
533
534
535
536
537
538
539 static class Elements {
540
541 final static String ENTITY_ID = "entityId";
542 final static String ETHNICITY_CODE = "ethnicityCode";
543 final static String ETHNICITY_CODE_UNMASKED = "ethnicityCodeUnmasked";
544 final static String SUB_ETHNICITY_CODE = "subEthnicityCode";
545 final static String SUB_ETHNICITY_CODE_UNMASKED = "subEthnicityCodeUnmasked";
546 final static String SUPPRESS_PERSONAL = "suppressPersonal";
547 final static String ID = "id";
548 final static String HISPANIC_OR_LATINO = "hispanicOrLatino";
549 final static String RACE_ETHNICITY_CODE_UNMASKED = "raceEthnicityCodeUnmasked";
550 final static String RACE_ETHNICITY_CODE = "raceEthnicityCode";
551 final static String LOCAL_RACE_ETHNICITY_CODE = "localRaceEthnicityCode";
552 final static String LOCAL_RACE_ETHNICITY_CODE_UNMASKED = "localRaceEthnicityCodeUnmasked";
553 final static String PERCENTAGE = "percentage";
554 final static String PERCENTAGE_UNMASKED = "percentageUnmasked";
555 }
556
557 }