View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kim.api.identity.personal;
17  
18  import java.io.Serializable;
19  import java.util.Collection;
20  import javax.xml.bind.annotation.XmlAccessType;
21  import javax.xml.bind.annotation.XmlAccessorType;
22  import javax.xml.bind.annotation.XmlAnyElement;
23  import javax.xml.bind.annotation.XmlElement;
24  import javax.xml.bind.annotation.XmlRootElement;
25  import javax.xml.bind.annotation.XmlType;
26  
27  import org.apache.commons.lang.StringUtils;
28  import org.kuali.rice.core.api.CoreConstants;
29  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
30  import org.kuali.rice.core.api.mo.ModelBuilder;
31  import org.kuali.rice.kim.api.KimApiConstants;
32  import org.w3c.dom.Element;
33  
34  @XmlRootElement(name = EntityEthnicity.Constants.ROOT_ELEMENT_NAME)
35  @XmlAccessorType(XmlAccessType.NONE)
36  @XmlType(name = EntityEthnicity.Constants.TYPE_NAME, propOrder = {
37      EntityEthnicity.Elements.ID,
38      EntityEthnicity.Elements.ENTITY_ID,
39      EntityEthnicity.Elements.ETHNICITY_CODE,
40      EntityEthnicity.Elements.ETHNICITY_CODE_UNMASKED,
41      EntityEthnicity.Elements.SUB_ETHNICITY_CODE,
42      EntityEthnicity.Elements.SUB_ETHNICITY_CODE_UNMASKED,
43      EntityEthnicity.Elements.SUPPRESS_PERSONAL,
44      CoreConstants.CommonElements.VERSION_NUMBER,
45      CoreConstants.CommonElements.OBJECT_ID,
46      CoreConstants.CommonElements.FUTURE_ELEMENTS
47  })
48  public final class EntityEthnicity extends AbstractDataTransferObject
49      implements EntityEthnicityContract
50  {
51  
52      @XmlElement(name = Elements.ENTITY_ID, required = false)
53      private final String entityId;
54      @XmlElement(name = Elements.ETHNICITY_CODE, required = false)
55      private final String ethnicityCode;
56      @XmlElement(name = Elements.ETHNICITY_CODE_UNMASKED, required = false)
57      private final String ethnicityCodeUnmasked;
58      @XmlElement(name = Elements.SUB_ETHNICITY_CODE, required = false)
59      private final String subEthnicityCode;
60      @XmlElement(name = Elements.SUB_ETHNICITY_CODE_UNMASKED, required = false)
61      private final String subEthnicityCodeUnmasked;
62      @XmlElement(name = Elements.SUPPRESS_PERSONAL, required = false)
63      private final boolean suppressPersonal;
64      @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
65      private final Long versionNumber;
66      @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
67      private final String objectId;
68      @XmlElement(name = Elements.ID, required = false)
69      private final String id;
70      @SuppressWarnings("unused")
71      @XmlAnyElement
72      private final Collection<Element> _futureElements = null;
73  
74      /**
75       * Private constructor used only by JAXB.
76       * 
77       */
78      private EntityEthnicity() {
79          this.entityId = null;
80          this.ethnicityCode = null;
81          this.ethnicityCodeUnmasked = null;
82          this.subEthnicityCode = null;
83          this.subEthnicityCodeUnmasked = null;
84          this.suppressPersonal = false;
85          this.versionNumber = null;
86          this.objectId = null;
87          this.id = null;
88      }
89  
90      private EntityEthnicity(Builder builder) {
91          this.entityId = builder.getEntityId();
92          this.ethnicityCode = builder.getEthnicityCode();
93          this.ethnicityCodeUnmasked = builder.getEthnicityCodeUnmasked();
94          this.subEthnicityCode = builder.getSubEthnicityCode();
95          this.subEthnicityCodeUnmasked = builder.getSubEthnicityCodeUnmasked();
96          this.suppressPersonal = builder.isSuppressPersonal();
97          this.versionNumber = builder.getVersionNumber();
98          this.objectId = builder.getObjectId();
99          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 }