1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.location.impl.postalcode;
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.postalcode.PostalCode;
21 import org.kuali.rice.location.framework.postalcode.PostalCodeEbo;
22 import org.kuali.rice.location.impl.country.CountryBo;
23 import org.kuali.rice.location.impl.county.CountyBo;
24 import org.kuali.rice.location.impl.state.StateBo;
25
26 import javax.persistence.Column;
27 import javax.persistence.Convert;
28 import javax.persistence.Entity;
29 import javax.persistence.FetchType;
30 import javax.persistence.Id;
31 import javax.persistence.IdClass;
32 import javax.persistence.JoinColumn;
33 import javax.persistence.JoinColumns;
34 import javax.persistence.ManyToOne;
35 import javax.persistence.Table;
36
37 @IdClass(PostalCodeId.class)
38 @Entity
39 @Table(name = "KRLC_PSTL_CD_T")
40 public class PostalCodeBo extends PersistableBusinessObjectBase implements PostalCodeEbo {
41
42 private static final long serialVersionUID = 3951927731999264335L;
43
44 @Id
45 @Column(name = "POSTAL_CD")
46 private String code;
47
48 @Id
49 @Column(name = "POSTAL_CNTRY_CD")
50 private String countryCode;
51
52 @Column(name = "POSTAL_CITY_NM")
53 private String cityName;
54
55 @Column(name = "POSTAL_STATE_CD")
56 private String stateCode;
57
58 @Column(name = "COUNTY_CD")
59 private String countyCode;
60
61 @Column(name = "ACTV_IND")
62 @Convert(converter = BooleanYNConverter.class)
63 private boolean active;
64
65 @ManyToOne(targetEntity = CountryBo.class, fetch = FetchType.EAGER)
66 @JoinColumn(name = "POSTAL_CNTRY_CD", insertable = false, updatable = false)
67 private CountryBo country;
68
69 @ManyToOne(targetEntity = StateBo.class, fetch = FetchType.EAGER)
70 @JoinColumns(value = {
71 @JoinColumn(name = "POSTAL_STATE_CD", referencedColumnName="POSTAL_STATE_CD", insertable = false, updatable = false),
72 @JoinColumn(name = "POSTAL_CNTRY_CD", referencedColumnName="POSTAL_CNTRY_CD",insertable = false, updatable = false)
73 })
74 private StateBo state;
75
76 @ManyToOne(targetEntity = CountyBo.class, fetch = FetchType.EAGER)
77 @JoinColumns(value = {
78 @JoinColumn(name = "COUNTY_CD", referencedColumnName="COUNTY_CD", insertable = false, updatable = false),
79 @JoinColumn(name="POSTAL_STATE_CD", referencedColumnName="STATE_CD", insertable = false, updatable = false),
80 @JoinColumn(name="POSTAL_CNTRY_CD", referencedColumnName="POSTAL_CNTRY_CD", insertable = false, updatable = false)
81 })
82 private CountyBo county;
83
84 @Override
85 public String getCode() {
86 return code;
87 }
88
89 public void setCode(String code) {
90 this.code = code;
91 }
92
93 @Override
94 public String getCountryCode() {
95 return countryCode;
96 }
97
98 public void setCountryCode(String countryCode) {
99 this.countryCode = countryCode;
100 }
101
102 @Override
103 public String getCityName() {
104 return cityName;
105 }
106
107 public void setCityName(String cityName) {
108 this.cityName = cityName;
109 }
110
111 @Override
112 public String getStateCode() {
113 return stateCode;
114 }
115
116 public void setStateCode(String stateCode) {
117 this.stateCode = stateCode;
118 }
119
120 @Override
121 public String getCountyCode() {
122 return countyCode;
123 }
124
125 public void setCountyCode(String countyCode) {
126 this.countyCode = countyCode;
127 }
128
129 @Override
130 public boolean isActive() {
131 return active;
132 }
133
134 @Override
135 public void setActive(boolean active) {
136 this.active = active;
137 }
138
139 public CountryBo getCountry() {
140 return country;
141 }
142
143 public void setCountry(CountryBo country) {
144 this.country = country;
145 }
146
147 public StateBo getState() {
148 return state;
149 }
150
151 public void setState(StateBo state) {
152 this.state = state;
153 }
154
155 public CountyBo getCounty() {
156 return county;
157 }
158
159 public void setCounty(CountyBo county) {
160 this.county = county;
161 }
162
163
164
165
166
167
168
169 public static PostalCode to(PostalCodeBo bo) {
170 if (bo == null) {
171 return null;
172 }
173
174 return PostalCode.Builder.create(bo).build();
175 }
176
177
178
179
180
181
182
183 public static PostalCodeBo from(PostalCode im) {
184 if (im == null) {
185 return null;
186 }
187
188 PostalCodeBo bo = new PostalCodeBo();
189 bo.code = im.getCode();
190 bo.countryCode = im.getCountryCode();
191 bo.cityName = im.getCityName();
192 bo.active = im.isActive();
193 bo.stateCode = im.getStateCode();
194 bo.cityName = im.getCityName();
195 bo.versionNumber = im.getVersionNumber();
196
197 return bo;
198 }
199 }
200