001/**
002 * Copyright 2005-2015 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 */
016package org.kuali.rice.kim.api.identity.employment;
017
018import org.apache.commons.lang.StringUtils;
019import org.kuali.rice.core.api.CoreConstants;
020import org.kuali.rice.core.api.mo.AbstractDataTransferObject;
021import org.kuali.rice.core.api.mo.ModelBuilder;
022import org.kuali.rice.core.api.util.jaxb.KualiDecimalAdapter;
023import org.kuali.rice.core.api.util.jaxb.PrimitiveBooleanDefaultToFalseAdapter;
024import org.kuali.rice.core.api.util.type.KualiDecimal;
025import org.kuali.rice.kim.api.identity.CodedAttribute;
026import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliation;
027import org.w3c.dom.Element;
028
029import javax.xml.bind.annotation.XmlAccessType;
030import javax.xml.bind.annotation.XmlAccessorType;
031import javax.xml.bind.annotation.XmlAnyElement;
032import javax.xml.bind.annotation.XmlElement;
033import javax.xml.bind.annotation.XmlRootElement;
034import javax.xml.bind.annotation.XmlType;
035import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
036import java.io.Serializable;
037import java.util.Collection;
038
039@XmlRootElement(name = EntityEmployment.Constants.ROOT_ELEMENT_NAME)
040@XmlAccessorType(XmlAccessType.NONE)
041@XmlType(name = EntityEmployment.Constants.TYPE_NAME, propOrder = {
042    EntityEmployment.Elements.ID,
043    EntityEmployment.Elements.ENTITY_ID,
044    EntityEmployment.Elements.EMPLOYEE_ID,
045    EntityEmployment.Elements.EMPLOYMENT_RECORD_ID,
046    EntityEmployment.Elements.ENTITY_AFFILIATION,
047    EntityEmployment.Elements.EMPLOYEE_STATUS,
048    EntityEmployment.Elements.EMPLOYEE_TYPE,
049    EntityEmployment.Elements.PRIMARY_DEPARTMENT_CODE,
050    EntityEmployment.Elements.BASE_SALARY_AMOUNT,
051    EntityEmployment.Elements.PRIMARY,
052    CoreConstants.CommonElements.VERSION_NUMBER,
053    CoreConstants.CommonElements.OBJECT_ID,
054    EntityEmployment.Elements.ACTIVE,
055
056    CoreConstants.CommonElements.FUTURE_ELEMENTS
057})
058public final class EntityEmployment extends AbstractDataTransferObject
059    implements EntityEmploymentContract
060{
061    @XmlElement(name = Elements.ID, required = false)
062    private final String id;
063    @XmlElement(name = Elements.ENTITY_ID, required = false)
064    private final String entityId;
065    @XmlElement(name = Elements.ENTITY_AFFILIATION, required = false)
066    private final EntityAffiliation entityAffiliation;
067    @XmlElement(name = Elements.EMPLOYEE_STATUS, required = false)
068    private final CodedAttribute employeeStatus;
069    @XmlElement(name = Elements.EMPLOYEE_TYPE, required = false)
070    private final CodedAttribute employeeType;
071    @XmlElement(name = Elements.PRIMARY_DEPARTMENT_CODE, required = false)
072    private final String primaryDepartmentCode;
073    @XmlElement(name = Elements.EMPLOYEE_ID, required = false)
074    private final String employeeId;
075    @XmlElement(name = Elements.EMPLOYMENT_RECORD_ID, required = false)
076    private final String employmentRecordId;
077    @XmlElement(name = Elements.BASE_SALARY_AMOUNT, required = false)
078    @XmlJavaTypeAdapter(KualiDecimalAdapter.class)
079    private final KualiDecimal baseSalaryAmount;
080    @XmlElement(name = Elements.PRIMARY, required = false)
081    private final boolean primary;
082    @XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false)
083    private final Long versionNumber;
084    @XmlElement(name = CoreConstants.CommonElements.OBJECT_ID, required = false)
085    private final String objectId;
086    @XmlElement(name = Elements.ACTIVE, required = true)
087    private final boolean active;
088
089    @SuppressWarnings("unused")
090    @XmlAnyElement
091    private final Collection<Element> _futureElements = null;
092
093    /**
094     * Private constructor used only by JAXB.
095     * 
096     */
097    private EntityEmployment() {
098        this.entityAffiliation = null;
099        this.employeeStatus = null;
100        this.employeeType = null;
101        this.primaryDepartmentCode = null;
102        this.employeeId = null;
103        this.employmentRecordId = null;
104        this.baseSalaryAmount = null;
105        this.primary = false;
106        this.versionNumber = null;
107        this.objectId = null;
108        this.active = false;
109        this.entityId = null;
110        this.id = null;
111    }
112
113    private EntityEmployment(Builder builder) {
114        this.entityAffiliation = builder.getEntityAffiliation() != null ? builder.getEntityAffiliation().build() : null;
115        this.employeeStatus = builder.getEmployeeStatus() != null ? builder.getEmployeeStatus().build() : null;
116        this.employeeType = builder.getEmployeeType() != null ? builder.getEmployeeType().build() : null;
117        this.primaryDepartmentCode = builder.getPrimaryDepartmentCode();
118        this.employeeId = builder.getEmployeeId();
119        this.employmentRecordId = builder.getEmploymentRecordId();
120        this.baseSalaryAmount = builder.getBaseSalaryAmount();
121        this.primary = builder.isPrimary();
122        this.versionNumber = builder.getVersionNumber();
123        this.objectId = builder.getObjectId();
124        this.active = builder.isActive();
125        this.id = builder.getId();
126        this.entityId = builder.getEntityId();
127    }
128
129    @Override
130    public String getEntityId() {
131        return this.entityId;
132    }
133    @Override
134    public EntityAffiliation getEntityAffiliation() {
135        return this.entityAffiliation;
136    }
137
138    @Override
139    public CodedAttribute getEmployeeStatus() {
140        return this.employeeStatus;
141    }
142
143    @Override
144    public CodedAttribute getEmployeeType() {
145        return this.employeeType;
146    }
147
148    @Override
149    public String getPrimaryDepartmentCode() {
150        return this.primaryDepartmentCode;
151    }
152
153    @Override
154    public String getEmployeeId() {
155        return this.employeeId;
156    }
157
158    @Override
159    public String getEmploymentRecordId() {
160        return this.employmentRecordId;
161    }
162
163    @Override
164    public KualiDecimal getBaseSalaryAmount() {
165        return this.baseSalaryAmount;
166    }
167
168    @Override
169    public boolean isPrimary() {
170        return this.primary;
171    }
172
173    @Override
174    public Long getVersionNumber() {
175        return this.versionNumber;
176    }
177
178    @Override
179    public String getObjectId() {
180        return this.objectId;
181    }
182
183    @Override
184    public boolean isActive() {
185        return this.active;
186    }
187
188    @Override
189    public String getId() {
190        return this.id;
191    }
192
193    /**
194     * A builder which can be used to construct {@link EntityEmployment} instances.  Enforces the constraints of the {@link EntityEmploymentContract}.
195     * 
196     */
197    public final static class Builder
198        implements Serializable, ModelBuilder, EntityEmploymentContract
199    {
200        private String entityId;
201        private EntityAffiliation.Builder entityAffiliation;
202        private CodedAttribute.Builder employeeStatus;
203        private CodedAttribute.Builder employeeType;
204        private String primaryDepartmentCode;
205        private String employeeId;
206        private String employmentRecordId;
207        private KualiDecimal baseSalaryAmount;
208        private boolean primary;
209        private Long versionNumber;
210        private String objectId;
211        private boolean active;
212        private String id;
213
214        private Builder() { }
215
216        public static Builder create() {
217            return new Builder();
218        }
219
220        public static Builder create(EntityEmploymentContract contract) {
221            if (contract == null) {
222                throw new IllegalArgumentException("contract was null");
223            }
224            Builder builder = create();
225            builder.setEntityId(contract.getEntityId());
226            if (contract.getEntityAffiliation() != null) {
227                builder.setEntityAffiliation(EntityAffiliation.Builder.create(contract.getEntityAffiliation()));
228            }
229            if (contract.getEmployeeStatus() != null) {
230                builder.setEmployeeStatus(CodedAttribute.Builder.create(contract.getEmployeeStatus()));
231            }
232            if (contract.getEmployeeType() != null) {
233                builder.setEmployeeType(CodedAttribute.Builder.create(contract.getEmployeeType()));
234            }
235            builder.setPrimaryDepartmentCode(contract.getPrimaryDepartmentCode());
236            builder.setEmployeeId(contract.getEmployeeId());
237            builder.setEmploymentRecordId(contract.getEmploymentRecordId());
238            builder.setBaseSalaryAmount(contract.getBaseSalaryAmount());
239            builder.setPrimary(contract.isPrimary());
240            builder.setVersionNumber(contract.getVersionNumber());
241            builder.setObjectId(contract.getObjectId());
242            builder.setActive(contract.isActive());
243            builder.setId(contract.getId());
244            return builder;
245        }
246
247        public EntityEmployment build() {
248            return new EntityEmployment(this);
249        }
250
251        @Override
252        public String getEntityId() {
253            return this.entityId;
254        }
255        @Override
256        public EntityAffiliation.Builder getEntityAffiliation() {
257            return this.entityAffiliation;
258        }
259
260        @Override
261        public CodedAttribute.Builder getEmployeeStatus() {
262            return this.employeeStatus;
263        }
264
265        @Override
266        public CodedAttribute.Builder getEmployeeType() {
267            return this.employeeType;
268        }
269
270        @Override
271        public String getPrimaryDepartmentCode() {
272            return this.primaryDepartmentCode;
273        }
274
275        @Override
276        public String getEmployeeId() {
277            return this.employeeId;
278        }
279
280        @Override
281        public String getEmploymentRecordId() {
282            return this.employmentRecordId;
283        }
284
285        @Override
286        public KualiDecimal getBaseSalaryAmount() {
287            return this.baseSalaryAmount;
288        }
289
290        @Override
291        public boolean isPrimary() {
292            return this.primary;
293        }
294
295        @Override
296        public Long getVersionNumber() {
297            return this.versionNumber;
298        }
299
300        @Override
301        public String getObjectId() {
302            return this.objectId;
303        }
304
305        @Override
306        public boolean isActive() {
307            return this.active;
308        }
309
310        @Override
311        public String getId() {
312            return this.id;
313        }
314
315        public void setEntityAffiliation(EntityAffiliation.Builder entityAffiliation) {
316            this.entityAffiliation = entityAffiliation;
317        }
318
319        public void setEmployeeStatus(CodedAttribute.Builder employeeStatus) {
320            this.employeeStatus = employeeStatus;
321        }
322
323        public void setEmployeeType(CodedAttribute.Builder employeeType) {
324            this.employeeType = employeeType;
325        }
326
327        public void setEntityId(String entityId) {
328            this.entityId = entityId;
329        }
330
331        public void setPrimaryDepartmentCode(String primaryDepartmentCode) {
332            this.primaryDepartmentCode = primaryDepartmentCode;
333        }
334
335        public void setEmployeeId(String employeeId) {
336            this.employeeId = employeeId;
337        }
338
339        public void setEmploymentRecordId(String employmentRecordId) {
340            this.employmentRecordId = employmentRecordId;
341        }
342
343        public void setBaseSalaryAmount(KualiDecimal baseSalaryAmount) {
344            this.baseSalaryAmount = baseSalaryAmount;
345        }
346
347        public void setPrimary(boolean primary) {
348            this.primary = primary;
349        }
350
351        public void setVersionNumber(Long versionNumber) {
352            this.versionNumber = versionNumber;
353        }
354
355        public void setObjectId(String objectId) {
356            this.objectId = objectId;
357        }
358
359        public void setActive(boolean active) {
360            this.active = active;
361        }
362
363        public void setId(String id) {
364            if (StringUtils.isWhitespace(id)) {
365                throw new IllegalArgumentException("id is blank");
366            }
367            this.id = id;
368        }
369
370    }
371
372
373    /**
374     * Defines some internal constants used on this class.
375     * 
376     */
377    static class Constants {
378
379        final static String ROOT_ELEMENT_NAME = "entityEmployment";
380        final static String TYPE_NAME = "EntityEmploymentType";
381    }
382
383
384    /**
385     * A private class which exposes constants which define the XML element names to use when this object is marshalled to XML.
386     * 
387     */
388    static class Elements {
389
390        final static String ENTITY_AFFILIATION = "entityAffiliation";
391        final static String EMPLOYEE_STATUS = "employeeStatus";
392        final static String EMPLOYEE_TYPE = "employeeType";
393        final static String PRIMARY_DEPARTMENT_CODE = "primaryDepartmentCode";
394        final static String EMPLOYEE_ID = "employeeId";
395        final static String EMPLOYMENT_RECORD_ID = "employmentRecordId";
396        final static String BASE_SALARY_AMOUNT = "baseSalaryAmount";
397        final static String PRIMARY = "primary";
398        final static String ACTIVE = "active";
399        final static String ENTITY_ID = "entityId";
400        final static String ID = "id";
401
402    }
403
404}