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.county;
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.county.County;
21  import org.kuali.rice.location.framework.county.CountyEbo;
22  import org.kuali.rice.location.impl.country.CountryBo;
23  import org.kuali.rice.location.impl.state.StateBo;
24  
25  import javax.persistence.Column;
26  import javax.persistence.Convert;
27  import javax.persistence.Entity;
28  import javax.persistence.FetchType;
29  import javax.persistence.Id;
30  import javax.persistence.IdClass;
31  import javax.persistence.JoinColumn;
32  import javax.persistence.JoinColumns;
33  import javax.persistence.ManyToOne;
34  import javax.persistence.Table;
35  
36  @IdClass(CountyId.class)
37  @Entity
38  @Table(name = "KRLC_CNTY_T")
39  public class CountyBo extends PersistableBusinessObjectBase implements CountyEbo {
40  
41      private static final long serialVersionUID = -5988292910408345009L;
42  
43      @Id
44      @Column(name = "COUNTY_CD")
45      private String code;
46  
47      @Id
48      @Column(name = "POSTAL_CNTRY_CD")
49      private String countryCode;
50  
51      @Id
52      @Column(name = "STATE_CD")
53      private String stateCode;
54  
55      @Column(name = "COUNTY_NM")
56      private String name;
57  
58      @Column(name = "ACTV_IND")
59      @Convert(converter = BooleanYNConverter.class)
60      private boolean active;
61  
62      @ManyToOne(targetEntity = CountryBo.class, fetch = FetchType.EAGER)
63      @JoinColumn(name = "POSTAL_CNTRY_CD", insertable = false, updatable = false)
64      private CountryBo country;
65  
66      @ManyToOne(targetEntity = StateBo.class, fetch = FetchType.EAGER)
67      @JoinColumns(value = {
68              @JoinColumn(name = "STATE_CD", referencedColumnName = "POSTAL_STATE_CD", insertable = false, updatable = false),
69              @JoinColumn(name = "POSTAL_CNTRY_CD", referencedColumnName = "POSTAL_CNTRY_CD", insertable = false, updatable = false)
70      })
71      private StateBo state;
72  
73      @Override
74      public String getCode() {
75          return code;
76      }
77  
78      public void setCode(String code) {
79          this.code = code;
80      }
81  
82      @Override
83      public String getCountryCode() {
84          return countryCode;
85      }
86  
87      public void setCountryCode(String countryCode) {
88          this.countryCode = countryCode;
89      }
90  
91      @Override
92      public String getStateCode() {
93          return stateCode;
94      }
95  
96      public void setStateCode(String stateCode) {
97          this.stateCode = stateCode;
98      }
99  
100     @Override
101     public String getName() {
102         return name;
103     }
104 
105     public void setName(String name) {
106         this.name = name;
107     }
108 
109     @Override
110     public boolean isActive() {
111         return active;
112     }
113 
114     @Override
115     public void setActive(boolean active) {
116         this.active = active;
117     }
118 
119     public CountryBo getCountry() {
120         return country;
121     }
122 
123     public void setCountry(CountryBo country) {
124         this.country = country;
125     }
126 
127     public StateBo getState() {
128         return state;
129     }
130 
131     public void setState(StateBo state) {
132         this.state = state;
133     }
134 
135     /**
136      * Converts a mutable bo to its immutable counterpart
137      * @param bo the mutable business object
138      * @return An immutable County if the passed in mutable is not null.  If the mutable reference was null,
139      * then null is returned.
140      */
141     public static County to(CountyBo bo) {
142         if (bo == null) {
143             return null;
144         }
145 
146         return County.Builder.create(bo).build();
147     }
148 
149     /**
150      * Converts a immutable object to its mutable counterpart
151      * @param im immutable object
152      * @return a new mutable CountyBo if the passed in immutable is not null.  If the immutable reference was null,
153      * then null is returned.
154      */
155     public static CountyBo from(County im) {
156         if (im == null) {
157             return null;
158         }
159 
160         CountyBo bo = new CountyBo();
161         bo.code = im.getCode();
162         bo.name = im.getName();
163         bo.countryCode = im.getCountryCode();
164         bo.stateCode = im.getStateCode();
165         bo.active = im.isActive();
166         bo.versionNumber = im.getVersionNumber();
167 
168         return bo;
169     }
170 }
171