1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.shareddata.impl.county; |
18 | |
|
19 | |
import org.apache.commons.lang.StringUtils; |
20 | |
import org.kuali.rice.core.api.exception.RiceIllegalArgumentException; |
21 | |
import org.kuali.rice.kns.service.BusinessObjectService; |
22 | |
import org.kuali.rice.shareddata.api.county.County; |
23 | |
import org.kuali.rice.shareddata.api.county.CountyService; |
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 | 9 | public class CountyServiceImpl implements CountyService { |
33 | |
|
34 | |
private BusinessObjectService businessObjectService; |
35 | |
|
36 | |
@Override |
37 | |
public County getCounty(String countryCode, String stateCode, String code) { |
38 | 5 | if (StringUtils.isBlank(countryCode)) { |
39 | 1 | throw new RiceIllegalArgumentException(("countryCode is null")); |
40 | |
} |
41 | |
|
42 | 4 | if (StringUtils.isBlank(code)) { |
43 | 1 | throw new RiceIllegalArgumentException(("code is null")); |
44 | |
} |
45 | |
|
46 | 3 | if (StringUtils.isBlank(stateCode)) { |
47 | 1 | throw new RiceIllegalArgumentException(("stateCode is null")); |
48 | |
} |
49 | |
|
50 | 2 | final Map<String, Object> map = new HashMap<String, Object>(); |
51 | 2 | map.put("countryCode", countryCode); |
52 | 2 | map.put("stateCode", stateCode); |
53 | 2 | map.put("code", code); |
54 | |
|
55 | 2 | return CountyBo.to(businessObjectService.findByPrimaryKey(CountyBo.class, Collections.unmodifiableMap(map))); |
56 | |
} |
57 | |
|
58 | |
@Override |
59 | |
public List<County> findAllCountiesInCountryAndState(String countryCode, String stateCode) { |
60 | 4 | if (StringUtils.isBlank(countryCode)) { |
61 | 1 | throw new RiceIllegalArgumentException(("countryCode is null")); |
62 | |
} |
63 | |
|
64 | 3 | if (StringUtils.isBlank(stateCode)) { |
65 | 1 | throw new RiceIllegalArgumentException(("stateCode is null")); |
66 | |
} |
67 | |
|
68 | 2 | final Map<String, Object> map = new HashMap<String, Object>(); |
69 | 2 | map.put("countryCode", countryCode); |
70 | 2 | map.put("stateCode", stateCode); |
71 | 2 | map.put("active", Boolean.TRUE); |
72 | |
|
73 | 2 | final Collection<CountyBo> bos = businessObjectService.findMatching(CountyBo.class, Collections.unmodifiableMap(map)); |
74 | 2 | if (bos == null) { |
75 | 1 | return Collections.emptyList(); |
76 | |
} |
77 | |
|
78 | 1 | final List<County> toReturn = new ArrayList<County>(); |
79 | 1 | for (CountyBo bo : bos) { |
80 | 1 | if (bo != null && bo.isActive()) { |
81 | 1 | toReturn.add(CountyBo.to(bo)); |
82 | |
} |
83 | |
} |
84 | |
|
85 | 1 | return Collections.unmodifiableList(toReturn); |
86 | |
} |
87 | |
|
88 | |
public void setBusinessObjectService(BusinessObjectService businessObjectService) { |
89 | 9 | this.businessObjectService = businessObjectService; |
90 | 9 | } |
91 | |
} |