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.affiliation;
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.affiliation.EntityAffiliation;
030import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
031
032@Entity
033@Table(name = "KRIM_ENTITY_AFLTN_T")
034public class EntityAffiliationBo extends EntityAffiliationBase {
035
036    private static final long serialVersionUID = 0L;
037
038    @PortableSequenceGenerator(name = "KRIM_ENTITY_AFLTN_ID_S")
039    @GeneratedValue(generator = "KRIM_ENTITY_AFLTN_ID_S")
040    @Id
041    @Column(name = "ENTITY_AFLTN_ID")
042    private String id;
043
044    @JoinFetch(value= JoinFetchType.OUTER)
045    @ManyToOne(targetEntity = EntityAffiliationTypeBo.class, cascade = { CascadeType.REFRESH })
046    @JoinColumn(name = "AFLTN_TYP_CD", referencedColumnName = "AFLTN_TYP_CD", insertable = false, updatable = false)
047    private EntityAffiliationTypeBo affiliationType;
048
049    public static EntityAffiliation to(EntityAffiliationBo bo) {
050        if (bo == null) {
051            return null;
052        }
053        return EntityAffiliation.Builder.create(bo).build();
054    }
055
056    /**
057     * Creates a EntityAffiliationBo business object from an immutable representation of a EntityAffiliation.
058     *
059     * @param immutable an immutable EntityAffiliation
060     * @return a EntityAffiliationBo
061     */
062    public static EntityAffiliationBo from(EntityAffiliation immutable) {
063        if (immutable == null) {
064            return null;
065        }
066        EntityAffiliationBo bo = new EntityAffiliationBo();
067        bo.setActive(immutable.isActive());
068        if (immutable.getAffiliationType() != null) {
069            bo.setAffiliationTypeCode(immutable.getAffiliationType().getCode());
070            bo.setAffiliationType(EntityAffiliationTypeBo.from(immutable.getAffiliationType()));
071        }
072        bo.setId(immutable.getId());
073        bo.setCampusCode(immutable.getCampusCode());
074        bo.setEntityId(immutable.getEntityId());
075        bo.setActive(immutable.isActive());
076        bo.setDefaultValue(immutable.isDefaultValue());
077        bo.setVersionNumber(immutable.getVersionNumber());
078        return bo;
079    }
080
081    @Override
082    public EntityAffiliationTypeBo getAffiliationType() {
083        return this.affiliationType;
084    }
085
086    public void setAffiliationType(EntityAffiliationTypeBo affiliationType) {
087        this.affiliationType = affiliationType;
088    }
089
090    @Override
091    public String getId() {
092        return id;
093    }
094
095    public void setId(String id) {
096        this.id = id;
097    }
098}