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.postalcode.PostalCodeEbo;
31  
32  public class TaxRegionPostalCode extends PersistableBusinessObjectBase implements MutableInactivatable {
33  
34      protected String postalCountryCode;
35  	protected String postalCode;
36  	protected String taxRegionCode;
37  	protected boolean active;
38  
39  	protected CountryEbo country;
40  	protected PostalCodeEbo postalZip;
41  	protected TaxRegion taxRegion;
42  
43  	public PostalCodeEbo getPostalZip() {
44          if ( StringUtils.isBlank(postalCode) || StringUtils.isBlank(postalCountryCode) ) {
45              postalZip = null;
46          } else {
47              if ( postalZip == null || !StringUtils.equals( postalZip.getCode(),postalCode) || !StringUtils.equals(postalZip.getCountryCode(), postalCountryCode ) ) {
48                  ModuleService moduleService = SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(PostalCodeEbo.class);
49                  if ( moduleService != null ) {
50                      Map<String,Object> keys = new HashMap<String, Object>(2);
51                      keys.put(LocationConstants.PrimaryKeyConstants.COUNTRY_CODE, postalCountryCode);
52                      keys.put(LocationConstants.PrimaryKeyConstants.CODE, postalCode);
53                      postalZip = moduleService.getExternalizableBusinessObject(PostalCodeEbo.class, keys);
54                  } else {
55                      throw new RuntimeException( "CONFIGURATION ERROR: No responsible module found for EBO class.  Unable to proceed." );
56                  }
57              }
58          }
59  		return postalZip;
60  	}
61  	public void setPostalZip(PostalCodeEbo postalZip) {
62  		this.postalZip = postalZip;
63  	}
64  	public TaxRegion getTaxRegion() {
65          if(StringUtils.isNotBlank(taxRegionCode) && ObjectUtils.isNull(taxRegion)){
66              this.refreshReferenceObject("taxRegion");
67          }	    
68          return taxRegion;
69      }
70      public void setTaxRegion(TaxRegion taxRegion) {
71          this.taxRegion = taxRegion;
72      }
73      @Override
74      public boolean isActive() {
75  		return active;
76  	}
77  	@Override
78  	public void setActive(boolean active) {
79  		this.active = active;
80  	}
81  	public String getPostalCode() {
82  		return postalCode;
83  	}
84  	public void setPostalCode(String postalCode) {
85  		this.postalCode = postalCode;
86  	}
87  	public String getTaxRegionCode() {
88  		return taxRegionCode;
89  	}
90  	public void setTaxRegionCode(String taxRegionCode) {
91  		this.taxRegionCode = taxRegionCode;
92  	}
93      public String getPostalCountryCode() {
94          return postalCountryCode;
95      }
96      public void setPostalCountryCode(String postalCountryCode) {
97          this.postalCountryCode = postalCountryCode;
98      }
99      public CountryEbo getCountry() {
100         if ( StringUtils.isBlank(postalCountryCode) ) {
101             country = null;
102         } else {
103             if ( country == null || !StringUtils.equals( country.getCode(),postalCountryCode) ) {
104                 ModuleService moduleService = SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(CountryEbo.class);
105                 if ( moduleService != null ) {
106                     Map<String,Object> keys = new HashMap<String, Object>(1);
107                     keys.put(LocationConstants.PrimaryKeyConstants.CODE, postalCountryCode);
108                     country = moduleService.getExternalizableBusinessObject(CountryEbo.class, keys);
109                 } else {
110                     throw new RuntimeException( "CONFIGURATION ERROR: No responsible module found for EBO class.  Unable to proceed." );
111                 }
112             }
113         }
114         return country;
115     }
116     public void setCountry(CountryEbo country) {
117         this.country = country;
118     }
119 }