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.location.impl.country;
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.country.Country;
21  import org.kuali.rice.location.framework.country.CountryEbo;
22  
23  import javax.persistence.Column;
24  import javax.persistence.Convert;
25  import javax.persistence.Entity;
26  import javax.persistence.Id;
27  import javax.persistence.Table;
28  
29  @Entity
30  @Table(name = "KRLC_CNTRY_T")
31  public class CountryBo extends PersistableBusinessObjectBase implements CountryEbo {
32  
33      private static final long serialVersionUID = 5725250018402409870L;
34  
35      @Id
36      @Column(name = "POSTAL_CNTRY_CD")
37      private String code;
38  
39      @Column(name = "ALT_POSTAL_CNTRY_CD")
40      private String alternateCode;
41  
42      @Column(name = "POSTAL_CNTRY_NM")
43      private String name;
44  
45      @Column(name = "PSTL_CNTRY_RSTRC_IND")
46      @Convert(converter = BooleanYNConverter.class)
47      private boolean restricted;
48  
49      @Column(name = "ACTV_IND")
50      @Convert(converter = BooleanYNConverter.class)
51      private boolean active;
52  
53      @Override
54      public String getCode() {
55          return code;
56      }
57  
58      public void setCode(String code) {
59          this.code = code;
60      }
61  
62      @Override
63      public String getAlternateCode() {
64          return alternateCode;
65      }
66  
67      public void setAlternateCode(String alternateCode) {
68          this.alternateCode = alternateCode;
69      }
70  
71      @Override
72      public String getName() {
73          return name;
74      }
75  
76      public void setName(String name) {
77          this.name = name;
78      }
79  
80      @Override
81      public boolean isRestricted() {
82          return restricted;
83      }
84  
85      public void setRestricted(boolean restricted) {
86          this.restricted = restricted;
87      }
88  
89      @Override
90      public boolean isActive() {
91          return active;
92      }
93  
94      @Override
95      public void setActive(boolean active) {
96          this.active = active;
97      }
98  
99      /**
100      * Converts a mutable CountryBo to an immutable Country representation.
101      * @param bo
102      * @return an immutable Country
103      */
104     public static Country to(CountryBo bo) {
105         if (bo == null) {
106             return null;
107         }
108         return Country.Builder.create(bo).build();
109     }
110 
111     /**
112      * Creates a CountryBo business object from an immutable representation of a Country.
113      * @param immutable an immutable Country
114      * @return a CountryBo
115      */
116     public static CountryBo from(Country immutable) {
117         if (immutable == null) {
118             return null;
119         }
120 
121         CountryBo bo = new CountryBo();
122         bo.code = immutable.getCode();
123         bo.alternateCode = immutable.getAlternateCode();
124         bo.name = immutable.getName();
125         bo.restricted = immutable.isRestricted();
126         bo.active = immutable.isActive();
127         bo.versionNumber = immutable.getVersionNumber();
128 
129         return bo;
130     }
131 }