View Javadoc

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