001    /**
002     * Copyright 2005-2014 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.bo.ui;
017    
018    import org.hibernate.annotations.Fetch;
019    import org.hibernate.annotations.FetchMode;
020    import org.hibernate.annotations.GenericGenerator;
021    import org.hibernate.annotations.Parameter;
022    import org.kuali.rice.kim.impl.identity.affiliation.EntityAffiliationTypeBo;
023    import org.kuali.rice.krad.util.ObjectUtils;
024    
025    import javax.persistence.CascadeType;
026    import javax.persistence.Column;
027    import javax.persistence.Entity;
028    import javax.persistence.FetchType;
029    import javax.persistence.GeneratedValue;
030    import javax.persistence.Id;
031    import javax.persistence.IdClass;
032    import javax.persistence.JoinColumn;
033    import javax.persistence.JoinColumns;
034    import javax.persistence.ManyToOne;
035    import javax.persistence.OneToMany;
036    import javax.persistence.Table;
037    import javax.persistence.Transient;
038    import java.util.ArrayList;
039    import java.util.List;
040    
041    /**
042     * This is a description of what this class does - shyu don't forget to fill this in. 
043     * 
044     * @author Kuali Rice Team (rice.collab@kuali.org)
045     *
046     */
047    @IdClass(PersonDocumentAffiliationId.class)
048    @Entity
049    @Table(name = "KRIM_PND_AFLTN_MT")
050    public class PersonDocumentAffiliation extends PersonDocumentBoDefaultBase {
051            private static final long serialVersionUID = 1L;
052    
053            @Id
054            @GeneratedValue(generator="KRIM_ENTITY_AFLTN_ID_S")
055            @GenericGenerator(name="KRIM_ENTITY_AFLTN_ID_S",strategy="org.kuali.rice.core.jpa.spring.RiceNumericStringSequenceStyleGenerator",parameters={
056                            @Parameter(name="sequence_name",value="KRIM_ENTITY_AFLTN_ID_S"),
057                            @Parameter(name="value_column",value="id")
058                    })
059            @Column(name = "ENTITY_AFLTN_ID")
060            protected String entityAffiliationId;
061    
062            @Column(name = "AFLTN_TYP_CD")
063            protected String affiliationTypeCode;
064    
065            @Column(name = "CAMPUS_CD")
066            protected String campusCode;
067    
068            @ManyToOne(targetEntity=EntityAffiliationTypeBo.class, fetch = FetchType.EAGER, cascade = {})
069            @JoinColumn(name = "AFLTN_TYP_CD", insertable = false, updatable = false)
070            protected EntityAffiliationTypeBo affiliationType;
071            @Transient
072            protected PersonDocumentEmploymentInfo newEmpInfo;
073    
074            @OneToMany(cascade={CascadeType.PERSIST,CascadeType.MERGE},fetch=FetchType.EAGER)
075            //@JoinColumn(name="ENTITY_AFLTN_ID", insertable=false, updatable=false)
076            @Fetch(value = FetchMode.SELECT)
077            @JoinColumns({
078                    @JoinColumn(name="FDOC_NBR",insertable=false,updatable=false),
079                    @JoinColumn(name="ENTITY_AFLTN_ID", insertable=false, updatable=false)
080            })
081            protected List<PersonDocumentEmploymentInfo> empInfos;
082    
083            public PersonDocumentAffiliation() {
084                    empInfos = new ArrayList<PersonDocumentEmploymentInfo>();
085                    setNewEmpInfo(new PersonDocumentEmploymentInfo());
086                    this.active = true;
087            }
088    
089            /**
090             * @see org.kuali.rice.kim.api.identity.EntityAffiliationContract#getAffiliationTypeCode()
091             */
092            public String getAffiliationTypeCode() {
093                    if(ObjectUtils.isNull(affiliationTypeCode))
094                            return "";
095                    return affiliationTypeCode;
096            }
097    
098            /**
099             * @see org.kuali.rice.kim.api.identity.EntityAffiliationContract#getCampusCode()
100             */
101            public String getCampusCode() {
102                    return campusCode;
103            }
104    
105            /**
106             * @see org.kuali.rice.kim.api.identity.EntityAffiliationContract#getEntityAffiliationId()
107             */
108            public String getEntityAffiliationId() {
109                    if(ObjectUtils.isNull(entityAffiliationId))
110                            return "";
111                    return entityAffiliationId;
112            }
113    
114            /**
115             * @see org.kuali.rice.kim.api.identity.EntityAffiliationContract#setAffiliationTypeCode(java.lang.String)
116             */
117            public void setAffiliationTypeCode(String affiliationTypeCode) {
118                    this.affiliationTypeCode = affiliationTypeCode;
119            }
120    
121            /**
122             * @see org.kuali.rice.kim.api.identity.EntityAffiliationContract#setCampusCode(java.lang.String)
123             */
124            public void setCampusCode(String campusCode) {
125                    this.campusCode = campusCode;
126            }
127    
128            public void setEntityAffiliationId(String entityAffiliationId) {
129                    this.entityAffiliationId = entityAffiliationId;
130            }
131    
132            public PersonDocumentEmploymentInfo getNewEmpInfo() {
133                    return this.newEmpInfo;
134            }
135    
136            public void setNewEmpInfo(PersonDocumentEmploymentInfo newEmpInfo) {
137                    this.newEmpInfo = newEmpInfo;
138            }
139    
140            public List<PersonDocumentEmploymentInfo> getEmpInfos() {
141                    return this.empInfos;
142            }
143    
144            public void setEmpInfos(List<PersonDocumentEmploymentInfo> empInfos) {
145                    this.empInfos = empInfos;
146            }
147    
148            public EntityAffiliationTypeBo getAffiliationType() {
149                    if(ObjectUtils.isNull(affiliationType))
150                            return null;
151                    return this.affiliationType;
152            }
153    
154            public boolean isEmploymentAffiliationType() {
155                    if(ObjectUtils.isNull(affiliationType))
156                            return false;
157                    return this.affiliationType.isEmploymentAffiliationType();
158            }
159             
160            public void setAffiliationType(EntityAffiliationTypeBo affiliationType) {
161                    this.affiliationType = affiliationType;
162            }
163    
164    }