1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.kuali.mobility.campus.service;
16
17 import org.apache.commons.lang.StringUtils;
18 import org.kuali.mobility.campus.entity.Campus;
19 import org.springframework.stereotype.Service;
20
21 import java.util.ArrayList;
22 import java.util.HashMap;
23 import java.util.Iterator;
24 import java.util.List;
25 import java.util.Map;
26 import javax.ws.rs.GET;
27 import javax.ws.rs.Path;
28 import javax.ws.rs.QueryParam;
29
30
31
32
33
34
35
36 @Service
37 public class CampusServiceImpl implements CampusService {
38
39
40
41
42 private List<Campus> campuses;
43
44
45
46
47 private Map<String, Campus> campusCodeMap = new HashMap<String, Campus>();
48
49
50
51
52
53 public List<Campus> findCampusesByTool(String toolName) {
54 List<Campus> toolCampuses = new ArrayList<Campus>();
55
56 for (Iterator<Campus> iterator = campuses.iterator(); iterator.hasNext();) {
57 Campus campus = iterator.next();
58 if (campus.getTools().contains(toolName)) {
59 toolCampuses.add(campus);
60 }
61 }
62 return toolCampuses;
63 }
64
65
66
67
68
69 public boolean needToSelectDifferentCampusForTool(String tool, String campus) {
70 List<Campus> campuses = findCampusesByTool(tool);
71 boolean needDifferentCampus = true;
72 if (campuses != null && !campuses.isEmpty()) {
73 for (Campus foundCampus : campuses) {
74 if (foundCampus.getCode().equals(campus)) {
75 needDifferentCampus = false;
76 }
77 }
78 }
79 return needDifferentCampus;
80 }
81
82
83
84
85
86 public void setCampuses(List<Campus> campuses) {
87 this.campuses = campuses;
88 }
89
90
91
92
93
94 @GET
95 @Path("/campuses")
96 public List<Campus> getCampuses() {
97 return this.campuses;
98 }
99
100
101
102
103 @Override
104 public Campus getCampusByCode(String campusCode) {
105
106
107
108 if(StringUtils.isEmpty(campusCode)){
109 return null;
110 }
111
112
113 if (this.campuses == null || this.campuses.size() == 0){
114 return null;
115 }
116
117
118 if (campusCodeMap.containsKey(campusCode)){
119 return campusCodeMap.get(campusCode);
120 }
121
122
123 for(Campus campus : this.campuses){
124
125 if (campusCode.equals(campus.getCode())){
126 this.campusCodeMap.put(campusCode, campus);
127 return campus;
128 }
129 }
130
131 return null;
132 }
133 }