View Javadoc

1   /**
2    * Copyright 2005-2012 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      CoreConstants.CommonElements.FUTURE_ELEMENTS
50  })
51  public final class EntityCitizenship extends AbstractDataTransferObject
52      implements EntityCitizenshipContract
53  {
54      @XmlElement(name = Elements.ID, required = false)
55      private final String id;
56      @XmlElement(name = Elements.ENTITY_ID, required = false)
57      private final String entityId;
58      @XmlElement(name = Elements.STATUS, required = false)
59      private final CodedAttribute status;
60      @XmlElement(name = Elements.COUNTRY_CODE, required = false)
61      private final String countryCode;
62      @XmlJavaTypeAdapter(DateTimeAdapter.class)
63      @XmlElement(name = Elements.START_DATE, required = false)
64      private final DateTime startDate;
65      @XmlJavaTypeAdapter(DateTimeAdapter.class)
66      @XmlElement(name = Elements.END_DATE, required = false)
67      private final DateTime endDate;
68      @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
69      private final Long versionNumber;
70      @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
71      private final String objectId;
72      @XmlElement(name = Elements.ACTIVE, required = false)
73      private final boolean active;
74      @SuppressWarnings("unused")
75      @XmlAnyElement
76      private final Collection<Element> _futureElements = null;
77  
78      /**
79       * Private constructor used only by JAXB.
80       * 
81       */
82      private EntityCitizenship() {
83          this.status = null;
84          this.countryCode = null;
85          this.startDate = null;
86          this.endDate = null;
87          this.versionNumber = null;
88          this.objectId = null;
89          this.active = false;
90          this.id = null;
91          this.entityId = null;
92      }
93  
94      private EntityCitizenship(Builder builder) {
95          this.status = builder.getStatus() != null ? builder.getStatus().build() : null;
96          this.countryCode = builder.getCountryCode();
97          this.startDate = builder.getStartDate();
98          this.endDate = builder.getEndDate();
99          this.versionNumber = builder.getVersionNumber();
100         this.objectId = builder.getObjectId();
101         this.active = builder.isActive();
102         this.id = builder.getId();
103         this.entityId = builder.getEntityId();
104     }
105 
106     @Override
107     public String getEntityId() {
108         return this.entityId;
109     }
110 
111     @Override
112     public CodedAttribute getStatus() {
113         return this.status;
114     }
115 
116     @Override
117     public String getCountryCode() {
118         return this.countryCode;
119     }
120 
121     @Override
122     public DateTime getStartDate() {
123         return this.startDate;
124     }
125 
126     @Override
127     public DateTime getEndDate() {
128         return this.endDate;
129     }
130 
131     @Override
132     public Long getVersionNumber() {
133         return this.versionNumber;
134     }
135 
136     @Override
137     public String getObjectId() {
138         return this.objectId;
139     }
140 
141     @Override
142     public boolean isActive() {
143         return this.active;
144     }
145 
146     @Override
147     public String getId() {
148         return this.id;
149     }
150 
151     /**
152      * A builder which can be used to construct {@link EntityCitizenship} instances.  Enforces the constraints of the {@link EntityCitizenshipContract}.
153      * 
154      */
155     public final static class Builder
156         implements Serializable, ModelBuilder, EntityCitizenshipContract
157     {
158         private String entityId;
159         private CodedAttribute.Builder status;
160         private String countryCode;
161         private DateTime startDate;
162         private DateTime endDate;
163         private Long versionNumber;
164         private String objectId;
165         private boolean active;
166         private String id;
167 
168         private Builder() {
169         }
170 
171         public static Builder create() {
172             return new Builder();
173         }
174 
175         public static Builder create(EntityCitizenshipContract contract) {
176             if (contract == null) {
177                 throw new IllegalArgumentException("contract was null");
178             }
179             Builder builder = create();
180             builder.setEntityId(contract.getEntityId());
181             if (contract.getStatus() != null) {
182                 builder.setStatus(CodedAttribute.Builder.create(contract.getStatus()));
183             }
184             builder.setCountryCode(contract.getCountryCode());
185             builder.setStartDate(contract.getStartDate());
186             builder.setEndDate(contract.getEndDate());
187             builder.setVersionNumber(contract.getVersionNumber());
188             builder.setObjectId(contract.getObjectId());
189             builder.setActive(contract.isActive());
190             builder.setId(contract.getId());
191             return builder;
192         }
193 
194         public EntityCitizenship build() {
195             return new EntityCitizenship(this);
196         }
197 
198         @Override
199         public String getEntityId() {
200             return this.entityId;
201         }
202 
203         @Override
204         public CodedAttribute.Builder getStatus() {
205             return this.status;
206         }
207 
208         @Override
209         public String getCountryCode() {
210             return this.countryCode;
211         }
212 
213         @Override
214         public DateTime getStartDate() {
215             return this.startDate;
216         }
217 
218         @Override
219         public DateTime getEndDate() {
220             return this.endDate;
221         }
222 
223         @Override
224         public Long getVersionNumber() {
225             return this.versionNumber;
226         }
227 
228         @Override
229         public String getObjectId() {
230             return this.objectId;
231         }
232 
233         @Override
234         public boolean isActive() {
235             return this.active;
236         }
237 
238         @Override
239         public String getId() {
240             return this.id;
241         }
242 
243         public void setEntityId(String entityId) {
244             this.entityId = entityId;
245         }
246         public void setStatus(CodedAttribute.Builder status) {
247             this.status = status;
248         }
249 
250         public void setCountryCode(String countryCode) {
251             this.countryCode = countryCode;
252         }
253 
254         public void setStartDate(DateTime startDate) {
255             this.startDate = startDate;
256         }
257 
258         public void setEndDate(DateTime endDate) {
259             this.endDate = endDate;
260         }
261 
262         public void setVersionNumber(Long versionNumber) {
263             this.versionNumber = versionNumber;
264         }
265 
266         public void setObjectId(String objectId) {
267             this.objectId = objectId;
268         }
269 
270         public void setActive(boolean active) {
271             this.active = active;
272         }
273 
274         public void setId(String id) {
275             if (StringUtils.isWhitespace(id)) {
276                 throw new IllegalArgumentException("id is blank");
277             }
278             this.id = id;
279         }
280 
281     }
282 
283 
284     /**
285      * Defines some internal constants used on this class.
286      * 
287      */
288     static class Constants {
289 
290         final static String ROOT_ELEMENT_NAME = "entityCitizenship";
291         final static String TYPE_NAME = "EntityCitizenshipType";
292     }
293 
294 
295     /**
296      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
297      * 
298      */
299     static class Elements {
300         final static String ENTITY_ID = "entityId";
301         final static String STATUS = "status";
302         final static String COUNTRY_CODE = "countryCode";
303         final static String START_DATE = "startDate";
304         final static String END_DATE = "endDate";
305         final static String ACTIVE = "active";
306         final static String ID = "id";
307 
308     }
309 
310 }