1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.student.enrollment.class2.courseoffering.service.impl;
18
19 import org.kuali.rice.core.api.criteria.QueryByCriteria;
20 import org.kuali.student.common.mock.MockService;
21 import org.kuali.student.common.util.UUIDHelper;
22 import org.kuali.student.enrollment.lui.dto.LuiCapacityInfo;
23 import org.kuali.student.enrollment.lui.dto.LuiInfo;
24 import org.kuali.student.enrollment.lui.dto.LuiLuiRelationInfo;
25 import org.kuali.student.enrollment.lui.service.LuiService;
26 import org.kuali.student.r2.common.dto.ContextInfo;
27 import org.kuali.student.r2.common.dto.StatusInfo;
28 import org.kuali.student.r2.common.dto.ValidationResultInfo;
29 import org.kuali.student.r2.common.exceptions.*;
30
31 import java.util.ArrayList;
32 import java.util.HashSet;
33 import java.util.LinkedHashMap;
34 import java.util.List;
35 import java.util.Map;
36 import java.util.Set;
37
38
39
40
41
42 public class LuiServiceMockImpl
43 implements LuiService, MockService {
44
45 private Map<String, LuiInfo> luis = new LinkedHashMap<String, LuiInfo>();
46 private Map<String, LuiLuiRelationInfo> luiLuiRelations = new LinkedHashMap<String, LuiLuiRelationInfo>();
47
48 @Override
49 public void clear() {
50 this.luis.clear();
51 this.luiLuiRelations.clear();
52 }
53
54 @Override
55 public LuiInfo getLui(String luiId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
56 if (!luis.containsKey(luiId)) {
57 throw new DoesNotExistException(luiId);
58 }
59 return new LuiInfo (luis.get(luiId));
60 }
61
62 @Override
63 public List<LuiInfo> getLuisByIds(List<String> luiIds, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
64 List<LuiInfo> list = new ArrayList<LuiInfo>();
65 for (String id : luiIds) {
66 list.add (this.getLui(id, contextInfo));
67 }
68 return list;
69 }
70
71 @Override
72 public List<String> getLuiIdsByType(String luiTypeKey, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
73 List<String> list = new ArrayList<String>();
74 for (LuiInfo info : this.luis.values()) {
75 if (info.getTypeKey().equals(luiTypeKey)) {
76 list.add(info.getId());
77 }
78 }
79 return list;
80 }
81
82 @Override
83 public List<String> getLuiIdsByClu(String cluId, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
84 List<String> list = new ArrayList<String>();
85 for (LuiInfo info : this.luis.values()) {
86 if (info.getAtpId().equals(cluId)) {
87 list.add(info.getId());
88 }
89 }
90 return list;
91 }
92
93 @Override
94 public List<String> getLuiIdsByAtpAndType(String atpId, String typeKey, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
95 List<String> list = new ArrayList<String>();
96 for (LuiInfo info : this.luis.values()) {
97 if (info.getAtpId().equals(atpId)) {
98 if (info.getTypeKey().equals(typeKey)) {
99 list.add(info.getId());
100 }
101 }
102 }
103 return list;
104 }
105
106 @Override
107 public List<String> getLuiIdsByAtpAndClu(String cluId, String atpId, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
108 List<String> list = new ArrayList<String>();
109 for (LuiInfo info : this.luis.values()) {
110 if (info.getAtpId().equals(atpId)) {
111 if (info.getCluId().equals(cluId)) {
112 list.add(info.getId());
113 }
114 }
115 }
116 return list;
117 }
118
119 @Override
120 public List<LuiInfo> getLuisByAtpAndClu(String cluId, String atpId, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
121 try {
122 return this.getLuisByIds(this.getLuiIdsByAtpAndClu(cluId, atpId, contextInfo), contextInfo);
123 } catch (DoesNotExistException ex) {
124 throw new OperationFailedException("unexpected", ex);
125 }
126 }
127
128 @Override
129 public List<String> searchForLuiIds(QueryByCriteria criteria, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
130 throw new UnsupportedOperationException("Not supported yet.");
131 }
132
133 @Override
134 public List<LuiInfo> searchForLuis(QueryByCriteria criteria, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
135 throw new UnsupportedOperationException("Not supported yet.");
136 }
137
138 @Override
139 public List<ValidationResultInfo> validateLui(String validationTypeKey, String cluId, String atpId, String luiTypeKey, LuiInfo luiInfo, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
140 return new ArrayList<ValidationResultInfo>();
141 }
142
143 @Override
144 public LuiInfo createLui(String cluId, String atpId, String luiTypeKey, LuiInfo luiInfo, ContextInfo contextInfo) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException {
145 LuiInfo copy = new LuiInfo(luiInfo);
146 if (copy.getId() == null) {
147 copy.setId(UUIDHelper.genStringUUID());
148 }
149 luis.put(copy.getId(), copy);
150 return new LuiInfo(copy);
151 }
152
153 @Override
154 public LuiInfo updateLui(String luiId, LuiInfo luiInfo, ContextInfo contextInfo) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException, VersionMismatchException {
155 if (!luis.containsKey(luiId)) {
156 throw new DoesNotExistException(luiId);
157 }
158 LuiInfo copy = new LuiInfo(luiInfo);
159 luis.put(luiId, copy);
160 return new LuiInfo(copy);
161 }
162
163 @Override
164 public StatusInfo deleteLui(String luiId, ContextInfo contextInfo) throws DependentObjectsExistException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
165 this.getLui(luiId, contextInfo);
166 luis.remove(luiId);
167 StatusInfo status = new StatusInfo();
168 status.setSuccess(Boolean.TRUE);
169 return status;
170 }
171
172 @Override
173 public LuiLuiRelationInfo getLuiLuiRelation(String luiLuiRelationId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
174 if (!this.luiLuiRelations.containsKey(luiLuiRelationId)) {
175 throw new DoesNotExistException(luiLuiRelationId);
176 }
177 return new LuiLuiRelationInfo(this.luiLuiRelations.get(luiLuiRelationId));
178 }
179
180 @Override
181 public List<LuiLuiRelationInfo> getLuiLuiRelationsByIds(List<String> luiLuiRelationIds, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
182 List<LuiLuiRelationInfo> list = new ArrayList<LuiLuiRelationInfo>();
183 for (LuiLuiRelationInfo info : this.luiLuiRelations.values()) {
184 if (luiLuiRelationIds.contains(info.getId())) {
185 list.add(info);
186 }
187 }
188 return list;
189 }
190
191 @Override
192 public List<String> getLuiLuiRelationIdsByType(String luiLuiRelationTypeKey, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
193 List<String> list = new ArrayList<String>();
194 for (LuiLuiRelationInfo info : this.luiLuiRelations.values()) {
195 if (info.getTypeKey().equals(luiLuiRelationTypeKey)) {
196 list.add(info.getId());
197 }
198 }
199 return list;
200 }
201
202 @Override
203 public List<LuiLuiRelationInfo> getLuiLuiRelationsByLui(String luiId, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
204 List<LuiLuiRelationInfo> list = new ArrayList<LuiLuiRelationInfo>();
205 for (LuiLuiRelationInfo info : this.luiLuiRelations.values()) {
206 if (info.getLuiId().equals(luiId)) {
207 list.add(info);
208 }
209 }
210 return list;
211 }
212
213 @Override
214 public List<LuiLuiRelationInfo> getLuiLuiRelationsByLuiAndRelatedLui(String luiId, String relatedLuiId, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
215 List<LuiLuiRelationInfo> list = new ArrayList<LuiLuiRelationInfo>();
216 for (LuiLuiRelationInfo info : this.luiLuiRelations.values()) {
217 if (info.getLuiId().equals(luiId) &&
218 info.getRelatedLuiId().equals(relatedLuiId)) {
219 list.add(info);
220 }
221 }
222 return list;
223 }
224
225 @Override
226 public List<LuiInfo> getLuiLuiRelationsByLuiAndRelatedLuiType(String luiId, String relatedLuiTypeKey, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
227
228 return null;
229 }
230
231
232 @Override
233 public List<String> getLuiIdsByRelatedLuiAndRelationType(String luiId, String luiLuiRelationTypeKey, ContextInfo contextInfo)
234 throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
235 List<String> list = new ArrayList<String>();
236 for (LuiLuiRelationInfo info : this.luiLuiRelations.values()) {
237 if (info.getLuiId().equals(luiId)) {
238 if (info.getTypeKey().equals(luiLuiRelationTypeKey)) {
239 list.add(info.getRelatedLuiId());
240 }
241 }
242 }
243 return list;
244 }
245
246 @Override
247 public List<LuiInfo> getLuisByRelatedLuiAndRelationType(String relatedLuiId, String luiLuiRelationTypeKey, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
248 try {
249 List<String> ids = this.getLuiIdsByLuiAndRelationType(relatedLuiId, luiLuiRelationTypeKey, contextInfo);
250 return this.getLuisByIds(ids, contextInfo);
251 } catch (DoesNotExistException ex) {
252 throw new OperationFailedException("unexpected", ex);
253 }
254 }
255
256
257 @Override
258 public List<String> getLuiIdsByLuiAndRelationType(String relatedLuiId, String luiLuiRelationTypeKey, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
259 Set<String> set = new HashSet<String>();
260 for (LuiLuiRelationInfo info : this.luiLuiRelations.values()) {
261 if (info.getRelatedLuiId().equals(relatedLuiId)) {
262 if (info.getTypeKey().equals(luiLuiRelationTypeKey)) {
263 set.add(info.getLuiId());
264 }
265 }
266 }
267 return new ArrayList(set);
268 }
269
270 @Override
271 public List<LuiInfo> getRelatedLuisByLuiAndRelationType(String luiId, String luiLuiRelationTypeKey, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
272 try {
273 return this.getLuisByIds(this.getLuiIdsByRelatedLuiAndRelationType(luiId, luiLuiRelationTypeKey, contextInfo), contextInfo);
274 } catch (DoesNotExistException ex) {
275 throw new OperationFailedException("unexpected", ex);
276 }
277 }
278
279 @Override
280 public List<String> searchForLuiLuiRelationIds(QueryByCriteria criteria, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
281 throw new UnsupportedOperationException("Not supported yet.");
282 }
283
284 @Override
285 public List<LuiLuiRelationInfo> searchForLuiLuiRelations(QueryByCriteria criteria, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
286 throw new UnsupportedOperationException("Not supported yet.");
287 }
288
289 @Override
290 public List<ValidationResultInfo> validateLuiLuiRelation(String validationTypeKey, String luiId, String relatedLuiId, String luiLuiRelationTypeKey, LuiLuiRelationInfo luiLuiRelationInfo, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
291 return new ArrayList<ValidationResultInfo>();
292 }
293
294 @Override
295 public LuiLuiRelationInfo createLuiLuiRelation(String luiId, String relatedLuiId, String luiLuiRelationTypeKey, LuiLuiRelationInfo luiLuiRelationInfo, ContextInfo contextInfo) throws CircularRelationshipException, DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException {
296 LuiLuiRelationInfo copy = new LuiLuiRelationInfo(luiLuiRelationInfo);
297 if (copy.getId() == null) {
298 copy.setId(UUIDHelper.genStringUUID());
299 }
300 luiLuiRelations.put(copy.getId(), copy);
301 return new LuiLuiRelationInfo(copy);
302 }
303
304 @Override
305 public LuiLuiRelationInfo updateLuiLuiRelation(String luiLuiRelationId, LuiLuiRelationInfo luiLuiRelationInfo, ContextInfo contextInfo) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException, VersionMismatchException {
306 if (!luiLuiRelations.containsKey(luiLuiRelationId)) {
307 throw new DoesNotExistException(luiLuiRelationId);
308 }
309 LuiLuiRelationInfo copy = new LuiLuiRelationInfo(luiLuiRelationInfo);
310 luiLuiRelations.put(luiLuiRelationId, copy);
311 return new LuiLuiRelationInfo(copy);
312 }
313
314 @Override
315 public StatusInfo deleteLuiLuiRelation(String luiLuiRelationId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
316 this.getLuiLuiRelation(luiLuiRelationId, contextInfo);
317 luiLuiRelations.remove(luiLuiRelationId);
318 StatusInfo status = new StatusInfo();
319 status.setSuccess(Boolean.TRUE);
320 return status;
321 }
322
323 @Override
324 public LuiCapacityInfo getLuiCapacity(String luiCapacityId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
325 throw new UnsupportedOperationException("Not supported yet.");
326 }
327
328 @Override
329 public List<String> getLuiCapacityIdsByType(String luiCapacityTypeKey, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
330 throw new UnsupportedOperationException("Not supported yet.");
331 }
332
333 @Override
334 public List<LuiCapacityInfo> getLuiCapacitiesByIds(List<String> luiCapacityIds, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
335 throw new UnsupportedOperationException("Not supported yet.");
336 }
337
338 @Override
339 public List<LuiCapacityInfo> getLuiCapacitiesByLui(String luiId, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
340 throw new UnsupportedOperationException("Not supported yet.");
341 }
342
343 @Override
344 public List<LuiCapacityInfo> searchForLuiCapacities(QueryByCriteria criteria, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
345 throw new UnsupportedOperationException("Not supported yet.");
346 }
347
348 @Override
349 public List<String> searchForLuiCapacityIds(QueryByCriteria criteria, ContextInfo contextInfo) throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
350 throw new UnsupportedOperationException("Not supported yet.");
351 }
352
353 @Override
354 public List<ValidationResultInfo> validateLuiCapacity(String validationTypeKey, String luiCapacityTypeKey, LuiCapacityInfo luiCapacityInfo, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
355 return new ArrayList<ValidationResultInfo>();
356 }
357
358 @Override
359 public LuiCapacityInfo createLuiCapacity(String luiCapacityTypeKey, LuiCapacityInfo luiCapacityInfo, ContextInfo contextInfo) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException {
360 throw new UnsupportedOperationException("Not supported yet.");
361 }
362
363 @Override
364 public LuiCapacityInfo updateLuiCapacity(String luiCapacityId, LuiCapacityInfo luiCapacityInfo, ContextInfo contextInfo) throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException, VersionMismatchException {
365 throw new UnsupportedOperationException("Not supported yet.");
366 }
367
368 @Override
369 public StatusInfo deleteLuiCapacity(String luiCapacityId, ContextInfo contextInfo) throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException {
370 throw new UnsupportedOperationException("Not supported yet.");
371 }
372 }