1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.shareddata.impl.postalcode; |
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.postalcode.PostalCode; |
23 | |
import org.kuali.rice.shareddata.api.postalcode.PostalCodeService; |
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 | 7 | public class PostalCodeServiceImpl implements PostalCodeService { |
33 | |
|
34 | |
private BusinessObjectService businessObjectService; |
35 | |
|
36 | |
@Override |
37 | |
public PostalCode getPostalCode(String countryCode, String code) { |
38 | 4 | if (StringUtils.isBlank(countryCode)) { |
39 | 1 | throw new RiceIllegalArgumentException(("countryCode is null")); |
40 | |
} |
41 | |
|
42 | 3 | if (StringUtils.isBlank(code)) { |
43 | 1 | throw new RiceIllegalArgumentException(("code is null")); |
44 | |
} |
45 | |
|
46 | 2 | final Map<String, Object> map = new HashMap<String, Object>(); |
47 | 2 | map.put("countryCode", countryCode); |
48 | 2 | map.put("code", code); |
49 | |
|
50 | 2 | return PostalCodeBo.to(businessObjectService.findByPrimaryKey(PostalCodeBo.class, Collections.unmodifiableMap(map))); |
51 | |
} |
52 | |
|
53 | |
@Override |
54 | |
public List<PostalCode> findAllPostalCodesInCountry(String countryCode) { |
55 | 3 | if (StringUtils.isBlank(countryCode)) { |
56 | 1 | throw new RiceIllegalArgumentException(("countryCode is null")); |
57 | |
} |
58 | |
|
59 | 2 | final Map<String, Object> map = new HashMap<String, Object>(); |
60 | 2 | map.put("countryCode", countryCode); |
61 | 2 | map.put("active", Boolean.TRUE); |
62 | |
|
63 | 2 | final Collection<PostalCodeBo> bos = businessObjectService.findMatching(PostalCodeBo.class, Collections.unmodifiableMap(map)); |
64 | 2 | if (bos == null) { |
65 | 1 | return Collections.emptyList(); |
66 | |
} |
67 | |
|
68 | 1 | final List<PostalCode> toReturn = new ArrayList<PostalCode>(); |
69 | 1 | for (PostalCodeBo bo : bos) { |
70 | 2 | if (bo != null && bo.isActive()) { |
71 | 2 | toReturn.add(PostalCodeBo.to(bo)); |
72 | |
} |
73 | |
} |
74 | |
|
75 | 1 | return Collections.unmodifiableList(toReturn); |
76 | |
} |
77 | |
|
78 | |
public void setBusinessObjectService(BusinessObjectService businessObjectService) { |
79 | 7 | this.businessObjectService = businessObjectService; |
80 | 7 | } |
81 | |
} |