| 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.ArrayList; |
| 19 | |
import java.util.HashMap; |
| 20 | |
import java.util.List; |
| 21 | |
import java.util.Map; |
| 22 | |
|
| 23 | |
import org.apache.commons.lang.StringUtils; |
| 24 | |
import org.apache.log4j.Logger; |
| 25 | |
import org.kuali.rice.kns.bo.Country; |
| 26 | |
import org.kuali.rice.kns.service.CountryService; |
| 27 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
| 28 | |
import org.kuali.rice.kns.service.KualiModuleService; |
| 29 | |
import org.kuali.rice.kns.util.KNSConstants; |
| 30 | |
import org.kuali.rice.kns.util.KNSPropertyConstants; |
| 31 | |
|
| 32 | 0 | public class CountryServiceImpl implements CountryService { |
| 33 | 0 | private static Logger LOG = Logger.getLogger(CountryServiceImpl.class); |
| 34 | |
|
| 35 | |
private KualiModuleService kualiModuleService; |
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
public Country getByPrimaryId(String postalCountryCode) { |
| 41 | 0 | if (StringUtils.isBlank(postalCountryCode)) { |
| 42 | 0 | LOG.debug("The postalCountryCode cannot be empty String."); |
| 43 | 0 | return null; |
| 44 | |
} |
| 45 | |
|
| 46 | 0 | Map<String, Object> postalCountryMap = new HashMap<String, Object>(); |
| 47 | 0 | postalCountryMap.put(KNSPropertyConstants.POSTAL_COUNTRY_CODE, postalCountryCode); |
| 48 | |
|
| 49 | 0 | return kualiModuleService.getResponsibleModuleService(Country.class).getExternalizableBusinessObject(Country.class, postalCountryMap); |
| 50 | |
} |
| 51 | |
|
| 52 | |
public Country getByPrimaryIdIfNecessary(String postalCountryCode, Country existingCountry) { |
| 53 | 0 | if (existingCountry != null) { |
| 54 | 0 | if (StringUtils.equals(postalCountryCode, existingCountry.getPostalCountryCode())) { |
| 55 | 0 | return existingCountry; |
| 56 | |
} |
| 57 | |
} |
| 58 | |
|
| 59 | 0 | return this.getByPrimaryId(postalCountryCode); |
| 60 | |
} |
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
public Country getByAlternatePostalCountryCode(String alternatePostalCountryCode) { |
| 66 | 0 | if (StringUtils.isBlank(alternatePostalCountryCode)) { |
| 67 | 0 | LOG.debug("The alternatePostalCountryCode cannot be empty String."); |
| 68 | 0 | return null; |
| 69 | |
} |
| 70 | |
|
| 71 | 0 | Map<String, Object> postalCountryMap = new HashMap<String, Object>(); |
| 72 | 0 | postalCountryMap.put(KNSPropertyConstants.ALTERNATE_POSTAL_COUNTRY_CODE, alternatePostalCountryCode); |
| 73 | |
|
| 74 | 0 | List<Country> countryList = kualiModuleService.getResponsibleModuleService(Country.class).getExternalizableBusinessObjectsList(Country.class, postalCountryMap); |
| 75 | 0 | if (countryList == null || countryList.isEmpty()) { |
| 76 | 0 | return null; |
| 77 | |
} |
| 78 | 0 | else if (countryList.size() == 1) { |
| 79 | 0 | return countryList.get(0); |
| 80 | |
} |
| 81 | 0 | else throw new IllegalStateException("Multiple countries found with same alternatePostalCountryCode"); |
| 82 | |
} |
| 83 | |
|
| 84 | |
|
| 85 | |
|
| 86 | |
|
| 87 | |
public Country getByAlternatePostalCountryCodeIfNecessary(String alternatePostalCountryCode, Country existingCountry) { |
| 88 | 0 | if (existingCountry != null) { |
| 89 | 0 | if (StringUtils.equals(alternatePostalCountryCode, existingCountry.getAlternatePostalCountryCode())) { |
| 90 | 0 | return existingCountry; |
| 91 | |
} |
| 92 | |
} |
| 93 | |
|
| 94 | 0 | return this.getByAlternatePostalCountryCode(alternatePostalCountryCode); |
| 95 | |
} |
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
public Country getDefaultCountry() { |
| 101 | 0 | String postalCountryCode = KNSServiceLocator.getParameterService().getParameterValue(KNSConstants.KNS_NAMESPACE, |
| 102 | |
KNSConstants.DetailTypes.ALL_DETAIL_TYPE, KNSConstants.SystemGroupParameterNames.DEFAULT_COUNTRY); |
| 103 | 0 | return this.getByPrimaryId(postalCountryCode); |
| 104 | |
} |
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
public List<Country> findAllCountriesNotRestricted() { |
| 110 | 0 | List<String> criteriaValues = new ArrayList<String>(); |
| 111 | 0 | criteriaValues.add(null); |
| 112 | 0 | criteriaValues.add("N"); |
| 113 | |
|
| 114 | 0 | Map<String, Object> postalCountryMap = new HashMap<String, Object>(); |
| 115 | 0 | postalCountryMap.put(KNSPropertyConstants.POSTAL_COUNTRY_RESTRICTED_INDICATOR, criteriaValues); |
| 116 | |
|
| 117 | 0 | return kualiModuleService.getResponsibleModuleService(Country.class).getExternalizableBusinessObjectsList(Country.class, postalCountryMap); |
| 118 | |
} |
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
public List<Country> findAllCountries() { |
| 124 | 0 | Map<String, Object> postalCountryMap = new HashMap<String, Object>(); |
| 125 | 0 | return kualiModuleService.getResponsibleModuleService(Country.class).getExternalizableBusinessObjectsList(Country.class, postalCountryMap); |
| 126 | |
} |
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
public void setKualiModuleService(KualiModuleService kualiModuleService) { |
| 134 | 0 | this.kualiModuleService = kualiModuleService; |
| 135 | 0 | } |
| 136 | |
|
| 137 | |
} |