1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.shareddata.impl.campus; |
18 | |
|
19 | |
import org.apache.commons.lang.StringUtils; |
20 | |
import org.kuali.rice.core.api.exception.RiceIllegalArgumentException; |
21 | |
import org.kuali.rice.krad.service.BusinessObjectService; |
22 | |
import org.kuali.rice.shareddata.api.campus.Campus; |
23 | |
import org.kuali.rice.shareddata.api.campus.CampusService; |
24 | |
import org.kuali.rice.shareddata.api.campus.CampusType; |
25 | |
|
26 | |
import java.util.ArrayList; |
27 | |
import java.util.Collections; |
28 | |
import java.util.List; |
29 | |
|
30 | |
import static java.util.Collections.singletonMap; |
31 | |
|
32 | 9 | public class CampusServiceImpl implements CampusService { |
33 | |
|
34 | |
private BusinessObjectService boService; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
@Override |
40 | |
public Campus getCampus(String code) { |
41 | 5 | if (StringUtils.isBlank(code)) { |
42 | 2 | throw new RiceIllegalArgumentException("code is blank"); |
43 | |
} |
44 | |
|
45 | 3 | CampusBo campusBo = boService.findByPrimaryKey(CampusBo.class, singletonMap("code", code)); |
46 | |
|
47 | 3 | return CampusBo.to(campusBo); |
48 | |
} |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
@Override |
54 | |
public List<Campus> findAllCampuses() { |
55 | 1 | List<CampusBo> campusBos = (List<CampusBo>) boService.findMatching(CampusBo.class, singletonMap("active", "true")); |
56 | |
|
57 | 1 | return this.convertListOfCampusBosToImmutables(campusBos); |
58 | |
} |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
@Override |
64 | |
public CampusType getCampusType(String code) { |
65 | 5 | if (StringUtils.isBlank(code)) { |
66 | 2 | throw new RiceIllegalArgumentException("code is blank"); |
67 | |
} |
68 | |
|
69 | 3 | CampusTypeBo campusTypeBo = boService.findByPrimaryKey(CampusTypeBo.class, singletonMap("code", code)); |
70 | |
|
71 | 3 | return CampusTypeBo.to(campusTypeBo); |
72 | |
} |
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
@Override |
78 | |
public List<CampusType> findAllCampusTypes() { |
79 | 0 | List<CampusTypeBo> campusTypeBos = (List<CampusTypeBo>)boService.findMatching(CampusTypeBo.class, singletonMap("active", "true")); |
80 | 0 | return this.convertListOfCampusTypesBosToImmutables(campusTypeBos); |
81 | |
} |
82 | |
|
83 | |
public void setBusinessObjectService(BusinessObjectService boService) { |
84 | 5 | this.boService = boService; |
85 | 5 | } |
86 | |
|
87 | |
private List<Campus> convertListOfCampusBosToImmutables(List<CampusBo> campusBos) { |
88 | 1 | ArrayList<Campus> campuses = new ArrayList<Campus>(); |
89 | 1 | for (CampusBo bo : campusBos) { |
90 | 2 | Campus campus = CampusBo.to(bo); |
91 | 2 | campuses.add(campus) ; |
92 | 2 | } |
93 | 1 | return Collections.unmodifiableList(campuses); |
94 | |
} |
95 | |
|
96 | |
private List<CampusType> convertListOfCampusTypesBosToImmutables(List<CampusTypeBo> campusTypeBos) { |
97 | 0 | ArrayList<CampusType> campusTypes = new ArrayList<CampusType>(); |
98 | 0 | for (CampusTypeBo bo : campusTypeBos) { |
99 | 0 | CampusType campusType = CampusTypeBo.to(bo); |
100 | 0 | campusTypes.add(campusType) ; |
101 | 0 | } |
102 | 0 | return Collections.unmodifiableList(campusTypes); |
103 | |
} |
104 | |
} |