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.citizenship;
17  
18  import java.sql.Timestamp;
19  
20  import javax.persistence.CascadeType;
21  import javax.persistence.Column;
22  import javax.persistence.Entity;
23  import javax.persistence.GeneratedValue;
24  import javax.persistence.Id;
25  import javax.persistence.JoinColumn;
26  import javax.persistence.ManyToOne;
27  import javax.persistence.Table;
28  import javax.persistence.Transient;
29  
30  import org.kuali.rice.kim.api.identity.citizenship.EntityCitizenship;
31  import org.kuali.rice.krad.data.jpa.PortableSequenceGenerator;
32  
33  @Entity
34  @Table(name = "KRIM_ENTITY_CTZNSHP_T")
35  public class EntityCitizenshipBo extends EntityCitizenshipBase {
36  
37      private static final long serialVersionUID = 1L;
38  
39      @PortableSequenceGenerator(name = "KRIM_ENTITY_CTZNSHP_ID_S")
40      @GeneratedValue(generator = "KRIM_ENTITY_CTZNSHP_ID_S")
41      @Id
42      @Column(name = "ENTITY_CTZNSHP_ID")
43      private String id;
44  
45      @ManyToOne(targetEntity = EntityCitizenshipStatusBo.class, cascade = { CascadeType.REFRESH })
46      @JoinColumn(name = "CTZNSHP_STAT_CD", referencedColumnName = "CTZNSHP_STAT_CD", insertable = false, updatable = false)
47      private EntityCitizenshipStatusBo status;
48  
49      @Transient
50      private EntityCitizenshipChangeTypeBo changeType;
51  
52      public static EntityCitizenship to(EntityCitizenshipBo bo) {
53          if (bo == null) {
54              return null;
55          }
56          return EntityCitizenship.Builder.create(bo).build();
57      }
58  
59      /**
60       * Creates a EntityCitizenshipBo business object from an immutable representation of a EntityCitizenship.
61       *
62       * @param immutable an immutable EntityCitizenship
63       * @return a EntityCitizenshipBo
64       */
65      public static EntityCitizenshipBo from(EntityCitizenship immutable) {
66          if (immutable == null) {
67              return null;
68          }
69          EntityCitizenshipBo bo = new EntityCitizenshipBo();
70          bo.setActive(immutable.isActive());
71          if (immutable.getStatus() != null) {
72              bo.setStatusCode(immutable.getStatus().getCode());
73              bo.setStatus(EntityCitizenshipStatusBo.from(immutable.getStatus()));
74          }
75          bo.setId(immutable.getId());
76          bo.setEntityId(immutable.getEntityId());
77          bo.setCountryCode(immutable.getCountryCode());
78          if (immutable.getStartDate() != null) {
79              bo.setStartDateValue(new Timestamp(immutable.getStartDate().getMillis()));
80          }
81          if (immutable.getEndDate() != null) {
82              bo.setEndDateValue(new Timestamp(immutable.getEndDate().getMillis()));
83          }
84          bo.setActive(immutable.isActive());
85          bo.setVersionNumber(immutable.getVersionNumber());
86          bo.setObjectId(immutable.getObjectId());
87          return bo;
88      }
89  
90      @Override
91      public EntityCitizenshipStatusBo getStatus() {
92          return this.status;
93      }
94  
95      @Override
96      public String getId() {
97          return id;
98      }
99  
100     public void setId(String id) {
101         this.id = id;
102     }
103 
104     public void setStatus(EntityCitizenshipStatusBo status) {
105         this.status = status;
106     }
107 }