001    /**
002     * Copyright 2005-2013 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.kim.api.identity.employment;
017    
018    import org.apache.commons.lang.StringUtils;
019    import org.kuali.rice.core.api.CoreConstants;
020    import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
021    import org.kuali.rice.core.api.mo.ModelBuilder;
022    import org.kuali.rice.core.api.util.jaxb.KualiDecimalAdapter;
023    import org.kuali.rice.core.api.util.type.KualiDecimal;
024    import org.kuali.rice.kim.api.identity.CodedAttribute;
025    import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliation;
026    import org.w3c.dom.Element;
027    
028    import javax.xml.bind.annotation.XmlAccessType;
029    import javax.xml.bind.annotation.XmlAccessorType;
030    import javax.xml.bind.annotation.XmlAnyElement;
031    import javax.xml.bind.annotation.XmlElement;
032    import javax.xml.bind.annotation.XmlRootElement;
033    import javax.xml.bind.annotation.XmlType;
034    import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
035    import java.io.Serializable;
036    import java.util.Collection;
037    
038    @XmlRootElement(name = EntityEmployment.Constants.ROOT_ELEMENT_NAME)
039    @XmlAccessorType(XmlAccessType.NONE)
040    @XmlType(name = EntityEmployment.Constants.TYPE_NAME, propOrder = {
041        EntityEmployment.Elements.ID,
042        EntityEmployment.Elements.ENTITY_ID,
043        EntityEmployment.Elements.EMPLOYEE_ID,
044        EntityEmployment.Elements.EMPLOYMENT_RECORD_ID,
045        EntityEmployment.Elements.ENTITY_AFFILIATION,
046        EntityEmployment.Elements.EMPLOYEE_STATUS,
047        EntityEmployment.Elements.EMPLOYEE_TYPE,
048        EntityEmployment.Elements.PRIMARY_DEPARTMENT_CODE,
049        EntityEmployment.Elements.BASE_SALARY_AMOUNT,
050        EntityEmployment.Elements.PRIMARY,
051        CoreConstants.CommonElements.VERSION_NUMBER,
052        CoreConstants.CommonElements.OBJECT_ID,
053        EntityEmployment.Elements.ACTIVE,
054    
055        CoreConstants.CommonElements.FUTURE_ELEMENTS
056    })
057    public final class EntityEmployment extends AbstractDataTransferObject
058        implements EntityEmploymentContract
059    {
060        @XmlElement(name = Elements.ID, required = false)
061        private final String id;
062        @XmlElement(name = Elements.ENTITY_ID, required = false)
063        private final String entityId;
064        @XmlElement(name = Elements.ENTITY_AFFILIATION, required = false)
065        private final EntityAffiliation entityAffiliation;
066        @XmlElement(name = Elements.EMPLOYEE_STATUS, required = false)
067        private final CodedAttribute employeeStatus;
068        @XmlElement(name = Elements.EMPLOYEE_TYPE, required = false)
069        private final CodedAttribute employeeType;
070        @XmlElement(name = Elements.PRIMARY_DEPARTMENT_CODE, required = false)
071        private final String primaryDepartmentCode;
072        @XmlElement(name = Elements.EMPLOYEE_ID, required = false)
073        private final String employeeId;
074        @XmlElement(name = Elements.EMPLOYMENT_RECORD_ID, required = false)
075        private final String employmentRecordId;
076        @XmlElement(name = Elements.BASE_SALARY_AMOUNT, required = false)
077        @XmlJavaTypeAdapter(KualiDecimalAdapter.class)
078        private final KualiDecimal baseSalaryAmount;
079        @XmlElement(name = Elements.PRIMARY, required = false)
080        private final boolean primary;
081        @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
082        private final Long versionNumber;
083        @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
084        private final String objectId;
085        @XmlElement(name = Elements.ACTIVE, required = false)
086        private final boolean active;
087    
088        @SuppressWarnings("unused")
089        @XmlAnyElement
090        private final Collection<Element> _futureElements = null;
091    
092        /**
093         * Private constructor used only by JAXB.
094         * 
095         */
096        private EntityEmployment() {
097            this.entityAffiliation = null;
098            this.employeeStatus = null;
099            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    }