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.location.api.LocationConstants;
28  import org.kuali.rice.location.framework.country.CountryEbo;
29  import org.kuali.rice.location.framework.county.CountyEbo;
30  
31  public class TaxRegionCounty extends PersistableBusinessObjectBase implements MutableInactivatable {
32  
33      protected String postalCountryCode;
34  	protected String countyCode;
35  	protected String stateCode;
36  	protected String taxRegionCode;
37  	protected boolean active;
38  
39  	protected CountryEbo country;
40  	protected CountyEbo county;
41  	protected TaxRegion taxRegion;
42  	
43  	public String getCountyCode() {
44  		return countyCode;
45  	}
46  	public void setCountyCode(String countyCode) {
47  		this.countyCode = countyCode;
48  	}
49  	@Override
50  	public boolean isActive() {
51  		return active;
52  	}
53  	@Override
54  	public void setActive(boolean active) {
55  		this.active = active;
56  	}
57  	public TaxRegion getTaxRegion() {
58          return taxRegion;
59      }
60      public void setTaxRegion(TaxRegion taxRegion) {
61          this.taxRegion = taxRegion;
62      }
63      public String getStateCode() {
64  		return stateCode;
65  	}
66  	public void setStateCode(String stateCode) {
67  		this.stateCode = stateCode;
68  	}
69  	public String getTaxRegionCode() {
70  		return taxRegionCode;
71  	}
72  	public void setTaxRegionCode(String taxRegionCode) {
73  		this.taxRegionCode = taxRegionCode;
74  	}
75  	
76  	public CountyEbo getCounty() {
77          if ( StringUtils.isBlank(postalCountryCode) || StringUtils.isBlank(stateCode) || StringUtils.isBlank(countyCode) ) {
78              county = null;
79          } else {
80              if ( county == null
81                      || !StringUtils.equals( county.getCode(),countyCode)
82                      || !StringUtils.equals( county.getStateCode(), stateCode )
83                      || !StringUtils.equals( county.getCountryCode(), postalCountryCode )) {
84                  ModuleService moduleService = SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(CountyEbo.class);
85                  if ( moduleService != null ) {
86                      Map<String,Object> keys = new HashMap<String, Object>(3);
87                      keys.put(LocationConstants.PrimaryKeyConstants.COUNTRY_CODE, postalCountryCode);
88                      keys.put(LocationConstants.PrimaryKeyConstants.STATE_CODE, stateCode);
89                      keys.put(LocationConstants.PrimaryKeyConstants.CODE, countyCode);
90                      county = moduleService.getExternalizableBusinessObject(CountyEbo.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 county;
97  	}
98  	public void setCounty(CountyEbo county) {
99  		this.county = county;
100 	}
101     /**
102      * Gets the postalCountryCode attribute. 
103      * @return Returns the postalCountryCode.
104      */
105     public String getPostalCountryCode() {
106         return postalCountryCode;
107     }
108     /**
109      * Sets the postalCountryCode attribute value.
110      * @param postalCountryCode The postalCountryCode to set.
111      */
112     public void setPostalCountryCode(String postalCountryCode) {
113         this.postalCountryCode = postalCountryCode;
114     }
115     /**
116      * Gets the country attribute. 
117      * @return Returns the country.
118      */
119     public CountryEbo getCountry() {
120         if ( StringUtils.isBlank(postalCountryCode) ) {
121             country = null;
122         } else {
123             if ( country == null || !StringUtils.equals( country.getCode(),postalCountryCode) ) {
124                 ModuleService moduleService = SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(CountryEbo.class);
125                 if ( moduleService != null ) {
126                     Map<String,Object> keys = new HashMap<String, Object>(1);
127                     keys.put(LocationConstants.PrimaryKeyConstants.CODE, postalCountryCode);
128                     country = moduleService.getExternalizableBusinessObject(CountryEbo.class, keys);
129                 } else {
130                     throw new RuntimeException( "CONFIGURATION ERROR: No responsible module found for EBO class.  Unable to proceed." );
131                 }
132             }
133         }
134         return country;
135     }
136     /**
137      * Sets the country attribute value.
138      * @param country The country to set.
139      */
140     public void setCountry(CountryEbo country) {
141         this.country = country;
142     }
143 }