View Javadoc
1   /**
2    * Copyright 2004-2014 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.kpme.pm.api.positionappointment;
17  
18  import java.io.Serializable;
19  import java.util.Collection;
20  
21  import javax.xml.bind.annotation.XmlAccessType;
22  import javax.xml.bind.annotation.XmlAccessorType;
23  import javax.xml.bind.annotation.XmlAnyElement;
24  import javax.xml.bind.annotation.XmlElement;
25  import javax.xml.bind.annotation.XmlRootElement;
26  import javax.xml.bind.annotation.XmlType;
27  
28  import org.apache.commons.lang.StringUtils;
29  import org.joda.time.DateTime;
30  import org.joda.time.LocalDate;
31  import org.kuali.kpme.core.api.groupkey.HrGroupKey;
32  import org.kuali.rice.core.api.CoreConstants;
33  import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
34  import org.kuali.rice.core.api.mo.ModelBuilder;
35  import org.w3c.dom.Element;
36  
37  @XmlRootElement(name = PositionAppointment.Constants.ROOT_ELEMENT_NAME)
38  @XmlAccessorType(XmlAccessType.NONE)
39  @XmlType(name = PositionAppointment.Constants.TYPE_NAME, propOrder = {
40      PositionAppointment.Elements.POSITION_APPOINTMENT,
41      PositionAppointment.Elements.DESCRIPTION,
42      PositionAppointment.Elements.PM_POSITION_APPOINTMENT_ID,
43      CoreConstants.CommonElements.VERSION_NUMBER,
44      CoreConstants.CommonElements.OBJECT_ID,
45      PositionAppointment.Elements.ACTIVE,
46      PositionAppointment.Elements.ID,
47      PositionAppointment.Elements.EFFECTIVE_LOCAL_DATE,
48      PositionAppointment.Elements.CREATE_TIME,
49      PositionAppointment.Elements.USER_PRINCIPAL_ID,
50      PositionAppointment.Elements.GROUP_KEY_CODE,
51      PositionAppointment.Elements.GROUP_KEY,
52      CoreConstants.CommonElements.FUTURE_ELEMENTS
53  })
54  public final class PositionAppointment
55      extends AbstractDataTransferObject
56      implements PositionAppointmentContract
57  {
58  
59      @XmlElement(name = Elements.POSITION_APPOINTMENT, required = false)
60      private final String positionAppointment;
61      @XmlElement(name = Elements.DESCRIPTION, required = false)
62      private final String description;
63      @XmlElement(name = Elements.PM_POSITION_APPOINTMENT_ID, required = false)
64      private final String pmPositionAppointmentId;
65      @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
66      private final Long versionNumber;
67      @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
68      private final String objectId;
69      @XmlElement(name = Elements.ACTIVE, required = false)
70      private final boolean active;
71      @XmlElement(name = Elements.ID, required = false)
72      private final String id;
73      @XmlElement(name = Elements.EFFECTIVE_LOCAL_DATE, required = false)
74      private final LocalDate effectiveLocalDate;
75      @XmlElement(name = Elements.CREATE_TIME, required = false)
76      private final DateTime createTime;
77      @XmlElement(name = Elements.USER_PRINCIPAL_ID, required = false)
78      private final String userPrincipalId;
79      @XmlElement(name = Elements.GROUP_KEY_CODE, required = true)
80      private final String groupKeyCode;
81      @XmlElement(name = Elements.GROUP_KEY, required = true)
82      private final HrGroupKey groupKey;
83      @SuppressWarnings("unused")
84      @XmlAnyElement
85      private final Collection<Element> _futureElements = null;
86  
87      /**
88       * Private constructor used only by JAXB.
89       * 
90       */
91      private PositionAppointment() {
92          this.positionAppointment = null;
93          this.description = null;
94          this.pmPositionAppointmentId = null;
95          this.versionNumber = null;
96          this.objectId = null;
97          this.active = false;
98          this.id = null;
99          this.effectiveLocalDate = null;
100         this.createTime = null;
101         this.userPrincipalId = null;
102         this.groupKeyCode = null;
103         this.groupKey = null;
104     }
105 
106     private PositionAppointment(Builder builder) {
107         this.positionAppointment = builder.getPositionAppointment();
108         this.description = builder.getDescription();
109         this.pmPositionAppointmentId = builder.getPmPositionAppointmentId();
110         this.versionNumber = builder.getVersionNumber();
111         this.objectId = builder.getObjectId();
112         this.active = builder.isActive();
113         this.id = builder.getId();
114         this.effectiveLocalDate = builder.getEffectiveLocalDate();
115         this.createTime = builder.getCreateTime();
116         this.userPrincipalId = builder.getUserPrincipalId();
117         this.groupKey = builder.getGroupKey() == null ? null : builder.getGroupKey().build();
118         this.groupKeyCode = builder.getGroupKeyCode();
119     }
120 
121     @Override
122     public String getPositionAppointment() {
123         return this.positionAppointment;
124     }
125 
126     @Override
127     public String getDescription() {
128         return this.description;
129     }
130 
131     @Override
132     public String getPmPositionAppointmentId() {
133         return this.pmPositionAppointmentId;
134     }
135 
136     @Override
137     public Long getVersionNumber() {
138         return this.versionNumber;
139     }
140 
141     @Override
142     public String getObjectId() {
143         return this.objectId;
144     }
145 
146     @Override
147     public boolean isActive() {
148         return this.active;
149     }
150 
151     @Override
152     public String getId() {
153         return this.id;
154     }
155 
156     @Override
157     public LocalDate getEffectiveLocalDate() {
158         return this.effectiveLocalDate;
159     }
160 
161     @Override
162     public DateTime getCreateTime() {
163         return this.createTime;
164     }
165 
166     @Override
167     public String getUserPrincipalId() {
168         return this.userPrincipalId;
169     }
170 
171     @Override
172     public HrGroupKey getGroupKey() {
173         return this.groupKey;
174     }
175 
176     @Override
177     public String getGroupKeyCode() {
178         return this.groupKeyCode;
179     }
180 
181 
182     /**
183      * A builder which can be used to construct {@link PositionAppointment} instances.  Enforces the constraints of the {@link PositionAppointmentContract}.
184      * 
185      */
186     public final static class Builder
187         implements Serializable, PositionAppointmentContract, ModelBuilder
188     {
189 
190         private String positionAppointment;
191         private String description;
192         private String pmPositionAppointmentId;
193         private Long versionNumber;
194         private String objectId;
195         private boolean active;
196         private String id;
197         private LocalDate effectiveLocalDate;
198         private DateTime createTime;
199         private String userPrincipalId;
200         private String groupKeyCode;
201         private HrGroupKey.Builder groupKey;
202 
203         private Builder(String groupKeyCode, String positionAppointment) {
204 
205         	setGroupKeyCode(groupKeyCode);
206         	setPositionAppointment(positionAppointment);
207         }
208 
209         public static Builder create(String groupKeyCode, String positionAppointment) {
210 
211             return new Builder(groupKeyCode,positionAppointment);
212         }
213 
214         public static Builder create(PositionAppointmentContract contract) {
215             if (contract == null) {
216                 throw new IllegalArgumentException("contract was null");
217             }
218 
219             Builder builder = create(contract.getGroupKeyCode(),contract.getPositionAppointment());
220             builder.setPositionAppointment(contract.getPositionAppointment());
221             builder.setDescription(contract.getDescription());
222             builder.setPmPositionAppointmentId(contract.getPmPositionAppointmentId());
223             builder.setVersionNumber(contract.getVersionNumber());
224             builder.setObjectId(contract.getObjectId());
225             builder.setActive(contract.isActive());
226             builder.setId(contract.getId());
227             builder.setEffectiveLocalDate(contract.getEffectiveLocalDate());
228             builder.setCreateTime(contract.getCreateTime());
229             builder.setUserPrincipalId(contract.getUserPrincipalId());
230             builder.setGroupKey(contract.getGroupKey() == null ? null : HrGroupKey.Builder.create(contract.getGroupKey()));
231             return builder;
232         }
233 
234         public PositionAppointment build() {
235             return new PositionAppointment(this);
236         }
237 
238         @Override
239         public String getPositionAppointment() {
240             return this.positionAppointment;
241         }
242 
243         @Override
244         public String getDescription() {
245             return this.description;
246         }
247 
248         @Override
249         public String getPmPositionAppointmentId() {
250             return this.pmPositionAppointmentId;
251         }
252 
253         @Override
254         public Long getVersionNumber() {
255             return this.versionNumber;
256         }
257 
258         @Override
259         public String getObjectId() {
260             return this.objectId;
261         }
262 
263         @Override
264         public boolean isActive() {
265             return this.active;
266         }
267 
268         @Override
269         public String getId() {
270             return this.id;
271         }
272 
273         @Override
274         public LocalDate getEffectiveLocalDate() {
275             return this.effectiveLocalDate;
276         }
277 
278         @Override
279         public DateTime getCreateTime() {
280             return this.createTime;
281         }
282 
283         @Override
284         public String getUserPrincipalId() {
285             return this.userPrincipalId;
286         }
287         
288         @Override
289         public String getGroupKeyCode() {
290             return this.groupKeyCode;
291         }
292 
293         @Override
294         public HrGroupKey.Builder getGroupKey() {
295             return this.groupKey;
296         }
297 
298         public void setPositionAppointment(String positionAppointment) {
299 
300         	if (StringUtils.isWhitespace(positionAppointment)) {
301                 throw new IllegalArgumentException("positionAppointment is blank");
302             }
303             this.positionAppointment = positionAppointment;
304         }
305 
306         public void setDescription(String description) {
307 
308             this.description = description;
309         }
310 
311         public void setPmPositionAppointmentId(String pmPositionAppointmentId) {
312 
313             this.pmPositionAppointmentId = pmPositionAppointmentId;
314         }
315 
316         public void setVersionNumber(Long versionNumber) {
317 
318             this.versionNumber = versionNumber;
319         }
320 
321         public void setObjectId(String objectId) {
322 
323             this.objectId = objectId;
324         }
325 
326         public void setActive(boolean active) {
327 
328             this.active = active;
329         }
330 
331         public void setId(String id) {
332 
333             this.id = id;
334         }
335 
336         public void setEffectiveLocalDate(LocalDate effectiveLocalDate) {
337 
338             this.effectiveLocalDate = effectiveLocalDate;
339         }
340 
341         public void setCreateTime(DateTime createTime) {
342 
343             this.createTime = createTime;
344         }
345 
346         public void setUserPrincipalId(String userPrincipalId) {
347 
348             this.userPrincipalId = userPrincipalId;
349         }
350 
351         public void setGroupKeyCode(String groupKeyCode) {
352             if (StringUtils.isWhitespace(groupKeyCode)) {
353                 throw new IllegalArgumentException("groupKeyCode is blank");
354             }
355             this.groupKeyCode = groupKeyCode;
356         }
357 
358         public void setGroupKey(HrGroupKey.Builder groupKey) {
359             this.groupKey = groupKey;
360         }
361 
362     }
363 
364 
365     /**
366      * Defines some internal constants used on this class.
367      * 
368      */
369     static class Constants {
370 
371         final static String ROOT_ELEMENT_NAME = "positionAppointment";
372         final static String TYPE_NAME = "PositionAppointmentType";
373 
374     }
375 
376 
377     /**
378      * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
379      * 
380      */
381     static class Elements {
382 
383         final static String POSITION_APPOINTMENT = "positionAppointment";
384         final static String DESCRIPTION = "description";
385         final static String PM_POSITION_APPOINTMENT_ID = "pmPositionAppointmentId";
386         final static String ACTIVE = "active";
387         final static String ID = "id";
388         final static String EFFECTIVE_LOCAL_DATE = "effectiveLocalDate";
389         final static String CREATE_TIME = "createTime";
390         final static String USER_PRINCIPAL_ID = "userPrincipalId";
391         final static String GROUP_KEY_CODE = "groupKeyCode";
392         final static String GROUP_KEY = "groupKey";
393 
394     }
395 
396 }