001/**
002 * Copyright 2005-2016 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.impl.identity.employment;
017
018import javax.persistence.CascadeType;
019import javax.persistence.Column;
020import javax.persistence.Entity;
021import javax.persistence.GeneratedValue;
022import javax.persistence.Id;
023import javax.persistence.JoinColumn;
024import javax.persistence.ManyToOne;
025import javax.persistence.Table;
026
027import org.eclipse.persistence.annotations.JoinFetch;
028import org.eclipse.persistence.annotations.JoinFetchType;
029import org.kuali.rice.kim.api.identity.employment.EntityEmployment;
030import org.kuali.rice.kim.impl.identity.affiliation.EntityAffiliationBo;
031import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
032
033@Entity
034@Table(name = "KRIM_ENTITY_EMP_INFO_T")
035public class EntityEmploymentBo extends EntityEmploymentBase {
036
037    private static final long serialVersionUID = 1L;
038
039    @PortableSequenceGenerator(name = "KRIM_ENTITY_EMP_ID_S")
040    @GeneratedValue(generator = "KRIM_ENTITY_EMP_ID_S")
041    @Id
042    @Column(name = "ENTITY_EMP_ID")
043    private String id;
044
045    @JoinFetch(value= JoinFetchType.OUTER)
046    @ManyToOne(targetEntity = EntityEmploymentTypeBo.class, cascade = { CascadeType.REFRESH })
047    @JoinColumn(name = "EMP_TYP_CD", referencedColumnName = "EMP_TYP_CD", insertable = false, updatable = false)
048    private EntityEmploymentTypeBo employeeType;
049
050    @JoinFetch(value= JoinFetchType.OUTER)
051    @ManyToOne(targetEntity = EntityEmploymentStatusBo.class, cascade = { CascadeType.REFRESH })
052    @JoinColumn(name = "EMP_STAT_CD", referencedColumnName = "EMP_STAT_CD", insertable = false, updatable = false)
053    private EntityEmploymentStatusBo employeeStatus;
054
055    @JoinFetch(value= JoinFetchType.OUTER)
056    @ManyToOne(targetEntity = EntityAffiliationBo.class, cascade = { CascadeType.REFRESH })
057    @JoinColumn(name = "ENTITY_AFLTN_ID", referencedColumnName = "ENTITY_AFLTN_ID", insertable = false, updatable = false)
058    private EntityAffiliationBo entityAffiliation;
059
060    @Override
061    public EntityAffiliationBo getEntityAffiliation() {
062        return this.entityAffiliation;
063    }
064
065    @Override
066    public EntityEmploymentStatusBo getEmployeeStatus() {
067        return this.employeeStatus;
068    }
069
070    @Override
071    public EntityEmploymentTypeBo getEmployeeType() {
072        return this.employeeType;
073    }
074
075    public static EntityEmployment to(EntityEmploymentBo bo) {
076        if (bo == null) {
077            return null;
078        }
079        return EntityEmployment.Builder.create(bo).build();
080    }
081
082    /**
083     * Creates a EntityEmploymentBo business object from an immutable representation of a EntityEmployment.
084     *
085     * @param immutable an immutable EntityEmployment
086     * @return a EntityEmploymentBo
087     */
088    public static EntityEmploymentBo from(EntityEmployment immutable) {
089        if (immutable == null) {
090            return null;
091        }
092        EntityEmploymentBo bo = new EntityEmploymentBo();
093        bo.id = immutable.getId();
094        bo.setActive(immutable.isActive());
095        bo.setEntityId(immutable.getEntityId());
096        if (immutable.getEmployeeType() != null) {
097            bo.setEmployeeTypeCode(immutable.getEmployeeType().getCode());
098            bo.setEmployeeType(EntityEmploymentTypeBo.from(immutable.getEmployeeType()));
099        }
100        if (immutable.getEmployeeStatus() != null) {
101            bo.setEmployeeStatusCode(immutable.getEmployeeStatus().getCode());
102            bo.setEmployeeStatus(EntityEmploymentStatusBo.from(immutable.getEmployeeStatus()));
103        }
104        if (immutable.getEntityAffiliation() != null) {
105            bo.setEntityAffiliationId(immutable.getEntityAffiliation().getId());
106            bo.setEntityAffiliation(EntityAffiliationBo.from(immutable.getEntityAffiliation()));
107        }
108        bo.setPrimaryDepartmentCode(immutable.getPrimaryDepartmentCode());
109        bo.setEmployeeId(immutable.getEmployeeId());
110        bo.setEmploymentRecordId(immutable.getEmploymentRecordId());
111        bo.setBaseSalaryAmount(immutable.getBaseSalaryAmount());
112        bo.setPrimary(immutable.isPrimary());
113        bo.setVersionNumber(immutable.getVersionNumber());
114        bo.setObjectId(immutable.getObjectId());
115        return bo;
116    }
117
118    @Override
119    public String getId() {
120        return id;
121    }
122
123    public void setId(String id) {
124        this.id = id;
125    }
126
127    public void setEmployeeType(EntityEmploymentTypeBo employeeType) {
128        this.employeeType = employeeType;
129    }
130
131    public void setEmployeeStatus(EntityEmploymentStatusBo employeeStatus) {
132        this.employeeStatus = employeeStatus;
133    }
134
135    public void setEntityAffiliation(EntityAffiliationBo entityAffiliation) {
136        this.entityAffiliation = entityAffiliation;
137    }
138}