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.List; |
20 | |
import java.util.Map; |
21 | |
|
22 | |
import org.apache.commons.lang.StringUtils; |
23 | |
import org.apache.log4j.Logger; |
24 | |
import org.kuali.rice.kns.bo.State; |
25 | |
import org.kuali.rice.kns.service.CountryService; |
26 | |
import org.kuali.rice.kns.service.KualiModuleService; |
27 | |
import org.kuali.rice.kns.service.StateService; |
28 | |
import org.kuali.rice.kns.util.KNSPropertyConstants; |
29 | |
|
30 | 0 | public class StateServiceImpl implements StateService { |
31 | 0 | private static Logger LOG = Logger.getLogger(StateServiceImpl.class); |
32 | |
|
33 | |
private KualiModuleService kualiModuleService; |
34 | |
private CountryService countryService; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
public State getByPrimaryId(String postalStateCode) { |
40 | 0 | String postalCountryCode = countryService.getDefaultCountry().getPostalCountryCode(); |
41 | 0 | return this.getByPrimaryId(postalCountryCode, postalStateCode); |
42 | |
} |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
public State getByPrimaryId(String postalCountryCode, String postalStateCode) { |
48 | 0 | if (StringUtils.isBlank(postalCountryCode) || StringUtils.isBlank(postalStateCode)) { |
49 | 0 | LOG.debug("neither postalCountryCode nor postalStateCode can be empty String."); |
50 | 0 | return null; |
51 | |
} |
52 | |
|
53 | 0 | Map<String, Object> postalStateMap = new HashMap<String, Object>(); |
54 | 0 | postalStateMap.put(KNSPropertyConstants.POSTAL_COUNTRY_CODE, postalCountryCode); |
55 | 0 | postalStateMap.put(KNSPropertyConstants.POSTAL_STATE_CODE, postalStateCode); |
56 | |
|
57 | 0 | return kualiModuleService.getResponsibleModuleService(State.class).getExternalizableBusinessObject(State.class, postalStateMap); |
58 | |
} |
59 | |
|
60 | |
public State getByPrimaryIdIfNecessary(String postalStateCode, State existingState) { |
61 | 0 | String postalCountryCode = countryService.getDefaultCountry().getPostalCountryCode(); |
62 | |
|
63 | 0 | return this.getByPrimaryIdIfNecessary(postalCountryCode, postalStateCode, existingState); |
64 | |
} |
65 | |
|
66 | |
public State getByPrimaryIdIfNecessary(String postalCountryCode, String postalStateCode, State existingState) { |
67 | 0 | if (existingState != null) { |
68 | 0 | String existingCountryCode = existingState.getPostalCountryCode(); |
69 | 0 | String existingPostalStateCode = existingState.getPostalStateCode(); |
70 | 0 | if (StringUtils.equals(postalCountryCode, existingCountryCode) && StringUtils.equals(postalStateCode, existingPostalStateCode)) { |
71 | 0 | return existingState; |
72 | |
} |
73 | |
} |
74 | |
|
75 | 0 | return this.getByPrimaryId(postalCountryCode, postalStateCode); |
76 | |
} |
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
public List<State> findAllStates() { |
82 | 0 | String postalCountryCode = countryService.getDefaultCountry().getPostalCountryCode(); |
83 | 0 | return this.findAllStates(postalCountryCode); |
84 | |
} |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
public List<State> findAllStates(String postalCountryCode) { |
90 | 0 | if (StringUtils.isBlank(postalCountryCode)) { |
91 | 0 | throw new IllegalArgumentException("The postalCountryCode cannot be empty String."); |
92 | |
} |
93 | |
|
94 | 0 | Map<String, Object> postalStateMap = new HashMap<String, Object>(); |
95 | 0 | postalStateMap.put(KNSPropertyConstants.POSTAL_COUNTRY_CODE, postalCountryCode); |
96 | |
|
97 | 0 | return kualiModuleService.getResponsibleModuleService(State.class).getExternalizableBusinessObjectsList(State.class, postalStateMap); |
98 | |
} |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
public void setKualiModuleService(KualiModuleService kualiModuleService) { |
106 | 0 | this.kualiModuleService = kualiModuleService; |
107 | 0 | } |
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
public void setCountryService(CountryService countryService) { |
115 | 0 | this.countryService = countryService; |
116 | 0 | } |
117 | |
} |