001 /**
002 * Copyright 2005-2014 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 */
016 package org.kuali.rice.kim.api.identity.personal;
017
018 import java.io.Serializable;
019 import java.util.Collection;
020 import javax.xml.bind.annotation.XmlAccessType;
021 import javax.xml.bind.annotation.XmlAccessorType;
022 import javax.xml.bind.annotation.XmlAnyElement;
023 import javax.xml.bind.annotation.XmlElement;
024 import javax.xml.bind.annotation.XmlRootElement;
025 import javax.xml.bind.annotation.XmlType;
026
027 import org.apache.commons.lang.StringUtils;
028 import org.kuali.rice.core.api.CoreConstants;
029 import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
030 import org.kuali.rice.core.api.mo.ModelBuilder;
031 import org.kuali.rice.kim.api.KimApiConstants;
032 import org.w3c.dom.Element;
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 })
048 public 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.getEthnicityCode());
176 builder.setSubEthnicityCode(contract.getSubEthnicityCode());
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 public EntityEthnicity build() {
185 return new EntityEthnicity(this);
186 }
187
188 @Override
189 public String getEntityId() {
190 return this.entityId;
191 }
192
193 @Override
194 public String getEthnicityCode() {
195 if (isSuppressPersonal()) {
196 return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
197 }
198 return this.ethnicityCode;
199 }
200
201 @Override
202 public String getEthnicityCodeUnmasked() {
203 return this.ethnicityCode;
204 }
205
206 @Override
207 public String getSubEthnicityCode() {
208 if (isSuppressPersonal()) {
209 return KimApiConstants.RestrictedMasks.RESTRICTED_DATA_MASK;
210 }
211 return this.subEthnicityCode;
212 }
213
214 @Override
215 public String getSubEthnicityCodeUnmasked() {
216 return this.subEthnicityCode;
217 }
218
219 @Override
220 public boolean isSuppressPersonal() {
221 return this.suppressPersonal;
222 }
223
224 @Override
225 public Long getVersionNumber() {
226 return this.versionNumber;
227 }
228
229 @Override
230 public String getObjectId() {
231 return this.objectId;
232 }
233
234 @Override
235 public String getId() {
236 return this.id;
237 }
238
239 public void setEntityId(String entityId) {
240 // TODO add validation of input value if required and throw IllegalArgumentException if needed
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 }