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