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.personal;
017
018import org.apache.commons.lang.StringUtils;
019import org.kuali.rice.core.api.CoreConstants;
020import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
021import org.kuali.rice.core.api.mo.ModelBuilder;
022import org.kuali.rice.kim.api.KimApiConstants;
023import org.w3c.dom.Element;
024
025import javax.xml.bind.annotation.XmlAccessType;
026import javax.xml.bind.annotation.XmlAccessorType;
027import javax.xml.bind.annotation.XmlAnyElement;
028import javax.xml.bind.annotation.XmlElement;
029import javax.xml.bind.annotation.XmlRootElement;
030import javax.xml.bind.annotation.XmlType;
031import java.io.Serializable;
032import java.util.Collection;
033
034@XmlRootElement(name = EntityEthnicity.Constants.ROOT_ELEMENT_NAME)
035@XmlAccessorType(XmlAccessType.NONE)
036@XmlType(name = EntityEthnicity.Constants.TYPE_NAME, propOrder = {
037    EntityEthnicity.Elements.ID,
038    EntityEthnicity.Elements.ENTITY_ID,
039    EntityEthnicity.Elements.ETHNICITY_CODE,
040    EntityEthnicity.Elements.ETHNICITY_CODE_UNMASKED,
041    EntityEthnicity.Elements.SUB_ETHNICITY_CODE,
042    EntityEthnicity.Elements.SUB_ETHNICITY_CODE_UNMASKED,
043    EntityEthnicity.Elements.SUPPRESS_PERSONAL,
044    CoreConstants.CommonElements.VERSION_NUMBER,
045    CoreConstants.CommonElements.OBJECT_ID,
046    CoreConstants.CommonElements.FUTURE_ELEMENTS
047})
048public final class EntityEthnicity extends AbstractDataTransferObject
049    implements EntityEthnicityContract
050{
051
052    @XmlElement(name = Elements.ENTITY_ID, required = false)
053    private final String entityId;
054    @XmlElement(name = Elements.ETHNICITY_CODE, required = false)
055    private final String ethnicityCode;
056    @XmlElement(name = Elements.ETHNICITY_CODE_UNMASKED, required = false)
057    private final String ethnicityCodeUnmasked;
058    @XmlElement(name = Elements.SUB_ETHNICITY_CODE, required = false)
059    private final String subEthnicityCode;
060    @XmlElement(name = Elements.SUB_ETHNICITY_CODE_UNMASKED, required = false)
061    private final String subEthnicityCodeUnmasked;
062    @XmlElement(name = Elements.SUPPRESS_PERSONAL, required = false)
063    private final boolean suppressPersonal;
064    @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
065    private final Long versionNumber;
066    @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
067    private final String objectId;
068    @XmlElement(name = Elements.ID, required = false)
069    private final String id;
070    @SuppressWarnings("unused")
071    @XmlAnyElement
072    private final Collection<Element> _futureElements = null;
073
074    /**
075     * Private constructor used only by JAXB.
076     * 
077     */
078    private EntityEthnicity() {
079        this.entityId = null;
080        this.ethnicityCode = null;
081        this.ethnicityCodeUnmasked = null;
082        this.subEthnicityCode = null;
083        this.subEthnicityCodeUnmasked = null;
084        this.suppressPersonal = false;
085        this.versionNumber = null;
086        this.objectId = null;
087        this.id = null;
088    }
089
090    private EntityEthnicity(Builder builder) {
091        this.entityId = builder.getEntityId();
092        this.ethnicityCode = builder.getEthnicityCode();
093        this.ethnicityCodeUnmasked = builder.getEthnicityCodeUnmasked();
094        this.subEthnicityCode = builder.getSubEthnicityCode();
095        this.subEthnicityCodeUnmasked = builder.getSubEthnicityCodeUnmasked();
096        this.suppressPersonal = builder.isSuppressPersonal();
097        this.versionNumber = builder.getVersionNumber();
098        this.objectId = builder.getObjectId();
099        this.id = builder.getId();
100    }
101
102    @Override
103    public String getEntityId() {
104        return this.entityId;
105    }
106
107    @Override
108    public String getEthnicityCode() {
109        return this.ethnicityCode;
110    }
111
112    @Override
113    public String getEthnicityCodeUnmasked() {
114        return this.ethnicityCodeUnmasked;
115    }
116
117    @Override
118    public String getSubEthnicityCode() {
119        return this.subEthnicityCode;
120    }
121
122    @Override
123    public String getSubEthnicityCodeUnmasked() {
124        return this.subEthnicityCodeUnmasked;
125    }
126
127    @Override
128    public boolean isSuppressPersonal() {
129        return this.suppressPersonal;
130    }
131
132    @Override
133    public Long getVersionNumber() {
134        return this.versionNumber;
135    }
136
137    @Override
138    public String getObjectId() {
139        return this.objectId;
140    }
141
142    @Override
143    public String getId() {
144        return this.id;
145    }
146
147    /**
148     * A builder which can be used to construct {@link EntityEthnicity} instances.  Enforces the constraints of the {@link EntityEthnicityContract}.
149     * 
150     */
151    public final static class Builder
152        implements Serializable, ModelBuilder, EntityEthnicityContract
153    {
154
155        private String entityId;
156        private String ethnicityCode;
157        private String subEthnicityCode;
158        private boolean suppressPersonal;
159        private Long versionNumber;
160        private String objectId;
161        private String id;
162
163        private Builder() { }
164
165        public static Builder create() {
166            return new Builder();
167        }
168
169        public static Builder create(EntityEthnicityContract contract) {
170            if (contract == null) {
171                throw new IllegalArgumentException("contract was null");
172            }
173            Builder builder = create();
174            builder.setEntityId(contract.getEntityId());
175            builder.setEthnicityCode(contract.getEthnicityCodeUnmasked());
176            builder.setSubEthnicityCode(contract.getSubEthnicityCodeUnmasked());
177            builder.setSuppressPersonal(contract.isSuppressPersonal());
178            builder.setVersionNumber(contract.getVersionNumber());
179            builder.setObjectId(contract.getObjectId());
180            builder.setId(contract.getId());
181            return builder;
182        }
183
184        @Override
185        public EntityEthnicity build() {
186            return new EntityEthnicity(this);
187        }
188
189        @Override
190        public String getEntityId() {
191            return this.entityId;
192        }
193
194        @Override
195        public String getEthnicityCode() {
196            if (isSuppressPersonal()) {
197                return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
198            }
199            return this.ethnicityCode;
200        }
201
202        @Override
203        public String getEthnicityCodeUnmasked() {
204            return this.ethnicityCode;
205        }
206
207        @Override
208        public String getSubEthnicityCode() {
209            if (isSuppressPersonal()) {
210                return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
211            }
212            return this.subEthnicityCode;
213        }
214
215        @Override
216        public String getSubEthnicityCodeUnmasked() {
217            return this.subEthnicityCode;
218        }
219
220        @Override
221        public boolean isSuppressPersonal() {
222            return this.suppressPersonal;
223        }
224
225        @Override
226        public Long getVersionNumber() {
227            return this.versionNumber;
228        }
229
230        @Override
231        public String getObjectId() {
232            return this.objectId;
233        }
234
235        @Override
236        public String getId() {
237            return this.id;
238        }
239
240        public void setEntityId(String entityId) {
241            this.entityId = entityId;
242        }
243
244        public void setEthnicityCode(String ethnicityCode) {
245            this.ethnicityCode = ethnicityCode;
246        }
247
248        public void setSubEthnicityCode(String subEthnicityCode) {
249            this.subEthnicityCode = subEthnicityCode;
250        }
251
252        private void setSuppressPersonal(boolean suppressPersonal) {
253            this.suppressPersonal = suppressPersonal;
254        }
255
256        public void setVersionNumber(Long versionNumber) {
257            this.versionNumber = versionNumber;
258        }
259
260        public void setObjectId(String objectId) {
261            this.objectId = objectId;
262        }
263
264        public void setId(String id) {
265            if (StringUtils.isWhitespace(id)) {
266                throw new IllegalArgumentException("id is blank");
267            }
268            this.id = id;
269        }
270
271    }
272
273
274    /**
275     * Defines some internal constants used on this class.
276     * 
277     */
278    static class Constants {
279
280        final static String ROOT_ELEMENT_NAME = "entityEthnicity";
281        final static String TYPE_NAME = "EntityEthnicityType";
282    }
283
284
285    /**
286     * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
287     * 
288     */
289    static class Elements {
290
291        final static String ENTITY_ID = "entityId";
292        final static String ETHNICITY_CODE = "ethnicityCode";
293        final static String ETHNICITY_CODE_UNMASKED = "ethnicityCodeUnmasked";
294        final static String SUB_ETHNICITY_CODE = "subEthnicityCode";
295        final static String SUB_ETHNICITY_CODE_UNMASKED = "subEthnicityCodeUnmasked";
296        final static String SUPPRESS_PERSONAL = "suppressPersonal";
297        final static String ID = "id";
298
299    }
300
301}