1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.businessobject;
17
18 import java.util.HashMap;
19 import java.util.Map;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.kuali.ole.sys.context.SpringContext;
23 import org.kuali.rice.core.api.mo.common.active.MutableInactivatable;
24 import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
25 import org.kuali.rice.krad.service.KualiModuleService;
26 import org.kuali.rice.krad.service.ModuleService;
27 import org.kuali.rice.krad.util.ObjectUtils;
28 import org.kuali.rice.location.api.LocationConstants;
29 import org.kuali.rice.location.framework.country.CountryEbo;
30 import org.kuali.rice.location.framework.state.StateEbo;
31
32 public class TaxRegionState extends PersistableBusinessObjectBase implements MutableInactivatable {
33
34 protected String postalCountryCode;
35 protected String stateCode;
36 protected String taxRegionCode;
37 protected boolean active;
38
39 protected CountryEbo country;
40 protected StateEbo state;
41 protected TaxRegion taxRegion;
42
43 @Override
44 public boolean isActive() {
45 return active;
46 }
47
48 @Override
49 public void setActive(boolean active) {
50 this.active = active;
51 }
52
53 public String getStateCode() {
54 return stateCode;
55 }
56
57 public void setStateCode(String stateCode) {
58 this.stateCode = stateCode;
59 }
60
61 public TaxRegion getTaxRegion() {
62 if(ObjectUtils.isNull(taxRegion)){
63 this.refreshReferenceObject("taxRegion");
64 }
65 return taxRegion;
66 }
67
68 public void setTaxRegion(TaxRegion taxRegion) {
69 this.taxRegion = taxRegion;
70 }
71
72 public String getTaxRegionCode() {
73 return taxRegionCode;
74 }
75
76 public void setTaxRegionCode(String taxRegionCode) {
77 this.taxRegionCode = taxRegionCode;
78 }
79
80 public StateEbo getState() {
81 if ( StringUtils.isBlank(stateCode) || StringUtils.isBlank(postalCountryCode ) ) {
82 state = null;
83 } else {
84 if ( state == null || !StringUtils.equals( state.getCode(),stateCode) || !StringUtils.equals(state.getCountryCode(), postalCountryCode ) ) {
85 ModuleService moduleService = SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(StateEbo.class);
86 if ( moduleService != null ) {
87 Map<String,Object> keys = new HashMap<String, Object>(2);
88 keys.put(LocationConstants.PrimaryKeyConstants.COUNTRY_CODE, postalCountryCode);
89 keys.put(LocationConstants.PrimaryKeyConstants.CODE, stateCode);
90 state = moduleService.getExternalizableBusinessObject(StateEbo.class, keys);
91 } else {
92 throw new RuntimeException( "CONFIGURATION ERROR: No responsible module found for EBO class. Unable to proceed." );
93 }
94 }
95 }
96 return state;
97 }
98
99 public void setState(StateEbo state) {
100 this.state = state;
101 }
102
103
104
105
106
107
108 public String getPostalCountryCode() {
109 return postalCountryCode;
110 }
111
112
113
114
115
116
117 public void setPostalCountryCode(String postalCountryCode) {
118 this.postalCountryCode = postalCountryCode;
119 }
120
121
122
123
124
125 public CountryEbo getCountry() {
126 if ( StringUtils.isBlank(postalCountryCode) ) {
127 country = null;
128 } else {
129 if ( country == null || !StringUtils.equals( country.getCode(),postalCountryCode) ) {
130 ModuleService moduleService = SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(CountryEbo.class);
131 if ( moduleService != null ) {
132 Map<String,Object> keys = new HashMap<String, Object>(1);
133 keys.put(LocationConstants.PrimaryKeyConstants.CODE, postalCountryCode);
134 country = moduleService.getExternalizableBusinessObject(CountryEbo.class, keys);
135 } else {
136 throw new RuntimeException( "CONFIGURATION ERROR: No responsible module found for EBO class. Unable to proceed." );
137 }
138 }
139 }
140 return country;
141 }
142
143
144
145
146
147 public void setCountry(CountryEbo country) {
148 this.country = country;
149 }
150 }