View Javadoc
1   /**
2    * Copyright 2005-2014 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.kuali.rice.kim.api.identity.affiliation.EntityAffiliation;
28  import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
29  
30  @Entity
31  @Table(name = "KRIM_ENTITY_AFLTN_T")
32  public class EntityAffiliationBo extends EntityAffiliationBase {
33  
34      private static final long serialVersionUID = 0L;
35  
36      @PortableSequenceGenerator(name = "KRIM_ENTITY_AFLTN_ID_S")
37      @GeneratedValue(generator = "KRIM_ENTITY_AFLTN_ID_S")
38      @Id
39      @Column(name = "ENTITY_AFLTN_ID")
40      private String id;
41  
42      @ManyToOne(targetEntity = EntityAffiliationTypeBo.class, cascade = { CascadeType.REFRESH })
43      @JoinColumn(name = "AFLTN_TYP_CD", referencedColumnName = "AFLTN_TYP_CD", insertable = false, updatable = false)
44      private EntityAffiliationTypeBo affiliationType;
45  
46      public static EntityAffiliation to(EntityAffiliationBo bo) {
47          if (bo == null) {
48              return null;
49          }
50          return EntityAffiliation.Builder.create(bo).build();
51      }
52  
53      /**
54       * Creates a EntityAffiliationBo business object from an immutable representation of a EntityAffiliation.
55       *
56       * @param immutable an immutable EntityAffiliation
57       * @return a EntityAffiliationBo
58       */
59      public static EntityAffiliationBo from(EntityAffiliation immutable) {
60          if (immutable == null) {
61              return null;
62          }
63          EntityAffiliationBo bo = new EntityAffiliationBo();
64          bo.setActive(immutable.isActive());
65          if (immutable.getAffiliationType() != null) {
66              bo.setAffiliationTypeCode(immutable.getAffiliationType().getCode());
67              bo.setAffiliationType(EntityAffiliationTypeBo.from(immutable.getAffiliationType()));
68          }
69          bo.setId(immutable.getId());
70          bo.setCampusCode(immutable.getCampusCode());
71          bo.setEntityId(immutable.getEntityId());
72          bo.setActive(immutable.isActive());
73          bo.setDefaultValue(immutable.isDefaultValue());
74          bo.setVersionNumber(immutable.getVersionNumber());
75          return bo;
76      }
77  
78      @Override
79      public EntityAffiliationTypeBo getAffiliationType() {
80          return this.affiliationType;
81      }
82  
83      public void setAffiliationType(EntityAffiliationTypeBo affiliationType) {
84          this.affiliationType = affiliationType;
85      }
86  
87      @Override
88      public String getId() {
89          return id;
90      }
91  
92      public void setId(String id) {
93          this.id = id;
94      }
95  }