1 package org.kuali.rice.kim.api.identity.address;
2
3 import java.io.Serializable;
4 import java.util.Collection;
5 import javax.xml.bind.annotation.XmlAccessType;
6 import javax.xml.bind.annotation.XmlAccessorType;
7 import javax.xml.bind.annotation.XmlAnyElement;
8 import javax.xml.bind.annotation.XmlElement;
9 import javax.xml.bind.annotation.XmlRootElement;
10 import javax.xml.bind.annotation.XmlType;
11
12 import org.apache.commons.lang.StringUtils;
13 import org.kuali.rice.core.api.CoreConstants;
14 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
15 import org.kuali.rice.core.api.mo.ModelBuilder;
16 import org.kuali.rice.kim.api.KimApiConstants;
17 import org.kuali.rice.kim.api.identity.Type;
18 import org.w3c.dom.Element;
19
20 @XmlRootElement(name = EntityAddress.Constants.ROOT_ELEMENT_NAME)
21 @XmlAccessorType(XmlAccessType.NONE)
22 @XmlType(name = EntityAddress.Constants.TYPE_NAME, propOrder = {
23 EntityAddress.Elements.ID,
24 EntityAddress.Elements.ENTITY_TYPE_CODE,
25 EntityAddress.Elements.ENTITY_ID,
26 EntityAddress.Elements.ADDRESS_TYPE,
27 EntityAddress.Elements.LINE1,
28 EntityAddress.Elements.LINE2,
29 EntityAddress.Elements.LINE3,
30 EntityAddress.Elements.CITY,
31 EntityAddress.Elements.STATE_CODE,
32 EntityAddress.Elements.POSTAL_CODE,
33 EntityAddress.Elements.COUNTRY_CODE,
34
35 EntityAddress.Elements.LINE1_UNMASKED,
36 EntityAddress.Elements.LINE2_UNMASKED,
37 EntityAddress.Elements.LINE3_UNMASKED,
38 EntityAddress.Elements.CITY_UNMASKED,
39 EntityAddress.Elements.STATE_CODE_UNMASKED,
40 EntityAddress.Elements.POSTAL_CODE_UNMASKED,
41 EntityAddress.Elements.COUNTRY_CODE_UNMASKED,
42 EntityAddress.Elements.SUPPRESS_ADDRESS,
43 EntityAddress.Elements.DEFAULT_VALUE,
44 EntityAddress.Elements.ACTIVE,
45 CoreConstants.CommonElements.VERSION_NUMBER,
46 CoreConstants.CommonElements.OBJECT_ID,
47 CoreConstants.CommonElements.FUTURE_ELEMENTS
48 })
49 public final class EntityAddress extends AbstractDataTransferObject
50 implements EntityAddressContract
51 {
52 @XmlElement(name = Elements.ID, required = false)
53 private final String id;
54 @XmlElement(name = Elements.ENTITY_TYPE_CODE, required = false)
55 private final String entityTypeCode;
56 @XmlElement(name = Elements.ENTITY_ID, required = false)
57 private final String entityId;
58 @XmlElement(name = Elements.ADDRESS_TYPE, required = false)
59 private final Type addressType;
60 @XmlElement(name = Elements.LINE1, required = false)
61 private final String line1;
62 @XmlElement(name = Elements.LINE2, required = false)
63 private final String line2;
64 @XmlElement(name = Elements.LINE3, required = false)
65 private final String line3;
66 @XmlElement(name = Elements.CITY, required = false)
67 private final String city;
68 @XmlElement(name = Elements.STATE_CODE, required = false)
69 private final String stateCode;
70 @XmlElement(name = Elements.POSTAL_CODE, required = false)
71 private final String postalCode;
72 @XmlElement(name = Elements.COUNTRY_CODE, required = false)
73 private final String countryCode;
74 @XmlElement(name = Elements.LINE1_UNMASKED, required = false)
75 private final String line1Unmasked;
76 @XmlElement(name = Elements.LINE2_UNMASKED, required = false)
77 private final String line2Unmasked;
78 @XmlElement(name = Elements.LINE3_UNMASKED, required = false)
79 private final String line3Unmasked;
80 @XmlElement(name = Elements.CITY_UNMASKED, required = false)
81 private final String cityUnmasked;
82 @XmlElement(name = Elements.STATE_CODE_UNMASKED, required = false)
83 private final String stateCodeUnmasked;
84 @XmlElement(name = Elements.POSTAL_CODE_UNMASKED, required = false)
85 private final String postalCodeUnmasked;
86 @XmlElement(name = Elements.COUNTRY_CODE_UNMASKED, required = false)
87 private final String countryCodeUnmasked;
88 @XmlElement(name = Elements.SUPPRESS_ADDRESS, required = false)
89 private final boolean suppressAddress;
90 @XmlElement(name = Elements.DEFAULT_VALUE, required = false)
91 private final boolean defaultValue;
92 @XmlElement(name = Elements.ACTIVE, required = false)
93 private final boolean active;
94 @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
95 private final Long versionNumber;
96 @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
97 private final String objectId;
98 @SuppressWarnings("unused")
99 @XmlAnyElement
100 private final Collection<Element> _futureElements = null;
101
102
103
104
105
106 private EntityAddress() {
107 this.entityId = null;
108 this.entityTypeCode = null;
109 this.addressType = null;
110 this.line1 = null;
111 this.line2 = null;
112 this.line3 = null;
113 this.city = null;
114 this.stateCode = null;
115 this.postalCode = null;
116 this.countryCode = null;
117 this.line1Unmasked = null;
118 this.line2Unmasked = null;
119 this.line3Unmasked = null;
120 this.cityUnmasked = null;
121 this.stateCodeUnmasked = null;
122 this.postalCodeUnmasked = null;
123 this.countryCodeUnmasked = null;
124 this.suppressAddress = false;
125 this.defaultValue = false;
126 this.versionNumber = null;
127 this.objectId = null;
128 this.active = false;
129 this.id = null;
130 }
131
132 private EntityAddress(Builder builder) {
133 this.entityId = builder.getEntityId();
134 this.entityTypeCode = builder.getEntityTypeCode();
135
136 this.addressType = (builder.getAddressType() != null) ? builder.getAddressType().build() : null;
137 this.line1 = builder.getLine1();
138 this.line2 = builder.getLine2();
139 this.line3 = builder.getLine3();
140 this.city = builder.getCity();
141 this.stateCode = builder.getStateCode();
142 this.postalCode = builder.getPostalCode();
143 this.countryCode = builder.getCountryCode();
144 this.line1Unmasked = builder.getLine1Unmasked();
145 this.line2Unmasked = builder.getLine2Unmasked();
146 this.line3Unmasked = builder.getLine3Unmasked();
147 this.cityUnmasked = builder.getCityUnmasked();
148 this.stateCodeUnmasked = builder.getStateCodeUnmasked();
149 this.postalCodeUnmasked = builder.getPostalCodeUnmasked();
150 this.countryCodeUnmasked = builder.getCountryCodeUnmasked();
151 this.suppressAddress = builder.isSuppressAddress();
152 this.defaultValue = builder.isDefaultValue();
153 this.versionNumber = builder.getVersionNumber();
154 this.objectId = builder.getObjectId();
155 this.active = builder.isActive();
156 this.id = builder.getId();
157 }
158
159 @Override
160 public String getEntityId() {
161 return this.entityId;
162 }
163
164 @Override
165 public String getEntityTypeCode() {
166 return this.entityTypeCode;
167 }
168
169 @Override
170 public Type getAddressType() {
171 return this.addressType;
172 }
173
174 @Override
175 public String getLine1() {
176 return this.line1;
177 }
178
179 @Override
180 public String getLine2() {
181 return this.line2;
182 }
183
184 @Override
185 public String getLine3() {
186 return this.line3;
187 }
188
189 @Override
190 public String getCity() {
191 return this.city;
192 }
193
194 @Override
195 public String getStateCode() {
196 return this.stateCode;
197 }
198
199 @Override
200 public String getPostalCode() {
201 return this.postalCode;
202 }
203
204 @Override
205 public String getCountryCode() {
206 return this.countryCode;
207 }
208
209 @Override
210 public String getLine1Unmasked() {
211 return this.line1Unmasked;
212 }
213
214 @Override
215 public String getLine2Unmasked() {
216 return this.line2Unmasked;
217 }
218
219 @Override
220 public String getLine3Unmasked() {
221 return this.line3Unmasked;
222 }
223
224 @Override
225 public String getCityUnmasked() {
226 return this.cityUnmasked;
227 }
228
229 @Override
230 public String getStateCodeUnmasked() {
231 return this.stateCodeUnmasked;
232 }
233
234 @Override
235 public String getPostalCodeUnmasked() {
236 return this.postalCodeUnmasked;
237 }
238
239 @Override
240 public String getCountryCodeUnmasked() {
241 return this.countryCodeUnmasked;
242 }
243
244 @Override
245 public boolean isSuppressAddress() {
246 return this.suppressAddress;
247 }
248
249 @Override
250 public boolean isDefaultValue() {
251 return this.defaultValue;
252 }
253
254 @Override
255 public Long getVersionNumber() {
256 return this.versionNumber;
257 }
258
259 @Override
260 public String getObjectId() {
261 return this.objectId;
262 }
263
264 @Override
265 public boolean isActive() {
266 return this.active;
267 }
268
269 @Override
270 public String getId() {
271 return this.id;
272 }
273
274
275
276
277
278 public final static class Builder
279 implements Serializable, ModelBuilder, EntityAddressContract
280 {
281
282 private String entityId;
283 private String entityTypeCode;
284 private Type.Builder addressType;
285 private String line1Unmasked;
286 private String line2Unmasked;
287 private String line3Unmasked;
288 private String cityUnmasked;
289 private String stateCodeUnmasked;
290 private String postalCodeUnmasked;
291 private String countryCodeUnmasked;
292 private boolean suppressAddress;
293 private boolean defaultValue;
294 private Long versionNumber;
295 private String objectId;
296 private boolean active;
297 private String id;
298
299 private Builder() {}
300
301 public static Builder create() {
302 return new Builder();
303 }
304
305 public static Builder create(EntityAddressContract contract) {
306 if (contract == null) {
307 throw new IllegalArgumentException("contract was null");
308 }
309 Builder builder = create();
310 builder.setEntityId(contract.getEntityId());
311 builder.setSuppressAddress(contract.isSuppressAddress());
312 builder.setEntityTypeCode(contract.getEntityTypeCode());
313 if (contract.getAddressType() != null) {
314 builder.setAddressType(Type.Builder.create(contract.getAddressType()));
315 }
316 builder.setLine1(contract.getLine1Unmasked());
317 builder.setLine2(contract.getLine2Unmasked());
318 builder.setLine3(contract.getLine3Unmasked());
319 builder.setCity(contract.getCityUnmasked());
320 builder.setStateCode(contract.getStateCodeUnmasked());
321 builder.setPostalCode(contract.getPostalCodeUnmasked());
322 builder.setCountryCode(contract.getCountryCodeUnmasked());
323 builder.setDefaultValue(contract.isDefaultValue());
324 builder.setVersionNumber(contract.getVersionNumber());
325 builder.setObjectId(contract.getObjectId());
326 builder.setActive(contract.isActive());
327 builder.setId(contract.getId());
328 return builder;
329 }
330
331 public EntityAddress build() {
332 return new EntityAddress(this);
333 }
334
335 @Override
336 public String getEntityId() {
337 return this.entityId;
338 }
339
340 @Override
341 public String getEntityTypeCode() {
342 return this.entityTypeCode;
343 }
344
345 @Override
346 public Type.Builder getAddressType() {
347 return this.addressType;
348 }
349
350 @Override
351 public String getLine1() {
352 if (isSuppressAddress()) {
353 return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
354 }
355 return this.line1Unmasked;
356
357 }
358
359 @Override
360 public String getLine2() {
361 if (isSuppressAddress()) {
362 return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
363 }
364 return this.line2Unmasked;
365 }
366
367 @Override
368 public String getLine3() {
369 if (isSuppressAddress()) {
370 return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
371 }
372 return this.line3Unmasked;
373 }
374
375 @Override
376 public String getCity() {
377 if (isSuppressAddress()) {
378 return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
379 }
380 return this.cityUnmasked;
381 }
382
383 @Override
384 public String getStateCode() {
385 if (isSuppressAddress()) {
386 return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE;
387 }
388 return this.stateCodeUnmasked;
389 }
390
391 @Override
392 public String getPostalCode() {
393 if (isSuppressAddress()) {
394 return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK_ZIP;
395 }
396 return this.postalCodeUnmasked;
397 }
398
399 @Override
400 public String getCountryCode() {
401 if (isSuppressAddress()) {
402 return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE;
403 }
404 return this.countryCodeUnmasked;
405 }
406
407 @Override
408 public String getLine1Unmasked() {
409 return this.line1Unmasked;
410 }
411
412 @Override
413 public String getLine2Unmasked() {
414 return this.line2Unmasked;
415 }
416
417 @Override
418 public String getLine3Unmasked() {
419 return this.line3Unmasked;
420 }
421
422 @Override
423 public String getCityUnmasked() {
424 return this.cityUnmasked;
425 }
426
427 @Override
428 public String getStateCodeUnmasked() {
429 return this.stateCodeUnmasked;
430 }
431
432 @Override
433 public String getPostalCodeUnmasked() {
434 return this.postalCodeUnmasked;
435 }
436
437 @Override
438 public String getCountryCodeUnmasked() {
439 return this.countryCodeUnmasked;
440 }
441
442 @Override
443 public boolean isSuppressAddress() {
444 return this.suppressAddress;
445 }
446
447 @Override
448 public boolean isDefaultValue() {
449 return this.defaultValue;
450 }
451
452 @Override
453 public Long getVersionNumber() {
454 return this.versionNumber;
455 }
456
457 @Override
458 public String getObjectId() {
459 return this.objectId;
460 }
461
462 @Override
463 public boolean isActive() {
464 return this.active;
465 }
466
467 @Override
468 public String getId() {
469 return this.id;
470 }
471
472 public void setEntityId(String entityId) {
473 this.entityId = entityId;
474 }
475
476 public void setEntityTypeCode(String entityTypeCode) {
477 this.entityTypeCode = entityTypeCode;
478 }
479
480 public void setAddressType(Type.Builder addressType) {
481 this.addressType = addressType;
482 }
483
484 public void setLine1(String line1) {
485 this.line1Unmasked = line1;
486 }
487
488 public void setLine2(String line2) {
489 this.line2Unmasked = line2;
490 }
491
492 public void setLine3(String line3) {
493 this.line3Unmasked = line3;
494 }
495
496 public void setCity(String city) {
497 this.cityUnmasked = city;
498 }
499
500 public void setStateCode(String stateCode) {
501 this.stateCodeUnmasked = stateCode;
502 }
503
504 public void setPostalCode(String postalCode) {
505 this.postalCodeUnmasked = postalCode;
506 }
507
508 public void setCountryCode(String countryCode) {
509 this.countryCodeUnmasked = countryCode;
510 }
511
512 private void setSuppressAddress(boolean suppressAddress) {
513 this.suppressAddress = suppressAddress;
514 }
515
516 public void setDefaultValue(boolean defaultValue) {
517 this.defaultValue = defaultValue;
518 }
519
520 public void setVersionNumber(Long versionNumber) {
521 this.versionNumber = versionNumber;
522 }
523
524 public void setObjectId(String objectId) {
525 this.objectId = objectId;
526 }
527
528 public void setActive(boolean active) {
529 this.active = active;
530 }
531
532 public void setId(String id) {
533 if (StringUtils.isWhitespace(id)) {
534 throw new IllegalArgumentException("id is blank");
535 }
536 this.id = id;
537 }
538
539 }
540
541
542
543
544
545
546 static class Constants {
547
548 final static String ROOT_ELEMENT_NAME = "entityAddress";
549 final static String TYPE_NAME = "EntityAddressType";
550 }
551
552
553
554
555
556
557 static class Elements {
558
559 final static String ENTITY_ID = "entityId";
560 final static String ENTITY_TYPE_CODE = "entityTypeCode";
561 final static String ADDRESS_TYPE = "addressType";
562 final static String LINE1 = "line1";
563 final static String LINE2 = "line2";
564 final static String LINE3 = "line3";
565 final static String CITY = "city";
566 final static String STATE_CODE = "stateCode";
567 final static String POSTAL_CODE = "postalCode";
568 final static String COUNTRY_CODE = "countryCode";
569 final static String LINE1_UNMASKED = "line1Unmasked";
570 final static String LINE2_UNMASKED = "line2Unmasked";
571 final static String LINE3_UNMASKED = "line3Unmasked";
572 final static String CITY_UNMASKED = "cityUnmasked";
573 final static String STATE_CODE_UNMASKED = "stateCodeUnmasked";
574 final static String POSTAL_CODE_UNMASKED = "postalCodeUnmasked";
575 final static String COUNTRY_CODE_UNMASKED = "countryCodeUnmasked";
576 final static String SUPPRESS_ADDRESS = "suppressAddress";
577 final static String DEFAULT_VALUE = "defaultValue";
578 final static String ACTIVE = "active";
579 final static String ID = "id";
580
581 }
582
583 }