View Javadoc
1   /*
2    * Copyright 2008-2009 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.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      * Gets the postalCountryCode attribute.
105      * 
106      * @return Returns the postalCountryCode.
107      */
108     public String getPostalCountryCode() {
109         return postalCountryCode;
110     }
111 
112     /**
113      * Sets the postalCountryCode attribute value.
114      * 
115      * @param postalCountryCode The postalCountryCode to set.
116      */
117     public void setPostalCountryCode(String postalCountryCode) {
118         this.postalCountryCode = postalCountryCode;
119     }
120 
121     /**
122      * Gets the country attribute. 
123      * @return Returns the country.
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      * Sets the country attribute value.
145      * @param country The country to set.
146      */
147     public void setCountry(CountryEbo country) {
148         this.country = country;
149     }
150 }