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 public class CampusServiceImpl implements CampusService {
32
33 private BusinessObjectService boService;
34
35
36
37
38 @Override
39 public Campus getCampus(String code) {
40 if (StringUtils.isBlank(code)) {
41 throw new RiceIllegalArgumentException("code is blank");
42 }
43
44 CampusBo campusBo = boService.findByPrimaryKey(CampusBo.class, singletonMap("code", code));
45
46 return CampusBo.to(campusBo);
47 }
48
49
50
51
52 @Override
53 public List<Campus> findAllCampuses() {
54 List<CampusBo> campusBos = (List<CampusBo>) boService.findMatching(CampusBo.class, singletonMap("active", "true"));
55
56 return this.convertListOfCampusBosToImmutables(campusBos);
57 }
58
59
60
61
62 @Override
63 public CampusType getCampusType(String code) {
64 if (StringUtils.isBlank(code)) {
65 throw new RiceIllegalArgumentException("code is blank");
66 }
67
68 CampusTypeBo campusTypeBo = boService.findByPrimaryKey(CampusTypeBo.class, singletonMap("code", code));
69
70 return CampusTypeBo.to(campusTypeBo);
71 }
72
73
74
75
76 @Override
77 public List<CampusType> findAllCampusTypes() {
78 List<CampusTypeBo> campusTypeBos = (List<CampusTypeBo>)boService.findMatching(CampusTypeBo.class, singletonMap("active", "true"));
79 return this.convertListOfCampusTypesBosToImmutables(campusTypeBos);
80 }
81
82 public void setBusinessObjectService(BusinessObjectService boService) {
83 this.boService = boService;
84 }
85
86 private List<Campus> convertListOfCampusBosToImmutables(List<CampusBo> campusBos) {
87 ArrayList<Campus> campuses = new ArrayList<Campus>();
88 for (CampusBo bo : campusBos) {
89 Campus campus = CampusBo.to(bo);
90 campuses.add(campus) ;
91 }
92 return Collections.unmodifiableList(campuses);
93 }
94
95 private List<CampusType> convertListOfCampusTypesBosToImmutables(List<CampusTypeBo> campusTypeBos) {
96 ArrayList<CampusType> campusTypes = new ArrayList<CampusType>();
97 for (CampusTypeBo bo : campusTypeBos) {
98 CampusType campusType = CampusTypeBo.to(bo);
99 campusTypes.add(campusType) ;
100 }
101 return Collections.unmodifiableList(campusTypes);
102 }
103 }