| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.kns.service.impl; |
| 17 | |
|
| 18 | |
import java.util.HashMap; |
| 19 | |
import java.util.Map; |
| 20 | |
|
| 21 | |
import org.apache.commons.lang.StringUtils; |
| 22 | |
import org.apache.log4j.Logger; |
| 23 | |
import org.kuali.rice.kns.bo.PostalCode; |
| 24 | |
import org.kuali.rice.kns.service.CountryService; |
| 25 | |
import org.kuali.rice.kns.service.KualiModuleService; |
| 26 | |
import org.kuali.rice.kns.service.PostalCodeService; |
| 27 | |
import org.kuali.rice.kns.util.KNSPropertyConstants; |
| 28 | |
|
| 29 | 0 | public class PostalCodeServiceImpl implements PostalCodeService { |
| 30 | 0 | private static Logger LOG = Logger.getLogger(PostalCodeServiceImpl.class); |
| 31 | |
|
| 32 | |
private CountryService countryService; |
| 33 | |
private KualiModuleService kualiModuleService; |
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
public PostalCode getByPostalCodeInDefaultCountry(String postalZipCode) { |
| 39 | 0 | String postalCountryCode = countryService.getDefaultCountry().getPostalCountryCode(); |
| 40 | |
|
| 41 | 0 | return this.getByPrimaryId(postalCountryCode, postalZipCode); |
| 42 | |
} |
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
public PostalCode getByPrimaryId(String postalCountryCode, String postalCode) { |
| 48 | 0 | if (StringUtils.isBlank(postalCountryCode) || StringUtils.isBlank(postalCode)) { |
| 49 | 0 | LOG.debug("neither postalCountryCode nor postalCode can be empty String."); |
| 50 | 0 | return null; |
| 51 | |
} |
| 52 | |
|
| 53 | 0 | Map<String, Object> postalCodeMap = new HashMap<String, Object>(); |
| 54 | 0 | postalCodeMap.put(KNSPropertyConstants.POSTAL_COUNTRY_CODE, postalCountryCode); |
| 55 | 0 | postalCodeMap.put(KNSPropertyConstants.POSTAL_CODE, postalCode); |
| 56 | |
|
| 57 | 0 | return kualiModuleService.getResponsibleModuleService(PostalCode.class).getExternalizableBusinessObject(PostalCode.class, postalCodeMap); |
| 58 | |
} |
| 59 | |
|
| 60 | |
public PostalCode getByPostalCodeInDefaultCountryIfNecessary(String postalCode, PostalCode existingPostalCode) { |
| 61 | 0 | String postalCountryCode = countryService.getDefaultCountry().getPostalCountryCode(); |
| 62 | |
|
| 63 | 0 | return this.getByPrimaryIdIfNecessary(postalCountryCode, postalCode, existingPostalCode); |
| 64 | |
} |
| 65 | |
|
| 66 | |
public PostalCode getByPrimaryIdIfNecessary(String postalCountryCode, String postalCode, PostalCode existingPostalCode) { |
| 67 | 0 | if (existingPostalCode != null) { |
| 68 | 0 | String existingCountryCode = existingPostalCode.getPostalCountryCode(); |
| 69 | 0 | String existingPostalZipCode = existingPostalCode.getPostalCode(); |
| 70 | 0 | if (StringUtils.equals(postalCountryCode, existingCountryCode) && StringUtils.equals(postalCode, existingPostalZipCode)) { |
| 71 | 0 | return existingPostalCode; |
| 72 | |
} |
| 73 | |
} |
| 74 | |
|
| 75 | 0 | return this.getByPrimaryId(postalCountryCode, postalCode); |
| 76 | |
} |
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
public void setCountryService(CountryService countryService) { |
| 84 | 0 | this.countryService = countryService; |
| 85 | 0 | } |
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
public void setKualiModuleService(KualiModuleService kualiModuleService) { |
| 93 | 0 | this.kualiModuleService = kualiModuleService; |
| 94 | 0 | } |
| 95 | |
} |