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