001/* 002 * Copyright 2008-2009 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.ole.sys.businessobject; 017 018import java.util.HashMap; 019import java.util.Map; 020 021import org.apache.commons.lang.StringUtils; 022import org.kuali.ole.sys.context.SpringContext; 023import org.kuali.rice.core.api.mo.common.active.MutableInactivatable; 024import org.kuali.rice.krad.bo.PersistableBusinessObjectBase; 025import org.kuali.rice.krad.service.KualiModuleService; 026import org.kuali.rice.krad.service.ModuleService; 027import org.kuali.rice.krad.util.ObjectUtils; 028import org.kuali.rice.location.api.LocationConstants; 029import org.kuali.rice.location.framework.country.CountryEbo; 030import org.kuali.rice.location.framework.postalcode.PostalCodeEbo; 031 032public class TaxRegionPostalCode extends PersistableBusinessObjectBase implements MutableInactivatable { 033 034 protected String postalCountryCode; 035 protected String postalCode; 036 protected String taxRegionCode; 037 protected boolean active; 038 039 protected CountryEbo country; 040 protected PostalCodeEbo postalZip; 041 protected TaxRegion taxRegion; 042 043 public PostalCodeEbo getPostalZip() { 044 if ( StringUtils.isBlank(postalCode) || StringUtils.isBlank(postalCountryCode) ) { 045 postalZip = null; 046 } else { 047 if ( postalZip == null || !StringUtils.equals( postalZip.getCode(),postalCode) || !StringUtils.equals(postalZip.getCountryCode(), postalCountryCode ) ) { 048 ModuleService moduleService = SpringContext.getBean(KualiModuleService.class).getResponsibleModuleService(PostalCodeEbo.class); 049 if ( moduleService != null ) { 050 Map<String,Object> keys = new HashMap<String, Object>(2); 051 keys.put(LocationConstants.PrimaryKeyConstants.COUNTRY_CODE, postalCountryCode); 052 keys.put(LocationConstants.PrimaryKeyConstants.CODE, postalCode); 053 postalZip = moduleService.getExternalizableBusinessObject(PostalCodeEbo.class, keys); 054 } else { 055 throw new RuntimeException( "CONFIGURATION ERROR: No responsible module found for EBO class. Unable to proceed." ); 056 } 057 } 058 } 059 return postalZip; 060 } 061 public void setPostalZip(PostalCodeEbo postalZip) { 062 this.postalZip = postalZip; 063 } 064 public TaxRegion getTaxRegion() { 065 if(StringUtils.isNotBlank(taxRegionCode) && ObjectUtils.isNull(taxRegion)){ 066 this.refreshReferenceObject("taxRegion"); 067 } 068 return taxRegion; 069 } 070 public void setTaxRegion(TaxRegion taxRegion) { 071 this.taxRegion = taxRegion; 072 } 073 @Override 074 public boolean isActive() { 075 return active; 076 } 077 @Override 078 public void setActive(boolean active) { 079 this.active = active; 080 } 081 public String getPostalCode() { 082 return postalCode; 083 } 084 public void setPostalCode(String postalCode) { 085 this.postalCode = postalCode; 086 } 087 public String getTaxRegionCode() { 088 return taxRegionCode; 089 } 090 public void setTaxRegionCode(String taxRegionCode) { 091 this.taxRegionCode = taxRegionCode; 092 } 093 public String getPostalCountryCode() { 094 return postalCountryCode; 095 } 096 public void setPostalCountryCode(String postalCountryCode) { 097 this.postalCountryCode = postalCountryCode; 098 } 099 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}