View Javadoc
1   /**
2    * Copyright 2005-2015 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.location.impl.state;
17  
18  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
19  import org.kuali.rice.krad.data.jpa.converters.BooleanYNConverter;
20  import org.kuali.rice.location.api.state.State;
21  import org.kuali.rice.location.framework.state.StateEbo;
22  import org.kuali.rice.location.impl.country.CountryBo;
23  
24  import javax.persistence.Column;
25  import javax.persistence.Convert;
26  import javax.persistence.Entity;
27  import javax.persistence.FetchType;
28  import javax.persistence.Id;
29  import javax.persistence.IdClass;
30  import javax.persistence.JoinColumn;
31  import javax.persistence.ManyToOne;
32  import javax.persistence.Table;
33  
34  @IdClass(StateId.class)
35  @Entity
36  @Table(name = "KRLC_ST_T")
37  public class StateBo extends PersistableBusinessObjectBase implements StateEbo {
38  
39      private static final long serialVersionUID = 6755670624476337736L;
40  
41      @Id
42      @Column(name = "POSTAL_STATE_CD")
43      private String code;
44  
45      @Id
46      @Column(name = "POSTAL_CNTRY_CD")
47      private String countryCode;
48  
49      @Column(name = "POSTAL_STATE_NM")
50      private String name;
51  
52      @Column(name = "ACTV_IND")
53      @Convert(converter = BooleanYNConverter.class)
54      private boolean active;
55  
56      @ManyToOne(targetEntity = CountryBo.class, fetch = FetchType.EAGER)
57      @JoinColumn(name = "POSTAL_CNTRY_CD", insertable = false, updatable = false)
58      private CountryBo country;
59  
60      @Override
61      public String getCode() {
62          return code;
63      }
64  
65      public void setCode(String code) {
66          this.code = code;
67      }
68  
69      @Override
70      public String getCountryCode() {
71          return countryCode;
72      }
73  
74      public void setCountryCode(String countryCode) {
75          this.countryCode = countryCode;
76      }
77  
78      @Override
79      public String getName() {
80          return name;
81      }
82  
83      public void setName(String name) {
84          this.name = name;
85      }
86  
87      @Override
88      public boolean isActive() {
89          return active;
90      }
91  
92      @Override
93      public void setActive(boolean active) {
94          this.active = active;
95      }
96  
97      public CountryBo getCountry() {
98          return country;
99      }
100 
101     public void setCountry(CountryBo country) {
102         this.country = country;
103     }
104 
105     /**
106      * Converts a mutable bo to its immutable counterpart
107      * @param bo the mutable business object
108      * @return An immutable State if the passed in mutable is not null.  If the mutable reference was null, then null
109      * is returned.
110      */
111     public static State to(StateBo bo) {
112         if (bo == null) {
113             return null;
114         }
115 
116         return State.Builder.create(bo).build();
117     }
118 
119     /**
120      * Converts a immutable object to its mutable counterpart
121      * @param im immutable object
122      * @return a new mutable CountryBo if the passed in immutable is not null.  If the immutable reference was null,
123      * then null is returned.
124      */
125     public static StateBo from(State im) {
126         if (im == null) {
127             return null;
128         }
129 
130         StateBo bo = new StateBo();
131         bo.code = im.getCode();
132         bo.countryCode = im.getCountryCode();
133         bo.name = im.getName();
134         bo.active = im.isActive();
135         bo.versionNumber = im.getVersionNumber();
136 
137         return bo;
138     }
139 
140 }
141