View Javadoc
1   /**
2    * Copyright 2005-2016 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kim.impl.identity.affiliation;
17  
18  import javax.persistence.CascadeType;
19  import javax.persistence.Column;
20  import javax.persistence.Entity;
21  import javax.persistence.GeneratedValue;
22  import javax.persistence.Id;
23  import javax.persistence.JoinColumn;
24  import javax.persistence.ManyToOne;
25  import javax.persistence.Table;
26  
27  import org.eclipse.persistence.annotations.JoinFetch;
28  import org.eclipse.persistence.annotations.JoinFetchType;
29  import org.kuali.rice.kim.api.identity.affiliation.EntityAffiliation;
30  import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
31  
32  @Entity
33  @Table(name = "KRIM_ENTITY_AFLTN_T")
34  public class EntityAffiliationBo extends EntityAffiliationBase {
35  
36      private static final long serialVersionUID = 0L;
37  
38      @PortableSequenceGenerator(name = "KRIM_ENTITY_AFLTN_ID_S")
39      @GeneratedValue(generator = "KRIM_ENTITY_AFLTN_ID_S")
40      @Id
41      @Column(name = "ENTITY_AFLTN_ID")
42      private String id;
43  
44      @JoinFetch(value= JoinFetchType.OUTER)
45      @ManyToOne(targetEntity = EntityAffiliationTypeBo.class, cascade = { CascadeType.REFRESH })
46      @JoinColumn(name = "AFLTN_TYP_CD", referencedColumnName = "AFLTN_TYP_CD", insertable = false, updatable = false)
47      private EntityAffiliationTypeBo affiliationType;
48  
49      public static EntityAffiliation to(EntityAffiliationBo bo) {
50          if (bo == null) {
51              return null;
52          }
53          return EntityAffiliation.Builder.create(bo).build();
54      }
55  
56      /**
57       * Creates a EntityAffiliationBo business object from an immutable representation of a EntityAffiliation.
58       *
59       * @param immutable an immutable EntityAffiliation
60       * @return a EntityAffiliationBo
61       */
62      public static EntityAffiliationBo from(EntityAffiliation immutable) {
63          if (immutable == null) {
64              return null;
65          }
66          EntityAffiliationBo bo = new EntityAffiliationBo();
67          bo.setActive(immutable.isActive());
68          if (immutable.getAffiliationType() != null) {
69              bo.setAffiliationTypeCode(immutable.getAffiliationType().getCode());
70              bo.setAffiliationType(EntityAffiliationTypeBo.from(immutable.getAffiliationType()));
71          }
72          bo.setId(immutable.getId());
73          bo.setCampusCode(immutable.getCampusCode());
74          bo.setEntityId(immutable.getEntityId());
75          bo.setActive(immutable.isActive());
76          bo.setDefaultValue(immutable.isDefaultValue());
77          bo.setVersionNumber(immutable.getVersionNumber());
78          return bo;
79      }
80  
81      @Override
82      public EntityAffiliationTypeBo getAffiliationType() {
83          return this.affiliationType;
84      }
85  
86      public void setAffiliationType(EntityAffiliationTypeBo affiliationType) {
87          this.affiliationType = affiliationType;
88      }
89  
90      @Override
91      public String getId() {
92          return id;
93      }
94  
95      public void setId(String id) {
96          this.id = id;
97      }
98  }