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