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.citizenship;
017
018import java.sql.Timestamp;
019
020import javax.persistence.CascadeType;
021import javax.persistence.Column;
022import javax.persistence.Entity;
023import javax.persistence.GeneratedValue;
024import javax.persistence.Id;
025import javax.persistence.JoinColumn;
026import javax.persistence.ManyToOne;
027import javax.persistence.Table;
028import javax.persistence.Transient;
029
030import org.eclipse.persistence.annotations.JoinFetch;
031import org.eclipse.persistence.annotations.JoinFetchType;
032import org.kuali.rice.kim.api.identity.citizenship.EntityCitizenship;
033import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
034
035@Entity
036@Table(name = "KRIM_ENTITY_CTZNSHP_T")
037public class EntityCitizenshipBo extends EntityCitizenshipBase {
038
039    private static final long serialVersionUID = 1L;
040
041    @PortableSequenceGenerator(name = "KRIM_ENTITY_CTZNSHP_ID_S")
042    @GeneratedValue(generator = "KRIM_ENTITY_CTZNSHP_ID_S")
043    @Id
044    @Column(name = "ENTITY_CTZNSHP_ID")
045    private String id;
046
047    @JoinFetch(value= JoinFetchType.OUTER)
048    @ManyToOne(targetEntity = EntityCitizenshipStatusBo.class, cascade = { CascadeType.REFRESH })
049    @JoinColumn(name = "CTZNSHP_STAT_CD", referencedColumnName = "CTZNSHP_STAT_CD", insertable = false, updatable = false)
050    private EntityCitizenshipStatusBo status;
051
052    @Transient
053    private EntityCitizenshipChangeTypeBo changeType;
054
055    public static EntityCitizenship to(EntityCitizenshipBo bo) {
056        if (bo == null) {
057            return null;
058        }
059        return EntityCitizenship.Builder.create(bo).build();
060    }
061
062    /**
063     * Creates a EntityCitizenshipBo business object from an immutable representation of a EntityCitizenship.
064     *
065     * @param immutable an immutable EntityCitizenship
066     * @return a EntityCitizenshipBo
067     */
068    public static EntityCitizenshipBo from(EntityCitizenship immutable) {
069        if (immutable == null) {
070            return null;
071        }
072        EntityCitizenshipBo bo = new EntityCitizenshipBo();
073        bo.setActive(immutable.isActive());
074        if (immutable.getStatus() != null) {
075            bo.setStatusCode(immutable.getStatus().getCode());
076            bo.setStatus(EntityCitizenshipStatusBo.from(immutable.getStatus()));
077        }
078        bo.setId(immutable.getId());
079        bo.setEntityId(immutable.getEntityId());
080        bo.setCountryCode(immutable.getCountryCode());
081        if (immutable.getStartDate() != null) {
082            bo.setStartDateValue(new Timestamp(immutable.getStartDate().getMillis()));
083        }
084        if (immutable.getEndDate() != null) {
085            bo.setEndDateValue(new Timestamp(immutable.getEndDate().getMillis()));
086        }
087        bo.setActive(immutable.isActive());
088        bo.setVersionNumber(immutable.getVersionNumber());
089        bo.setObjectId(immutable.getObjectId());
090        return bo;
091    }
092
093    @Override
094    public EntityCitizenshipStatusBo getStatus() {
095        return this.status;
096    }
097
098    @Override
099    public String getId() {
100        return id;
101    }
102
103    public void setId(String id) {
104        this.id = id;
105    }
106
107    public void setStatus(EntityCitizenshipStatusBo status) {
108        this.status = status;
109    }
110}