| 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.County; |
| 24 | |
import org.kuali.rice.kns.service.CountryService; |
| 25 | |
import org.kuali.rice.kns.service.CountyService; |
| 26 | |
import org.kuali.rice.kns.service.KualiModuleService; |
| 27 | |
import org.kuali.rice.kns.util.KNSPropertyConstants; |
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | 0 | public class CountyServiceImpl implements CountyService { |
| 33 | 0 | private static Logger LOG = Logger.getLogger(CountyServiceImpl.class); |
| 34 | |
|
| 35 | |
private CountryService countryService; |
| 36 | |
private KualiModuleService kualiModuleService; |
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
public County getByPrimaryId(String postalStateCode, String countyCode) { |
| 42 | 0 | String postalCountryCode = countryService.getDefaultCountry().getPostalCountryCode(); |
| 43 | |
|
| 44 | 0 | return this.getByPrimaryId(postalCountryCode, postalStateCode, countyCode); |
| 45 | |
} |
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
public County getByPrimaryId(String postalCountryCode, String postalStateCode, String countyCode) { |
| 51 | 0 | if (StringUtils.isBlank(postalCountryCode) || StringUtils.isBlank(postalStateCode) || StringUtils.isBlank(countyCode)) { |
| 52 | 0 | LOG.info("PostalCountryCode, postalStateCode and countycode can be empty String."); |
| 53 | 0 | return null; |
| 54 | |
} |
| 55 | |
|
| 56 | 0 | Map<String, Object> countyMap = new HashMap<String, Object>(); |
| 57 | 0 | countyMap.put(KNSPropertyConstants.POSTAL_COUNTRY_CODE, postalCountryCode); |
| 58 | 0 | countyMap.put(KNSPropertyConstants.STATE_CODE, postalStateCode); |
| 59 | 0 | countyMap.put(KNSPropertyConstants.COUNTY_CODE, countyCode); |
| 60 | |
|
| 61 | 0 | return kualiModuleService.getResponsibleModuleService(County.class).getExternalizableBusinessObject(County.class, countyMap); |
| 62 | |
} |
| 63 | |
|
| 64 | |
public County getByPrimaryIdIfNecessary(String postalStateCode, String countyCode, County existingCounty) { |
| 65 | 0 | String postalCountryCode = countryService.getDefaultCountry().getPostalCountryCode(); |
| 66 | |
|
| 67 | 0 | return this.getByPrimaryIdIfNecessary(postalCountryCode, postalStateCode, countyCode, existingCounty); |
| 68 | |
} |
| 69 | |
|
| 70 | |
public County getByPrimaryIdIfNecessary(String postalCountryCode, String postalStateCode, String countyCode, County existingCounty) { |
| 71 | 0 | if (existingCounty != null) { |
| 72 | 0 | String existingCountryCode = existingCounty.getPostalCountryCode(); |
| 73 | 0 | String existingStateCode = existingCounty.getStateCode(); |
| 74 | 0 | String existingCountyCode = existingCounty.getCountyCode(); |
| 75 | |
|
| 76 | 0 | if (StringUtils.equals(postalCountryCode, existingCountryCode) && StringUtils.equals(postalStateCode, existingStateCode) && StringUtils.equals(countyCode, existingCountyCode)) { |
| 77 | 0 | return existingCounty; |
| 78 | |
} |
| 79 | |
} |
| 80 | |
|
| 81 | 0 | return this.getByPrimaryId(postalCountryCode, postalStateCode, countyCode); |
| 82 | |
} |
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
public void setKualiModuleService(KualiModuleService kualiModuleService) { |
| 90 | 0 | this.kualiModuleService = kualiModuleService; |
| 91 | 0 | } |
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
public void setCountryService(CountryService countryService) { |
| 99 | 0 | this.countryService = countryService; |
| 100 | 0 | } |
| 101 | |
} |