1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.r2.core.exemption.service; |
17 | |
|
18 | |
import java.util.ArrayList; |
19 | |
import java.util.Date; |
20 | |
import java.util.LinkedHashMap; |
21 | |
import java.util.List; |
22 | |
import java.util.Map; |
23 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
24 | |
import org.kuali.student.r2.common.dto.MetaInfo; |
25 | |
import org.kuali.student.r2.common.dto.StatusInfo; |
26 | |
import org.kuali.student.r2.common.dto.ValidationResultInfo; |
27 | |
import org.kuali.student.r2.common.exceptions.AlreadyExistsException; |
28 | |
import org.kuali.student.r2.common.exceptions.DataValidationErrorException; |
29 | |
import org.kuali.student.r2.common.exceptions.DoesNotExistException; |
30 | |
import org.kuali.student.r2.common.exceptions.InvalidParameterException; |
31 | |
import org.kuali.student.r2.common.exceptions.MissingParameterException; |
32 | |
import org.kuali.student.r2.common.exceptions.OperationFailedException; |
33 | |
import org.kuali.student.r2.common.exceptions.PermissionDeniedException; |
34 | |
import org.kuali.student.r2.common.exceptions.VersionMismatchException; |
35 | |
import org.kuali.student.r2.core.exemption.dto.ExemptionInfo; |
36 | |
import org.kuali.student.r2.core.exemption.dto.ExemptionRequestInfo; |
37 | |
|
38 | 0 | public class ExemptionServiceMockImpl implements ExemptionService { |
39 | |
|
40 | |
@Override |
41 | |
public List<ValidationResultInfo> validateExemptionRequest(String validationTypeKey, ExemptionRequestInfo exemptionRequestInfo, ContextInfo context) |
42 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
43 | |
|
44 | 0 | return new ArrayList<ValidationResultInfo>(); |
45 | |
} |
46 | |
|
47 | |
|
48 | 0 | private Map<String, ExemptionRequestInfo> exemptionRequestMap = new LinkedHashMap<String, ExemptionRequestInfo>(); |
49 | |
|
50 | |
@Override |
51 | |
public ExemptionRequestInfo createExemptionRequest(String personId, String exemptionRequestTypeKey, ExemptionRequestInfo exemptionRequestInfo, ContextInfo context) |
52 | |
throws AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
53 | |
|
54 | 0 | if (!exemptionRequestTypeKey.equals(exemptionRequestInfo.getTypeKey())) { |
55 | 0 | throw new InvalidParameterException("The type parameter does not match the type on the info object"); |
56 | |
} |
57 | |
|
58 | 0 | ExemptionRequestInfo copy = new ExemptionRequestInfo(exemptionRequestInfo); |
59 | 0 | if (copy.getId() == null) { |
60 | 0 | copy.setId(exemptionRequestMap.size() + ""); |
61 | |
} |
62 | 0 | copy.setMeta(newMeta(context)); |
63 | 0 | exemptionRequestMap.put(copy.getId(), copy); |
64 | 0 | return new ExemptionRequestInfo(copy); |
65 | |
} |
66 | |
|
67 | |
@Override |
68 | |
public ExemptionRequestInfo updateExemptionRequest(String exemptionRequestId, ExemptionRequestInfo exemptionRequestInfo, ContextInfo context) |
69 | |
throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException { |
70 | |
|
71 | 0 | if (!exemptionRequestId.equals(exemptionRequestInfo.getId())) { |
72 | 0 | throw new InvalidParameterException("The id parameter does not match the id on the info object"); |
73 | |
} |
74 | 0 | ExemptionRequestInfo copy = new ExemptionRequestInfo(exemptionRequestInfo); |
75 | 0 | ExemptionRequestInfo old = this.getExemptionRequest(exemptionRequestInfo.getId(), context); |
76 | 0 | if (!old.getMeta().getVersionInd().equals(copy.getMeta().getVersionInd())) { |
77 | 0 | throw new VersionMismatchException(old.getMeta().getVersionInd()); |
78 | |
} |
79 | 0 | copy.setMeta(updateMeta(copy.getMeta(), context)); |
80 | 0 | this.exemptionRequestMap.put(exemptionRequestInfo.getId(), copy); |
81 | 0 | return new ExemptionRequestInfo(copy); |
82 | |
} |
83 | |
|
84 | |
@Override |
85 | |
public StatusInfo deleteExemptionRequest(String exemptionRequestId, ContextInfo context) |
86 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
87 | 0 | if (this.exemptionRequestMap.remove(exemptionRequestId) == null) { |
88 | 0 | throw new DoesNotExistException(exemptionRequestId); |
89 | |
} |
90 | 0 | return newStatus(); |
91 | |
} |
92 | |
|
93 | |
@Override |
94 | |
public ExemptionRequestInfo getExemptionRequest(String exemptionRequestId, ContextInfo context) |
95 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
96 | 0 | if (!this.exemptionRequestMap.containsKey(exemptionRequestId)) { |
97 | 0 | throw new DoesNotExistException(exemptionRequestId); |
98 | |
} |
99 | 0 | return this.exemptionRequestMap.get(exemptionRequestId); |
100 | |
} |
101 | |
|
102 | |
@Override |
103 | |
public List<ExemptionRequestInfo> getExemptionRequestsByIds(List<String> exemptionRequestIds, ContextInfo context) |
104 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
105 | 0 | List<ExemptionRequestInfo> list = new ArrayList<ExemptionRequestInfo>(); |
106 | 0 | for (String id : exemptionRequestIds) { |
107 | 0 | list.add(this.getExemptionRequest(id, context)); |
108 | |
} |
109 | 0 | return list; |
110 | |
} |
111 | |
|
112 | |
@Override |
113 | |
public List<String> getExemptionRequestIdsByType(String exemptionRequestTypeKey, ContextInfo context) |
114 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
115 | 0 | List<String> list = new ArrayList<String>(); |
116 | 0 | for (ExemptionRequestInfo info : exemptionRequestMap.values()) { |
117 | 0 | if (exemptionRequestTypeKey.equals(info.getTypeKey())) { |
118 | 0 | list.add(info.getId()); |
119 | |
} |
120 | |
} |
121 | 0 | return list; |
122 | |
} |
123 | |
|
124 | |
@Override |
125 | |
public List<ExemptionRequestInfo> getRequestsForPerson(String personId, ContextInfo context) |
126 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
127 | 0 | throw new OperationFailedException("getRequestsForPerson has not been implemented"); |
128 | |
} |
129 | |
|
130 | |
@Override |
131 | |
public List<ExemptionRequestInfo> getRequestsByTypeForPerson(String typeKey, String personId, ContextInfo context) |
132 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
133 | 0 | List<ExemptionRequestInfo> list = new ArrayList<ExemptionRequestInfo>(); |
134 | 0 | for (ExemptionRequestInfo info : exemptionRequestMap.values()) { |
135 | 0 | if (typeKey.equals(info.getTypeKey())) { |
136 | 0 | if (personId.equals(info.getPersonId())) { |
137 | 0 | list.add(info); |
138 | |
} |
139 | |
} |
140 | |
} |
141 | 0 | return list; |
142 | |
} |
143 | |
|
144 | |
@Override |
145 | |
public List<String> getExemptionRequestIdsByCheck(String checkKey, ContextInfo context) |
146 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
147 | 0 | List<String> list = new ArrayList<String>(); |
148 | 0 | for (ExemptionRequestInfo info : exemptionRequestMap.values()) { |
149 | 0 | if (checkKey.equals(info.getCheckKey())) { |
150 | 0 | list.add(info.getId()); |
151 | |
} |
152 | |
} |
153 | 0 | return list; |
154 | |
} |
155 | |
|
156 | |
@Override |
157 | |
public List<ValidationResultInfo> validateExemption(String validationTypeKey, ExemptionInfo exemptionInfo, ContextInfo context) |
158 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException { |
159 | |
|
160 | 0 | return new ArrayList<ValidationResultInfo>(); |
161 | |
} |
162 | |
|
163 | |
|
164 | 0 | private Map<String, ExemptionInfo> exemptionMap = new LinkedHashMap<String, ExemptionInfo>(); |
165 | |
|
166 | |
@Override |
167 | |
public ExemptionInfo createExemption(String exemptionRequestId, String exemptionTypeKey, ExemptionInfo exemptionInfo, ContextInfo context) |
168 | |
throws AlreadyExistsException, DataValidationErrorException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
169 | |
|
170 | 0 | if (!exemptionTypeKey.equals(exemptionInfo.getTypeKey())) { |
171 | 0 | throw new InvalidParameterException("The type parameter does not match the type on the info object"); |
172 | |
} |
173 | |
|
174 | 0 | ExemptionInfo copy = new ExemptionInfo(exemptionInfo); |
175 | 0 | if (copy.getId() == null) { |
176 | 0 | copy.setId(exemptionMap.size() + ""); |
177 | |
} |
178 | 0 | copy.setMeta(newMeta(context)); |
179 | 0 | exemptionMap.put(copy.getId(), copy); |
180 | 0 | return new ExemptionInfo(copy); |
181 | |
} |
182 | |
|
183 | |
@Override |
184 | |
public ExemptionInfo updateExemption(String exemptionId, ExemptionInfo exemptionInfo, ContextInfo context) |
185 | |
throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, VersionMismatchException { |
186 | |
|
187 | 0 | if (!exemptionId.equals(exemptionInfo.getId())) { |
188 | 0 | throw new InvalidParameterException("The id parameter does not match the id on the info object"); |
189 | |
} |
190 | 0 | ExemptionInfo copy = new ExemptionInfo(exemptionInfo); |
191 | 0 | ExemptionInfo old = this.getExemption(exemptionInfo.getId(), context); |
192 | 0 | if (!old.getMeta().getVersionInd().equals(copy.getMeta().getVersionInd())) { |
193 | 0 | throw new VersionMismatchException(old.getMeta().getVersionInd()); |
194 | |
} |
195 | 0 | copy.setMeta(updateMeta(copy.getMeta(), context)); |
196 | 0 | this.exemptionMap.put(exemptionInfo.getId(), copy); |
197 | 0 | return new ExemptionInfo(copy); |
198 | |
} |
199 | |
|
200 | |
@Override |
201 | |
public StatusInfo addUseToExemption(String exemptionId, ContextInfo context) |
202 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
203 | 0 | throw new OperationFailedException("addUseToExemption has not been implemented"); |
204 | |
} |
205 | |
|
206 | |
@Override |
207 | |
public StatusInfo deleteExemption(String exemptionId, ContextInfo context) |
208 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
209 | 0 | if (this.exemptionMap.remove(exemptionId) == null) { |
210 | 0 | throw new DoesNotExistException(exemptionId); |
211 | |
} |
212 | 0 | return newStatus(); |
213 | |
} |
214 | |
|
215 | |
@Override |
216 | |
public ExemptionInfo getExemption(String exemptionId, ContextInfo context) |
217 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
218 | 0 | if (!this.exemptionMap.containsKey(exemptionId)) { |
219 | 0 | throw new DoesNotExistException(exemptionId); |
220 | |
} |
221 | 0 | return this.exemptionMap.get(exemptionId); |
222 | |
} |
223 | |
|
224 | |
@Override |
225 | |
public List<ExemptionInfo> getExemptionsByIds(List<String> exemptionIds, ContextInfo context) |
226 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
227 | 0 | List<ExemptionInfo> list = new ArrayList<ExemptionInfo>(); |
228 | 0 | for (String id : exemptionIds) { |
229 | 0 | list.add(this.getExemption(id, context)); |
230 | |
} |
231 | 0 | return list; |
232 | |
} |
233 | |
|
234 | |
@Override |
235 | |
public List<String> getExemptionIdsByType(String exemptionTypeKey, ContextInfo context) |
236 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
237 | 0 | List<String> list = new ArrayList<String>(); |
238 | 0 | for (ExemptionInfo info : exemptionMap.values()) { |
239 | 0 | if (exemptionTypeKey.equals(info.getTypeKey())) { |
240 | 0 | list.add(info.getId()); |
241 | |
} |
242 | |
} |
243 | 0 | return list; |
244 | |
} |
245 | |
|
246 | |
@Override |
247 | |
public List<ExemptionInfo> getExemptionsForPerson(String personId, ContextInfo context) |
248 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
249 | 0 | throw new OperationFailedException("getExemptionsForPerson has not been implemented"); |
250 | |
} |
251 | |
|
252 | |
@Override |
253 | |
public List<ExemptionInfo> getExemptionsForRequest(String requestId, ContextInfo context) |
254 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
255 | 0 | throw new OperationFailedException("getExemptionsForRequest has not been implemented"); |
256 | |
} |
257 | |
|
258 | |
@Override |
259 | |
public List<ExemptionInfo> getActiveExemptionsForPerson(String personId, Date asOfDate, ContextInfo context) |
260 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
261 | 0 | throw new OperationFailedException("getActiveExemptionsForPerson has not been implemented"); |
262 | |
} |
263 | |
|
264 | |
@Override |
265 | |
public List<ExemptionInfo> getExemptionsByTypeForPerson(String typeKey, String personId, ContextInfo context) |
266 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
267 | 0 | List<ExemptionInfo> list = new ArrayList<ExemptionInfo>(); |
268 | 0 | for (ExemptionInfo info : exemptionMap.values()) { |
269 | 0 | if (typeKey.equals(info.getTypeKey())) { |
270 | 0 | if (personId.equals(info.getPersonId())) { |
271 | 0 | list.add(info); |
272 | |
} |
273 | |
} |
274 | |
} |
275 | 0 | return list; |
276 | |
} |
277 | |
|
278 | |
private boolean asOfCheck(Date asOfDate, ExemptionInfo info) { |
279 | 0 | if (info.getEffectiveDate() != null) { |
280 | 0 | if (asOfDate.before(info.getEffectiveDate())) { |
281 | 0 | return false; |
282 | |
|
283 | |
} |
284 | |
} |
285 | 0 | if (info.getExpirationDate() != null) { |
286 | 0 | if (asOfDate.after(info.getExpirationDate())) { |
287 | 0 | return false; |
288 | |
} |
289 | |
} |
290 | 0 | return true; |
291 | |
} |
292 | |
|
293 | |
@Override |
294 | |
public List<ExemptionInfo> getActiveExemptionsByTypeForPerson(String typeKey, String personId, Date asOfDate, ContextInfo context) |
295 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
296 | 0 | List<ExemptionInfo> list = new ArrayList<ExemptionInfo>(); |
297 | 0 | for (ExemptionInfo info : exemptionMap.values()) { |
298 | 0 | if (typeKey.equals(info.getTypeKey())) { |
299 | 0 | if (personId.equals(info.getPersonId())) { |
300 | 0 | if (asOfCheck(asOfDate, info)) { |
301 | 0 | list.add(info); |
302 | |
} |
303 | |
} |
304 | |
} |
305 | |
} |
306 | 0 | return list; |
307 | |
} |
308 | |
|
309 | |
@Override |
310 | |
public List<ExemptionInfo> getActiveExemptionsByTypeProcessAndCheckForPerson |
311 | |
(String typeKey, String processId |
312 | |
, String checkKey, String personId |
313 | |
, Date asOfDate, ContextInfo context |
314 | |
) |
315 | |
throws InvalidParameterException |
316 | |
,MissingParameterException |
317 | |
,OperationFailedException |
318 | |
,PermissionDeniedException |
319 | |
{ |
320 | 0 | List<ExemptionInfo> list = new ArrayList<ExemptionInfo>(); |
321 | 0 | for (ExemptionInfo info : exemptionMap.values()) { |
322 | 0 | if (typeKey.equals(info.getTypeKey())) { |
323 | 0 | if (processId.equals(info.getProcessId())) { |
324 | 0 | if (checkKey.equals(info.getCheckKey())) { |
325 | 0 | if (personId.equals(info.getPersonId())) { |
326 | 0 | if (asOfCheck (asOfDate, info)) { |
327 | 0 | list.add(info); |
328 | |
} |
329 | |
} |
330 | |
} |
331 | |
} |
332 | |
} |
333 | |
} |
334 | 0 | return list; |
335 | |
} |
336 | |
|
337 | |
|
338 | |
|
339 | |
private MetaInfo newMeta(ContextInfo context) { |
340 | 0 | MetaInfo meta = new MetaInfo(); |
341 | 0 | meta.setCreateId(context.getPrincipalId()); |
342 | 0 | meta.setCreateTime(new Date()); |
343 | 0 | meta.setUpdateId(context.getPrincipalId()); |
344 | 0 | meta.setUpdateTime(meta.getCreateTime()); |
345 | 0 | meta.setVersionInd("0"); |
346 | 0 | return meta; |
347 | |
} |
348 | |
|
349 | |
private StatusInfo newStatus() { |
350 | 0 | StatusInfo status = new StatusInfo(); |
351 | 0 | status.setSuccess(Boolean.TRUE); |
352 | 0 | return status; |
353 | |
} |
354 | |
|
355 | |
private MetaInfo updateMeta(MetaInfo old, ContextInfo context) { |
356 | 0 | MetaInfo meta = new MetaInfo(old); |
357 | 0 | meta.setUpdateId(context.getPrincipalId()); |
358 | 0 | meta.setUpdateTime(new Date()); |
359 | 0 | meta.setVersionInd((Integer.parseInt(meta.getVersionInd()) + 1) + ""); |
360 | 0 | return meta; |
361 | |
} |
362 | |
} |