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
27
28
29
30
31
32 @Service
33 public class CampusServiceImpl implements CampusService {
34
35
36
37
38 private List<Campus> campuses;
39
40
41
42
43 private Map<String, Campus> campusCodeMap = new HashMap<String, Campus>();
44
45
46
47
48
49 public List<Campus> findCampusesByTool(String toolName) {
50 List<Campus> toolCampuses = new ArrayList<Campus>();
51
52 for (Iterator<Campus> iterator = campuses.iterator(); iterator.hasNext();) {
53 Campus campus = iterator.next();
54 if (campus.getTools().contains(toolName)) {
55 toolCampuses.add(campus);
56 }
57 }
58 return toolCampuses;
59 }
60
61
62
63
64
65 public boolean needToSelectDifferentCampusForTool(String tool, String campus) {
66 List<Campus> campuses = findCampusesByTool(tool);
67 boolean needDifferentCampus = true;
68 if (campuses != null && !campuses.isEmpty()) {
69 for (Campus foundCampus : campuses) {
70 if (foundCampus.getCode().equals(campus)) {
71 needDifferentCampus = false;
72 }
73 }
74 }
75 return needDifferentCampus;
76 }
77
78
79
80
81
82 public void setCampuses(List<Campus> campuses) {
83 this.campuses = campuses;
84 }
85
86
87
88
89
90 public List<Campus> getCampuses() {
91 return this.campuses;
92 }
93
94
95
96
97 @Override
98 public Campus getCampusByCode(String campusCode) {
99
100
101
102 if(StringUtils.isEmpty(campusCode)){
103 return null;
104 }
105
106
107 if (this.campuses == null || this.campuses.size() == 0){
108 return null;
109 }
110
111
112 if (campusCodeMap.containsKey(campusCode)){
113 return campusCodeMap.get(campusCode);
114 }
115
116
117 for(Campus campus : this.campuses){
118
119 if (campusCode.equals(campus.getCode())){
120 this.campusCodeMap.put(campusCode, campus);
121 return campus;
122 }
123 }
124
125 return null;
126 }
127 }