1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.shareddata.impl.state; |
18 | |
|
19 | |
|
20 | |
import org.apache.commons.lang.StringUtils; |
21 | |
import org.kuali.rice.kns.service.BusinessObjectService; |
22 | |
import org.kuali.rice.shareddata.api.state.State; |
23 | |
import org.kuali.rice.shareddata.api.state.StateService; |
24 | |
|
25 | |
import java.util.ArrayList; |
26 | |
import java.util.Collection; |
27 | |
import java.util.Collections; |
28 | |
import java.util.HashMap; |
29 | |
import java.util.List; |
30 | |
import java.util.Map; |
31 | |
|
32 | 0 | public class StateServiceImpl implements StateService { |
33 | |
|
34 | |
private BusinessObjectService businessObjectService; |
35 | |
|
36 | |
@Override |
37 | |
public State getState(String countryCode, String code) { |
38 | 0 | if (StringUtils.isBlank(countryCode)) { |
39 | 0 | throw new IllegalArgumentException(("countryCode is null")); |
40 | |
} |
41 | |
|
42 | 0 | if (StringUtils.isBlank(code)) { |
43 | 0 | throw new IllegalArgumentException(("code is null")); |
44 | |
} |
45 | |
|
46 | 0 | final Map<String, Object> map = new HashMap<String, Object>(); |
47 | 0 | map.put("countryCode", countryCode); |
48 | 0 | map.put("code", code); |
49 | |
|
50 | 0 | return StateBo.to(businessObjectService.findByPrimaryKey(StateBo.class, Collections.unmodifiableMap(map))); |
51 | |
} |
52 | |
|
53 | |
@Override |
54 | |
public List<State> findAllStatesInCountry(String countryCode) { |
55 | 0 | if (StringUtils.isBlank(countryCode)) { |
56 | 0 | throw new IllegalArgumentException(("countryCode is null")); |
57 | |
} |
58 | |
|
59 | 0 | final Map<String, Object> map = new HashMap<String, Object>(); |
60 | 0 | map.put("countryCode", countryCode); |
61 | 0 | map.put("active", Boolean.TRUE); |
62 | |
|
63 | 0 | final Collection<StateBo> bos = businessObjectService.findMatching(StateBo.class, Collections.unmodifiableMap(map)); |
64 | 0 | if (bos == null) { |
65 | 0 | return Collections.emptyList(); |
66 | |
} |
67 | |
|
68 | 0 | final List<State> toReturn = new ArrayList<State>(); |
69 | 0 | for (StateBo bo : bos) { |
70 | 0 | if (bo != null && bo.isActive()) { |
71 | 0 | toReturn.add(StateBo.to(bo)); |
72 | |
} |
73 | |
} |
74 | |
|
75 | 0 | return Collections.unmodifiableList(toReturn); |
76 | |
} |
77 | |
|
78 | |
public void setBusinessObjectService(BusinessObjectService businessObjectService) { |
79 | 0 | this.businessObjectService = businessObjectService; |
80 | 0 | } |
81 | |
} |