001/**
002 * Copyright 2005-2015 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.kim.api.identity.address;
017
018import java.io.Serializable;
019import java.util.Collection;
020import javax.xml.bind.annotation.XmlAccessType;
021import javax.xml.bind.annotation.XmlAccessorType;
022import javax.xml.bind.annotation.XmlAnyElement;
023import javax.xml.bind.annotation.XmlElement;
024import javax.xml.bind.annotation.XmlRootElement;
025import javax.xml.bind.annotation.XmlType;
026import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
027
028import org.apache.commons.lang.StringUtils;
029import org.joda.time.DateTime;
030import org.kuali.rice.core.api.CoreConstants;
031import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
032import org.kuali.rice.core.api.mo.ModelBuilder;
033import org.kuali.rice.core.api.util.jaxb.DateTimeAdapter;
034import org.kuali.rice.kim.api.KimApiConstants;
035import org.kuali.rice.kim.api.identity.CodedAttribute;
036import org.w3c.dom.Element;
037
038@XmlRootElement(name = EntityAddress.Constants.ROOT_ELEMENT_NAME)
039@XmlAccessorType(XmlAccessType.NONE)
040@XmlType(name = EntityAddress.Constants.TYPE_NAME, propOrder = {
041    EntityAddress.Elements.ID,
042    EntityAddress.Elements.ENTITY_TYPE_CODE,
043    EntityAddress.Elements.ENTITY_ID,
044    EntityAddress.Elements.ADDRESS_TYPE,
045    EntityAddress.Elements.ATTENTION_LINE,
046    EntityAddress.Elements.LINE1,
047    EntityAddress.Elements.LINE2,
048    EntityAddress.Elements.LINE3,
049    EntityAddress.Elements.CITY,
050    EntityAddress.Elements.STATE_PROVINCE_CODE,
051    EntityAddress.Elements.POSTAL_CODE,
052    EntityAddress.Elements.COUNTRY_CODE,
053    EntityAddress.Elements.ATTENTION_LINE_UNMASKED,
054    EntityAddress.Elements.LINE1_UNMASKED,
055    EntityAddress.Elements.LINE2_UNMASKED,
056    EntityAddress.Elements.LINE3_UNMASKED,
057    EntityAddress.Elements.CITY_UNMASKED,
058    EntityAddress.Elements.STATE_PROVINCE_CODE_UNMASKED,
059    EntityAddress.Elements.POSTAL_CODE_UNMASKED,
060    EntityAddress.Elements.COUNTRY_CODE_UNMASKED,
061    EntityAddress.Elements.ADDRESS_FORMAT,
062    EntityAddress.Elements.MODIFIED_DATE,
063    EntityAddress.Elements.VALIDATED_DATE,
064    EntityAddress.Elements.VALIDATED,
065    EntityAddress.Elements.NOTE_MESSAGE,
066    EntityAddress.Elements.SUPPRESS_ADDRESS,
067    EntityAddress.Elements.DEFAULT_VALUE,
068    EntityAddress.Elements.ACTIVE,
069    CoreConstants.CommonElements.VERSION_NUMBER,
070    CoreConstants.CommonElements.OBJECT_ID,
071    CoreConstants.CommonElements.FUTURE_ELEMENTS
072})
073public final class EntityAddress extends AbstractDataTransferObject
074    implements EntityAddressContract
075{
076    @XmlElement(name = Elements.ID, required = false)
077    private final String id;
078    @XmlElement(name = Elements.ENTITY_TYPE_CODE, required = false)
079    private final String entityTypeCode;
080    @XmlElement(name = Elements.ENTITY_ID, required = false)
081    private final String entityId;
082    @XmlElement(name = Elements.ADDRESS_TYPE, required = false)
083    private final CodedAttribute addressType;
084    @XmlElement(name = Elements.ATTENTION_LINE, required = false)
085    private final String attentionLine;
086    @XmlElement(name = Elements.LINE1, required = false)
087    private final String line1;
088    @XmlElement(name = Elements.LINE2, required = false)
089    private final String line2;
090    @XmlElement(name = Elements.LINE3, required = false)
091    private final String line3;
092    @XmlElement(name = Elements.CITY, required = false)
093    private final String city;
094    @XmlElement(name = Elements.STATE_PROVINCE_CODE, required = false)
095    private final String stateProvinceCode;
096    @XmlElement(name = Elements.POSTAL_CODE, required = false)
097    private final String postalCode;
098    @XmlElement(name = Elements.COUNTRY_CODE, required = false)
099    private final String countryCode;
100    @XmlElement(name = Elements.ATTENTION_LINE_UNMASKED, required = false)
101    private final String attentionLineUnmasked;
102    @XmlElement(name = Elements.LINE1_UNMASKED, required = false)
103    private final String line1Unmasked;
104    @XmlElement(name = Elements.LINE2_UNMASKED, required = false)
105    private final String line2Unmasked;
106    @XmlElement(name = Elements.LINE3_UNMASKED, required = false)
107    private final String line3Unmasked;
108    @XmlElement(name = Elements.CITY_UNMASKED, required = false)
109    private final String cityUnmasked;
110    @XmlElement(name = Elements.STATE_PROVINCE_CODE_UNMASKED, required = false)
111    private final String stateProvinceCodeUnmasked;
112    @XmlElement(name = Elements.POSTAL_CODE_UNMASKED, required = false)
113    private final String postalCodeUnmasked;
114    @XmlElement(name = Elements.COUNTRY_CODE_UNMASKED, required = false)
115    private final String countryCodeUnmasked;
116    @XmlElement(name = Elements.ADDRESS_FORMAT, required = false)
117    private final String addressFormat;
118    @XmlElement(name = Elements.MODIFIED_DATE, required = false)
119    @XmlJavaTypeAdapter(DateTimeAdapter.class)
120    private final DateTime modifiedDate;
121    @XmlElement(name = Elements.VALIDATED_DATE, required = false)
122    @XmlJavaTypeAdapter(DateTimeAdapter.class)
123    private final DateTime validatedDate;
124    @XmlElement(name = Elements.VALIDATED, required = false)
125    private final boolean validated;
126    @XmlElement(name = Elements.NOTE_MESSAGE, required = false)
127    private final String noteMessage;
128    @XmlElement(name = Elements.SUPPRESS_ADDRESS, required = false)
129    private final boolean suppressAddress;
130    @XmlElement(name = Elements.DEFAULT_VALUE, required = false)
131    private final boolean defaultValue;
132    @XmlElement(name = Elements.ACTIVE, required = false)
133    private final boolean active;
134    @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
135    private final Long versionNumber;
136    @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
137    private final String objectId;
138    @SuppressWarnings("unused")
139    @XmlAnyElement
140    private final Collection<Element> _futureElements = null;
141
142    /**
143     * Private constructor used only by JAXB.
144     * 
145     */
146    private EntityAddress() {
147        this.entityId = null;
148        this.entityTypeCode = null;
149        this.addressType = null;
150        this.attentionLine = null;
151        this.line1 = null;
152        this.line2 = null;
153        this.line3 = null;
154        this.city = null;
155        this.stateProvinceCode = null;
156        this.postalCode = null;
157        this.countryCode = null;
158        this.attentionLineUnmasked = null;
159        this.line1Unmasked = null;
160        this.line2Unmasked = null;
161        this.line3Unmasked = null;
162        this.cityUnmasked = null;
163        this.stateProvinceCodeUnmasked = null;
164        this.postalCodeUnmasked = null;
165        this.countryCodeUnmasked = null;
166        this.addressFormat = null;
167        this.modifiedDate = null;
168        this.validatedDate = null;
169        this.validated = true; // assume it's valid?
170        this.noteMessage = null;
171        this.suppressAddress = false;
172        this.defaultValue = false;
173        this.versionNumber = null;
174        this.objectId = null;
175        this.active = false;
176        this.id = null;
177    }
178
179    private EntityAddress(Builder builder) {
180        this.entityId = builder.getEntityId();
181        this.entityTypeCode = builder.getEntityTypeCode();
182
183        this.addressType = (builder.getAddressType() != null) ? builder.getAddressType().build() : null;
184        this.attentionLine = builder.getAttentionLine();
185        this.line1 = builder.getLine1();
186        this.line2 = builder.getLine2();
187        this.line3 = builder.getLine3();
188        this.city = builder.getCity();
189        this.stateProvinceCode = builder.getStateProvinceCode();
190        this.postalCode = builder.getPostalCode();
191        this.countryCode = builder.getCountryCode();
192        this.attentionLineUnmasked = builder.getAttentionLineUnmasked();
193        this.line1Unmasked = builder.getLine1Unmasked();
194        this.line2Unmasked = builder.getLine2Unmasked();
195        this.line3Unmasked = builder.getLine3Unmasked();
196        this.cityUnmasked = builder.getCityUnmasked();
197        this.stateProvinceCodeUnmasked = builder.getStateProvinceCodeUnmasked();
198        this.postalCodeUnmasked = builder.getPostalCodeUnmasked();
199        this.countryCodeUnmasked = builder.getCountryCodeUnmasked();
200        this.addressFormat = builder.getAddressFormat();
201        this.modifiedDate = builder.getModifiedDate();
202        this.validatedDate = builder.getValidatedDate();
203        this.validated = builder.isValidated();
204        this.noteMessage = builder.getNoteMessage();
205        this.suppressAddress = builder.isSuppressAddress();
206        this.defaultValue = builder.isDefaultValue();
207        this.versionNumber = builder.getVersionNumber();
208        this.objectId = builder.getObjectId();
209        this.active = builder.isActive();
210        this.id = builder.getId();
211    }
212
213    @Override
214    public String getEntityId() {
215        return this.entityId;
216    }
217
218    @Override
219    public String getEntityTypeCode() {
220        return this.entityTypeCode;
221    }
222
223    @Override
224    public CodedAttribute getAddressType() {
225        return this.addressType;
226    }
227
228    @Override
229    public String getAttentionLine() {
230        return this.attentionLine;
231    }
232
233    @Override
234    public String getLine1() {
235        return this.line1;
236    }
237
238    @Override
239    public String getLine2() {
240        return this.line2;
241    }
242
243    @Override
244    public String getLine3() {
245        return this.line3;
246    }
247
248    @Override
249    public String getCity() {
250        return this.city;
251    }
252
253    @Override
254    public String getStateProvinceCode() {
255        return this.stateProvinceCode;
256    }
257
258    @Override
259    public String getPostalCode() {
260        return this.postalCode;
261    }
262
263    @Override
264    public String getCountryCode() {
265        return this.countryCode;
266    }
267
268    @Override
269    public String getAttentionLineUnmasked() {
270        return this.attentionLineUnmasked;
271    }
272
273    @Override
274    public String getLine1Unmasked() {
275        return this.line1Unmasked;
276    }
277
278    @Override
279    public String getLine2Unmasked() {
280        return this.line2Unmasked;
281    }
282
283    @Override
284    public String getLine3Unmasked() {
285        return this.line3Unmasked;
286    }
287
288    @Override
289    public String getCityUnmasked() {
290        return this.cityUnmasked;
291    }
292
293    @Override
294    public String getStateProvinceCodeUnmasked() {
295        return this.stateProvinceCodeUnmasked;
296    }
297
298    @Override
299    public String getPostalCodeUnmasked() {
300        return this.postalCodeUnmasked;
301    }
302
303    @Override
304    public String getCountryCodeUnmasked() {
305        return this.countryCodeUnmasked;
306    }
307
308    @Override
309    public String getAddressFormat() {
310        return this.addressFormat;
311    }
312
313    @Override
314    public DateTime getModifiedDate() {
315        return modifiedDate;
316    }
317
318    @Override
319    public DateTime getValidatedDate() {
320        return validatedDate;
321    }
322
323    @Override
324    public boolean isValidated() {
325        return validated;
326    }
327
328    @Override
329    public String getNoteMessage() {
330        return noteMessage;
331    }
332
333    @Override
334    public boolean isSuppressAddress() {
335        return this.suppressAddress;
336    }
337
338    @Override
339    public boolean isDefaultValue() {
340        return this.defaultValue;
341    }
342
343    @Override
344    public Long getVersionNumber() {
345        return this.versionNumber;
346    }
347
348    @Override
349    public String getObjectId() {
350        return this.objectId;
351    }
352
353    @Override
354    public boolean isActive() {
355        return this.active;
356    }
357
358    @Override
359    public String getId() {
360        return this.id;
361    }
362
363    /**
364     * A builder which can be used to construct {@link EntityAddress} instances.  Enforces the constraints of the {@link EntityAddressContract}.
365     * 
366     */
367    public final static class Builder
368        implements Serializable, ModelBuilder, EntityAddressContract
369    {
370
371        private String entityId;
372        private String entityTypeCode;
373        private CodedAttribute.Builder addressType;
374        private String attentionLineUnmasked;
375        private String line1Unmasked;
376        private String line2Unmasked;
377        private String line3Unmasked;
378        private String cityUnmasked;
379        private String stateProvinceCodeUnmasked;
380        private String postalCodeUnmasked;
381        private String countryCodeUnmasked;
382        private String addressFormat;
383        private DateTime modifiedDate;
384        private DateTime validatedDate;
385        private boolean validated;
386        private String noteMessage;
387        private boolean suppressAddress;
388        private boolean defaultValue;
389        private Long versionNumber;
390        private String objectId;
391        private boolean active;
392        private String id;
393
394        private Builder() {}
395
396        public static Builder create() {
397            return new Builder();
398        }
399
400        public static Builder create(EntityAddressContract contract) {
401            if (contract == null) {
402                throw new IllegalArgumentException("contract was null");
403            }
404            Builder builder = create();
405            builder.setEntityId(contract.getEntityId());
406            builder.setSuppressAddress(contract.isSuppressAddress());
407            builder.setEntityTypeCode(contract.getEntityTypeCode());
408            if (contract.getAddressType() != null) {
409                builder.setAddressType(CodedAttribute.Builder.create(contract.getAddressType()));
410            }
411            builder.setAttentionLine(contract.getAttentionLineUnmasked());
412            builder.setLine1(contract.getLine1Unmasked());
413            builder.setLine2(contract.getLine2Unmasked());
414            builder.setLine3(contract.getLine3Unmasked());
415            builder.setCity(contract.getCityUnmasked());
416            builder.setStateProvinceCode(contract.getStateProvinceCodeUnmasked());
417            builder.setPostalCode(contract.getPostalCodeUnmasked());
418            builder.setCountryCode(contract.getCountryCodeUnmasked());
419            builder.setAddressFormat(contract.getAddressFormat());
420            builder.setModifiedDate(contract.getModifiedDate());
421            builder.setValidatedDate(contract.getValidatedDate());
422            builder.setValidated(contract.isValidated());
423            builder.setNoteMessage(contract.getNoteMessage());
424            builder.setDefaultValue(contract.isDefaultValue());
425            builder.setVersionNumber(contract.getVersionNumber());
426            builder.setObjectId(contract.getObjectId());
427            builder.setActive(contract.isActive());
428            builder.setId(contract.getId());
429            return builder;
430        }
431
432        public EntityAddress build() {
433            return new EntityAddress(this);
434        }
435
436        @Override
437        public String getEntityId() {
438            return this.entityId;
439        }
440
441        @Override
442        public String getEntityTypeCode() {
443            return this.entityTypeCode;
444        }
445
446        @Override
447        public CodedAttribute.Builder getAddressType() {
448            return this.addressType;
449        }
450
451        @Override
452        public String getAttentionLine() {
453            if (isSuppressAddress()) {
454                return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
455            }
456            return this.attentionLineUnmasked;
457
458        }
459
460        @Override
461        public String getLine1() {
462            if (isSuppressAddress()) {
463                return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
464            }
465            return this.line1Unmasked;
466
467        }
468
469        @Override
470        public String getLine2() {
471            if (isSuppressAddress()) {
472                return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
473            }
474            return this.line2Unmasked;
475        }
476
477        @Override
478        public String getLine3() {
479            if (isSuppressAddress()) {
480                return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
481            }
482            return this.line3Unmasked;
483        }
484
485        @Override
486        public String getCity() {
487            if (isSuppressAddress()) {
488                return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
489            }
490            return this.cityUnmasked;
491        }
492
493        @Override
494        public String getStateProvinceCode() {
495            if (isSuppressAddress()) {
496                return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE;
497            }
498            return this.stateProvinceCodeUnmasked;
499        }
500
501        @Override
502        public String getPostalCode() {
503            if (isSuppressAddress()) {
504                return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK_ZIP;
505            }
506            return this.postalCodeUnmasked;
507        }
508
509        @Override
510        public String getCountryCode() {
511            if (isSuppressAddress()) {
512                return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK_CODE;
513            }
514            return this.countryCodeUnmasked;
515        }
516
517        @Override
518        public String getAttentionLineUnmasked() {
519            return this.attentionLineUnmasked;
520        }
521
522        @Override
523        public String getLine1Unmasked() {
524            return this.line1Unmasked;
525        }
526
527        @Override
528        public String getLine2Unmasked() {
529            return this.line2Unmasked;
530        }
531
532        @Override
533        public String getLine3Unmasked() {
534            return this.line3Unmasked;
535        }
536
537        @Override
538        public String getCityUnmasked() {
539            return this.cityUnmasked;
540        }
541
542        @Override
543        public String getStateProvinceCodeUnmasked() {
544            return this.stateProvinceCodeUnmasked;
545        }
546
547        @Override
548        public String getPostalCodeUnmasked() {
549            return this.postalCodeUnmasked;
550        }
551
552        @Override
553        public String getCountryCodeUnmasked() {
554            return this.countryCodeUnmasked;
555        }
556
557        @Override
558        public String getAddressFormat() {
559            return this.addressFormat;
560        }
561
562        @Override
563        public DateTime getModifiedDate() {
564            return modifiedDate;
565        }
566
567        @Override
568        public DateTime getValidatedDate() {
569            return validatedDate;
570        }
571
572        @Override
573        public boolean isValidated() {
574            return validated;
575        }
576
577        @Override
578        public String getNoteMessage() {
579            return noteMessage;
580        }
581
582        @Override
583        public boolean isSuppressAddress() {
584            return this.suppressAddress;
585        }
586
587        @Override
588        public boolean isDefaultValue() {
589            return this.defaultValue;
590        }
591
592        @Override
593        public Long getVersionNumber() {
594            return this.versionNumber;
595        }
596
597        @Override
598        public String getObjectId() {
599            return this.objectId;
600        }
601
602        @Override
603        public boolean isActive() {
604            return this.active;
605        }
606
607        @Override
608        public String getId() {
609            return this.id;
610        }
611
612        public void setEntityId(String entityId) {
613            this.entityId = entityId;
614        }
615
616        public void setEntityTypeCode(String entityTypeCode) {
617            this.entityTypeCode = entityTypeCode;
618        }
619
620        public void setAddressType(CodedAttribute.Builder addressType) {
621            this.addressType = addressType;
622        }
623
624        public void setAttentionLine(String attnLine) {
625            this.attentionLineUnmasked = attnLine;
626        }
627
628        public void setLine1(String line1) {
629            this.line1Unmasked = line1;
630        }
631
632        public void setLine2(String line2) {
633            this.line2Unmasked = line2;
634        }
635
636        public void setLine3(String line3) {
637            this.line3Unmasked = line3;
638        }
639
640        public void setCity(String city) {
641            this.cityUnmasked = city;
642        }
643
644        public void setStateProvinceCode(String stateProvinceCode) {
645            this.stateProvinceCodeUnmasked = stateProvinceCode;
646        }
647
648        public void setPostalCode(String postalCode) {
649            this.postalCodeUnmasked = postalCode;
650        }
651
652        public void setCountryCode(String countryCode) {
653            this.countryCodeUnmasked = countryCode;
654        }
655
656        public void setAddressFormat(String addressFormat) {
657            this.addressFormat = addressFormat;
658        }
659
660        public void setModifiedDate(DateTime modifiedDate) {
661            this.modifiedDate = modifiedDate;
662        }
663
664        public void setValidatedDate(DateTime validatedDate) {
665            this.validatedDate = validatedDate;
666        }
667
668        public void setValidated(boolean validated) {
669            this.validated = validated;
670        }
671
672        public void setNoteMessage(String noteMessage) {
673            this.noteMessage = noteMessage;
674        }
675
676        private void setSuppressAddress(boolean suppressAddress) {
677            this.suppressAddress = suppressAddress;
678        }
679
680        public void setDefaultValue(boolean defaultValue) {
681            this.defaultValue = defaultValue;
682        }
683
684        public void setVersionNumber(Long versionNumber) {
685            this.versionNumber = versionNumber;
686        }
687
688        public void setObjectId(String objectId) {
689            this.objectId = objectId;
690        }
691
692        public void setActive(boolean active) {
693            this.active = active;
694        }
695
696        public void setId(String id) {
697            if (StringUtils.isWhitespace(id)) {
698                throw new IllegalArgumentException("id is blank");
699            }
700            this.id = id;
701        }
702
703    }
704
705
706    /**
707     * Defines some internal constants used on this class.
708     * 
709     */
710    static class Constants {
711
712        final static String ROOT_ELEMENT_NAME = "entityAddress";
713        final static String TYPE_NAME = "EntityAddressType";
714    }
715
716
717    /**
718     * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
719     * 
720     */
721    static class Elements {
722
723        final static String ENTITY_ID = "entityId";
724        final static String ENTITY_TYPE_CODE = "entityTypeCode";
725        final static String ADDRESS_TYPE = "addressType";
726        final static String ATTENTION_LINE = "attentionLine";
727        final static String LINE1 = "line1";
728        final static String LINE2 = "line2";
729        final static String LINE3 = "line3";
730        final static String CITY = "city";
731        final static String STATE_PROVINCE_CODE = "stateProvinceCode";
732        final static String POSTAL_CODE = "postalCode";
733        final static String COUNTRY_CODE = "countryCode";
734        final static String ATTENTION_LINE_UNMASKED = "attentionLineUnmasked";
735        final static String LINE1_UNMASKED = "line1Unmasked";
736        final static String LINE2_UNMASKED = "line2Unmasked";
737        final static String LINE3_UNMASKED = "line3Unmasked";
738        final static String CITY_UNMASKED = "cityUnmasked";
739        final static String STATE_PROVINCE_CODE_UNMASKED = "stateProvinceCodeUnmasked";
740        final static String POSTAL_CODE_UNMASKED = "postalCodeUnmasked";
741        final static String COUNTRY_CODE_UNMASKED = "countryCodeUnmasked";
742        final static String ADDRESS_FORMAT= "addressFormat";
743        final static String MODIFIED_DATE = "modifiedDate";
744        final static String VALIDATED_DATE = "validatedDate";
745        final static String VALIDATED = "validated";
746        final static String NOTE_MESSAGE = "noteMessage";
747        final static String SUPPRESS_ADDRESS = "suppressAddress";
748        final static String DEFAULT_VALUE = "defaultValue";
749        final static String ACTIVE = "active";
750        final static String ID = "id";
751
752    }
753
754}