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.citizenship;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.joda.time.DateTime;
20  import org.kuali.rice.core.api.CoreConstants;
21  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
22  import org.kuali.rice.core.api.mo.ModelBuilder;
23  import org.kuali.rice.core.api.util.jaxb.DateTimeAdapter;
24  import org.kuali.rice.kim.api.identity.CodedAttribute;
25  import org.w3c.dom.Element;
26  
27  import javax.xml.bind.annotation.XmlAccessType;
28  import javax.xml.bind.annotation.XmlAccessorType;
29  import javax.xml.bind.annotation.XmlAnyElement;
30  import javax.xml.bind.annotation.XmlElement;
31  import javax.xml.bind.annotation.XmlRootElement;
32  import javax.xml.bind.annotation.XmlType;
33  import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
34  import java.io.Serializable;
35  import java.util.Collection;
36  
37  @XmlRootElement(name = EntityCitizenship.Constants.ROOT_ELEMENT_NAME)
38  @XmlAccessorType(XmlAccessType.NONE)
39  @XmlType(name = EntityCitizenship.Constants.TYPE_NAME, propOrder = {
40      EntityCitizenship.Elements.ID,
41      EntityCitizenship.Elements.ENTITY_ID,
42      EntityCitizenship.Elements.STATUS,
43      EntityCitizenship.Elements.COUNTRY_CODE,
44      EntityCitizenship.Elements.START_DATE,
45      EntityCitizenship.Elements.END_DATE,
46      CoreConstants.CommonElements.VERSION_NUMBER,
47      CoreConstants.CommonElements.OBJECT_ID,
48      EntityCitizenship.Elements.ACTIVE,
49      EntityCitizenship.Elements.CHANGE_DATE,
50      EntityCitizenship.Elements.CHANGE_TYPE,
51      CoreConstants.CommonElements.FUTURE_ELEMENTS
52  })
53  public final class EntityCitizenship extends AbstractDataTransferObject
54      implements EntityCitizenshipContract
55  {
56      @XmlElement(name = Elements.ID, required = false)
57      private final String id;
58      @XmlElement(name = Elements.ENTITY_ID, required = false)
59      private final String entityId;
60      @XmlElement(name = Elements.STATUS, required = false)
61      private final CodedAttribute status;
62      @XmlElement(name = Elements.COUNTRY_CODE, required = false)
63      private final String countryCode;
64      @XmlJavaTypeAdapter(DateTimeAdapter.class)
65      @XmlElement(name = Elements.START_DATE, required = false)
66      private final DateTime startDate;
67      @XmlJavaTypeAdapter(DateTimeAdapter.class)
68      @XmlElement(name = Elements.END_DATE, required = false)
69      private final DateTime endDate;
70      @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
71      private final Long versionNumber;
72      @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
73      private final String objectId;
74      @XmlElement(name = Elements.ACTIVE, required = false)
75      private final boolean active;
76      @XmlJavaTypeAdapter(DateTimeAdapter.class)
77      @XmlElement(name = Elements.CHANGE_DATE, required = false)
78      private final DateTime changeDate;
79      @XmlElement(name = Elements.CHANGE_TYPE, required = false)
80      private final CodedAttribute changeType;
81      @SuppressWarnings("unused")
82      @XmlAnyElement
83      private final Collection<Element> _futureElements = null;
84  
85      /**
86       * Private constructor used only by JAXB.
87       * 
88       */
89      private EntityCitizenship() {
90          this.status = null;
91          this.countryCode = null;
92          this.startDate = null;
93          this.endDate = null;
94          this.versionNumber = null;
95          this.objectId = null;
96          this.active = false;
97          this.id = null;
98          this.entityId = null;
99          this.changeDate = null;
100         this.changeType = null;
101     }
102 
103     private EntityCitizenship(Builder builder) {
104         this.status = builder.getStatus() != null ? builder.getStatus().build() : null;
105         this.countryCode = builder.getCountryCode();
106         this.startDate = builder.getStartDate();
107         this.endDate = builder.getEndDate();
108         this.versionNumber = builder.getVersionNumber();
109         this.objectId = builder.getObjectId();
110         this.active = builder.isActive();
111         this.id = builder.getId();
112         this.entityId = builder.getEntityId();
113         this.changeDate = builder.getChangeDate();
114         this.changeType = builder.getChangeType() != null ? builder.getChangeType().build() : null;
115     }
116 
117     @Override
118     public String getEntityId() {
119         return this.entityId;
120     }
121 
122     @Override
123     public CodedAttribute getStatus() {
124         return this.status;
125     }
126 
127     @Override
128     public String getCountryCode() {
129         return this.countryCode;
130     }
131 
132     @Override
133     public DateTime getStartDate() {
134         return this.startDate;
135     }
136 
137     @Override
138     public DateTime getEndDate() {
139         return this.endDate;
140     }
141 
142     @Override
143     public Long getVersionNumber() {
144         return this.versionNumber;
145     }
146 
147     @Override
148     public String getObjectId() {
149         return this.objectId;
150     }
151 
152     @Override
153     public boolean isActive() {
154         return this.active;
155     }
156 
157     @Override
158     public String getId() {
159         return this.id;
160     }
161 
162     @Override
163     public DateTime getChangeDate() {
164         return this.changeDate;
165     }
166 
167     @Override
168     public CodedAttribute getChangeType() {
169         return this.changeType;
170     }
171 
172     /**
173      * A builder which can be used to construct {@link EntityCitizenship} instances.  Enforces the constraints of the {@link EntityCitizenshipContract}.
174      * 
175      */
176     public final static class Builder
177         implements Serializable, ModelBuilder, EntityCitizenshipContract
178     {
179         private String entityId;
180         private CodedAttribute.Builder status;
181         private String countryCode;
182         private DateTime startDate;
183         private DateTime endDate;
184         private Long versionNumber;
185         private String objectId;
186         private boolean active;
187         private String id;
188         private DateTime changeDate;
189         private CodedAttribute.Builder changeType;
190 
191         private Builder() {
192         }
193 
194         public static Builder create() {
195             return new Builder();
196         }
197 
198         public static Builder create(EntityCitizenshipContract contract) {
199             if (contract == null) {
200                 throw new IllegalArgumentException("contract was null");
201             }
202             Builder builder = create();
203             builder.setEntityId(contract.getEntityId());
204             if (contract.getStatus() != null) {
205                 builder.setStatus(CodedAttribute.Builder.create(contract.getStatus()));
206             }
207             builder.setCountryCode(contract.getCountryCode());
208             builder.setStartDate(contract.getStartDate());
209             builder.setEndDate(contract.getEndDate());
210             builder.setVersionNumber(contract.getVersionNumber());
211             builder.setObjectId(contract.getObjectId());
212             builder.setActive(contract.isActive());
213             builder.setId(contract.getId());
214             builder.setChangeDate(contract.getChangeDate());
215             builder.setChangeType(contract.getChangeType() != null ? CodedAttribute.Builder.create(contract.getChangeType()) : null);
216             return builder;
217         }
218 
219         public EntityCitizenship build() {
220             return new EntityCitizenship(this);
221         }
222 
223         @Override
224         public String getEntityId() {
225             return this.entityId;
226         }
227 
228         @Override
229         public CodedAttribute.Builder getStatus() {
230             return this.status;
231         }
232 
233         @Override
234         public String getCountryCode() {
235             return this.countryCode;
236         }
237 
238         @Override
239         public DateTime getStartDate() {
240             return this.startDate;
241         }
242 
243         @Override
244         public DateTime getEndDate() {
245             return this.endDate;
246         }
247 
248         @Override
249         public Long getVersionNumber() {
250             return this.versionNumber;
251         }
252 
253         @Override
254         public String getObjectId() {
255             return this.objectId;
256         }
257 
258         @Override
259         public boolean isActive() {
260             return this.active;
261         }
262 
263         @Override
264         public String getId() {
265             return this.id;
266         }
267 
268         @Override
269         public DateTime getChangeDate() {
270             return this.changeDate;
271         }
272 
273         @Override
274         public CodedAttribute.Builder getChangeType() {
275             return this.changeType;
276         }
277 
278         public void setEntityId(String entityId) {
279             this.entityId = entityId;
280         }
281         public void setStatus(CodedAttribute.Builder status) {
282             this.status = status;
283         }
284 
285         public void setCountryCode(String countryCode) {
286             this.countryCode = countryCode;
287         }
288 
289         public void setStartDate(DateTime startDate) {
290             this.startDate = startDate;
291         }
292 
293         public void setEndDate(DateTime endDate) {
294             this.endDate = endDate;
295         }
296 
297         public void setVersionNumber(Long versionNumber) {
298             this.versionNumber = versionNumber;
299         }
300 
301         public void setObjectId(String objectId) {
302             this.objectId = objectId;
303         }
304 
305         public void setActive(boolean active) {
306             this.active = active;
307         }
308 
309         public void setId(String id) {
310             if (StringUtils.isWhitespace(id)) {
311                 throw new IllegalArgumentException("id is blank");
312             }
313             this.id = id;
314         }
315 
316         public void setChangeDate(DateTime changeDate) {
317             this.changeDate = changeDate;
318         }
319 
320         public void setChangeType(CodedAttribute.Builder changeType) {
321             this.changeType = changeType;
322         }
323 
324     }
325 
326 
327     /**
328      * Defines some internal constants used on this class.
329      * 
330      */
331     static class Constants {
332 
333         final static String ROOT_ELEMENT_NAME = "entityCitizenship";
334         final static String TYPE_NAME = "EntityCitizenshipType";
335     }
336 
337 
338     /**
339      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
340      * 
341      */
342     static class Elements {
343         final static String ENTITY_ID = "entityId";
344         final static String STATUS = "status";
345         final static String COUNTRY_CODE = "countryCode";
346         final static String START_DATE = "startDate";
347         final static String END_DATE = "endDate";
348         final static String ACTIVE = "active";
349         final static String ID = "id";
350         final static String CHANGE_DATE = "changeDate";
351         final static String CHANGE_TYPE = "changeType";
352 
353     }
354 
355 }