1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.student.enrollment.class2.courseregistration.service.impl; |
18 | |
|
19 | |
import java.util.ArrayList; |
20 | |
import java.util.Collections; |
21 | |
import java.util.Date; |
22 | |
import java.util.HashMap; |
23 | |
import java.util.LinkedHashMap; |
24 | |
import java.util.List; |
25 | |
import java.util.Map; |
26 | |
import java.math.BigDecimal; |
27 | |
|
28 | |
import org.kuali.rice.core.api.criteria.QueryByCriteria; |
29 | |
|
30 | |
import org.kuali.student.enrollment.courseregistration.service.CourseRegistrationService; |
31 | |
import org.kuali.student.enrollment.courseregistration.infc.RegistrationRequest; |
32 | |
import org.kuali.student.enrollment.courseregistration.infc.RegistrationRequestItem; |
33 | |
import org.kuali.student.enrollment.courseregistration.dto.CourseRegistrationInfo; |
34 | |
import org.kuali.student.enrollment.courseregistration.dto.ActivityRegistrationInfo; |
35 | |
import org.kuali.student.enrollment.courseregistration.dto.RegistrationRequestInfo; |
36 | |
import org.kuali.student.enrollment.courseregistration.dto.RegistrationRequestItemInfo; |
37 | |
import org.kuali.student.enrollment.courseregistration.dto.RegistrationResponseInfo; |
38 | |
import org.kuali.student.enrollment.courseregistration.dto.RegistrationResponseItemInfo; |
39 | |
import org.kuali.student.enrollment.courseregistration.dto.CreditLoadInfo; |
40 | |
|
41 | |
import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService; |
42 | |
import org.kuali.student.enrollment.courseoffering.infc.RegistrationGroup; |
43 | |
|
44 | |
import org.kuali.student.r2.common.util.constants.LprServiceConstants; |
45 | |
|
46 | |
import org.kuali.student.r2.common.dto.BulkStatusInfo; |
47 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
48 | |
import org.kuali.student.r2.common.dto.MetaInfo; |
49 | |
import org.kuali.student.r2.common.dto.OperationStatusInfo; |
50 | |
import org.kuali.student.r2.common.dto.StatusInfo; |
51 | |
import org.kuali.student.r2.common.infc.ValidationResult; |
52 | |
import org.kuali.student.r2.common.dto.ValidationResultInfo; |
53 | |
|
54 | |
import org.kuali.student.r2.common.exceptions.AlreadyExistsException; |
55 | |
import org.kuali.student.r2.common.exceptions.DataValidationErrorException; |
56 | |
import org.kuali.student.r2.common.exceptions.DoesNotExistException; |
57 | |
import org.kuali.student.r2.common.exceptions.InvalidParameterException; |
58 | |
import org.kuali.student.r2.common.exceptions.MissingParameterException; |
59 | |
import org.kuali.student.r2.common.exceptions.OperationFailedException; |
60 | |
import org.kuali.student.r2.common.exceptions.PermissionDeniedException; |
61 | |
import org.kuali.student.r2.common.exceptions.ReadOnlyException; |
62 | |
import org.kuali.student.r2.common.exceptions.VersionMismatchException; |
63 | |
|
64 | 0 | public class CourseRegistrationServiceMockImpl |
65 | |
extends AbstractCourseRegistrationService |
66 | |
implements CourseRegistrationService { |
67 | |
|
68 | 0 | private final Map<String, CourseRegistrationInfo> crMap = new LinkedHashMap<String, CourseRegistrationInfo>(); |
69 | 0 | private final Map<String, ActivityRegistrationInfo> arMap = new LinkedHashMap<String, ActivityRegistrationInfo>(); |
70 | 0 | private final Map<String, RegistrationRequestInfo> rrMap = new LinkedHashMap<String, RegistrationRequestInfo>(); |
71 | 0 | private final Map<String, List<ActivityRegistrationInfo>> regMap = new LinkedHashMap<String, List<ActivityRegistrationInfo>>(); |
72 | 0 | private final Map<String, List<RegistrationRequestItemInfo>> xactionMap = new LinkedHashMap<String, List<RegistrationRequestItemInfo>>(); |
73 | 0 | private final Map<String, List<RegistrationRequestItemInfo>> studentMap = new LinkedHashMap<String, List<RegistrationRequestItemInfo>>(); |
74 | |
|
75 | |
private final static String CREDIT_LIMIT = "15"; |
76 | 0 | private static long id = 0; |
77 | |
|
78 | |
private CourseOfferingService coService; |
79 | |
|
80 | |
public CourseOfferingService getCourseOfferingService() { |
81 | 0 | return coService; |
82 | |
} |
83 | |
|
84 | |
public void setCourseOfferingService(CourseOfferingService coService) { |
85 | 0 | this.coService = coService; |
86 | 0 | } |
87 | |
|
88 | |
@Override |
89 | |
public CourseRegistrationInfo getCourseRegistration(String courseRegistrationId, ContextInfo contextInfo) |
90 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
91 | |
|
92 | 0 | CourseRegistrationInfo crInfo = this.crMap.get(courseRegistrationId); |
93 | 0 | if (crInfo == null) { |
94 | 0 | throw new DoesNotExistException(courseRegistrationId + " does not exist"); |
95 | |
} |
96 | |
|
97 | 0 | return (crInfo); |
98 | |
} |
99 | |
|
100 | |
public List<CourseRegistrationInfo> getCourseRegistrations(ContextInfo contextInfo) |
101 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
102 | |
|
103 | 0 | return (Collections.unmodifiableList(new ArrayList<CourseRegistrationInfo>(this.crMap.values()))); |
104 | |
} |
105 | |
|
106 | |
@Override |
107 | |
public List<CourseRegistrationInfo> getCourseRegistrationsByIds(List<String> courseRegistrationIds, ContextInfo contextInfo) |
108 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
109 | |
|
110 | 0 | List<CourseRegistrationInfo> ret = new ArrayList<CourseRegistrationInfo>(); |
111 | 0 | for (String id : courseRegistrationIds) { |
112 | 0 | ret.add(getCourseRegistration(id, contextInfo)); |
113 | |
} |
114 | |
|
115 | 0 | return Collections.unmodifiableList(ret); |
116 | |
} |
117 | |
|
118 | |
@Override |
119 | |
public List<String> getCourseRegistrationIdsByType (String courseRegistrationTypeKey, ContextInfo contextInfo) |
120 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
121 | |
|
122 | 0 | List<String> ret = new ArrayList<String>(); |
123 | 0 | for (CourseRegistrationInfo cr : getCourseRegistrations(contextInfo)) { |
124 | 0 | if (cr.getType().equals(courseRegistrationTypeKey)) { |
125 | 0 | ret.add(cr.getId()); |
126 | |
} |
127 | |
} |
128 | |
|
129 | 0 | return Collections.unmodifiableList(ret); |
130 | |
} |
131 | |
|
132 | |
@Override |
133 | |
public List<CourseRegistrationInfo> getCourseRegistrationsByStudent(String studentId, ContextInfo contextInfo) |
134 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
135 | |
|
136 | 0 | List<CourseRegistrationInfo> ret = new ArrayList<CourseRegistrationInfo>(); |
137 | 0 | for (CourseRegistrationInfo cr : getCourseRegistrations(contextInfo)) { |
138 | 0 | if (cr.getStudentId().equals(studentId)) { |
139 | 0 | ret.add(cr); |
140 | |
} |
141 | |
} |
142 | |
|
143 | 0 | return Collections.unmodifiableList(ret); |
144 | |
} |
145 | |
|
146 | |
@Override |
147 | |
public List<CourseRegistrationInfo> getCourseRegistrationsByCourseOffering(String courseOfferingId, ContextInfo contextInfo) |
148 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
149 | |
|
150 | 0 | List<CourseRegistrationInfo> ret = new ArrayList<CourseRegistrationInfo>(); |
151 | 0 | for (CourseRegistrationInfo cr : getCourseRegistrations(contextInfo)) { |
152 | 0 | if (cr.getCourseOfferingId().equals(courseOfferingId)) { |
153 | 0 | ret.add(cr); |
154 | |
} |
155 | |
} |
156 | |
|
157 | 0 | return Collections.unmodifiableList(ret); |
158 | |
} |
159 | |
|
160 | |
@Override |
161 | |
public List<CourseRegistrationInfo> getCourseRegistrationsByStudentAndCourseOffering(String studentId, String courseOfferingId, ContextInfo contextInfo) |
162 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
163 | |
|
164 | 0 | List<CourseRegistrationInfo> ret = new ArrayList<CourseRegistrationInfo>(); |
165 | 0 | for (CourseRegistrationInfo cr : getCourseRegistrationsByStudent(studentId, contextInfo)) { |
166 | 0 | if (cr.getCourseOfferingId().equals(courseOfferingId)) { |
167 | 0 | ret.add(cr); |
168 | |
} |
169 | |
} |
170 | |
|
171 | 0 | return Collections.unmodifiableList(ret); |
172 | |
} |
173 | |
|
174 | |
@Override |
175 | |
public List<CourseRegistrationInfo> getCourseRegistrationsByStudentAndTerm(String studentId, String termId, ContextInfo contextInfo) |
176 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
177 | |
|
178 | 0 | List<CourseRegistrationInfo> ret = new ArrayList<CourseRegistrationInfo>(); |
179 | 0 | for (CourseRegistrationInfo cr : getCourseRegistrationsByStudent(studentId, contextInfo)) { |
180 | |
try { |
181 | 0 | if (getCourseOfferingService().getCourseOffering(cr.getCourseOfferingId(), contextInfo).getTermId().equals(termId)) { |
182 | 0 | ret.add(cr); |
183 | |
} |
184 | 0 | } catch (DoesNotExistException dne) { |
185 | 0 | throw new OperationFailedException("bad stuff in reg", dne); |
186 | 0 | } |
187 | |
} |
188 | |
|
189 | 0 | return Collections.unmodifiableList(ret); |
190 | |
} |
191 | |
|
192 | |
@Override |
193 | |
public List<String> searchForCourseRegistrationIds(QueryByCriteria criteria, ContextInfo contextInfo) |
194 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
195 | |
|
196 | 0 | List<String> ret = new ArrayList<String>(); |
197 | 0 | for (CourseRegistrationInfo cr : searchForCourseRegistrations(criteria, contextInfo)) { |
198 | 0 | ret.add(cr.getId()); |
199 | |
} |
200 | |
|
201 | 0 | return Collections.unmodifiableList(ret); |
202 | |
} |
203 | |
|
204 | |
@Override |
205 | |
public ActivityRegistrationInfo getActivityRegistration(String activityRegistrationId, ContextInfo contextInfo) |
206 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
207 | |
|
208 | 0 | ActivityRegistrationInfo arInfo = this.arMap.get(activityRegistrationId); |
209 | 0 | if (arInfo == null) { |
210 | 0 | throw new DoesNotExistException(activityRegistrationId + " does not exist"); |
211 | |
} |
212 | |
|
213 | 0 | return arInfo; |
214 | |
} |
215 | |
|
216 | |
public List<ActivityRegistrationInfo> getActivityRegistrations(ContextInfo contextInfo) |
217 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
218 | |
|
219 | 0 | return Collections.unmodifiableList(new ArrayList<ActivityRegistrationInfo>(this.arMap.values())); |
220 | |
} |
221 | |
|
222 | |
@Override |
223 | |
public List<ActivityRegistrationInfo> getActivityRegistrationsByIds(List<String> activityRegistrationIds, ContextInfo contextInfo) |
224 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
225 | |
|
226 | 0 | List<ActivityRegistrationInfo> ret = new ArrayList<ActivityRegistrationInfo>(); |
227 | 0 | for (String id : activityRegistrationIds) { |
228 | 0 | ret.add(getActivityRegistration(id, contextInfo)); |
229 | |
} |
230 | |
|
231 | 0 | return Collections.unmodifiableList(ret); |
232 | |
} |
233 | |
|
234 | |
@Override |
235 | |
public List<String> getActivityRegistrationIdsByType(String activityRegistrationTypeKey, ContextInfo contextInfo) |
236 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
237 | |
|
238 | 0 | List<String> ret = new ArrayList<String>(); |
239 | 0 | for (ActivityRegistrationInfo ar : getActivityRegistrations(contextInfo)) { |
240 | 0 | if (ar.getType().equals(activityRegistrationTypeKey)) { |
241 | 0 | ret.add(ar.getId()); |
242 | |
} |
243 | |
} |
244 | |
|
245 | 0 | return Collections.unmodifiableList(ret); |
246 | |
} |
247 | |
|
248 | |
@Override |
249 | |
public List<ActivityRegistrationInfo> getActivityRegistrationsForCourseRegistration(String courseRegistrationId, ContextInfo contextInfo) |
250 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
251 | |
|
252 | 0 | List<ActivityRegistrationInfo> ret = new ArrayList<ActivityRegistrationInfo>(); |
253 | 0 | for (ActivityRegistrationInfo ar : this.regMap.get(courseRegistrationId)) { |
254 | 0 | ret.add(ar); |
255 | |
} |
256 | |
|
257 | 0 | return Collections.unmodifiableList(ret); |
258 | |
} |
259 | |
|
260 | |
@Override |
261 | |
public List<ActivityRegistrationInfo> getActivityRegistrationsByStudent(String studentId, ContextInfo contextInfo) |
262 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
263 | |
|
264 | 0 | List<ActivityRegistrationInfo> ret = new ArrayList<ActivityRegistrationInfo>(); |
265 | 0 | for (ActivityRegistrationInfo ar : getActivityRegistrations(contextInfo)) { |
266 | 0 | if (ar.getStudentId().equals(studentId)) { |
267 | 0 | ret.add(ar); |
268 | |
} |
269 | |
} |
270 | |
|
271 | 0 | return Collections.unmodifiableList(ret); |
272 | |
} |
273 | |
|
274 | |
@Override |
275 | |
public List<ActivityRegistrationInfo> getActivityRegistrationsByActivityOffering(String activityOfferingId, ContextInfo contextInfo) |
276 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
277 | |
|
278 | 0 | List<ActivityRegistrationInfo> ret = new ArrayList<ActivityRegistrationInfo>(); |
279 | 0 | for (ActivityRegistrationInfo ar : getActivityRegistrations(contextInfo)) { |
280 | 0 | if (ar.getActivityOfferingId().equals(activityOfferingId)) { |
281 | 0 | ret.add(ar); |
282 | |
} |
283 | |
} |
284 | |
|
285 | 0 | return Collections.unmodifiableList(ret); |
286 | |
} |
287 | |
|
288 | |
@Override |
289 | |
public List<ActivityRegistrationInfo> getActivityRegistrationsByStudentAndActivityOffering(String studentId, String activityOfferingId, ContextInfo contextInfo) |
290 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
291 | |
|
292 | 0 | List<ActivityRegistrationInfo> ret = new ArrayList<ActivityRegistrationInfo>(); |
293 | 0 | for (ActivityRegistrationInfo ar : getActivityRegistrationsByStudent(studentId, contextInfo)) { |
294 | 0 | if (ar.getActivityOfferingId().equals(activityOfferingId)) { |
295 | 0 | ret.add(ar); |
296 | |
} |
297 | |
} |
298 | |
|
299 | 0 | return Collections.unmodifiableList(ret); |
300 | |
} |
301 | |
|
302 | |
@Override |
303 | |
public List<ActivityRegistrationInfo> getActivityRegistrationsByStudentAndTerm(String studentId, String termId, ContextInfo contextInfo) |
304 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
305 | |
|
306 | 0 | List<ActivityRegistrationInfo> ret = new ArrayList<ActivityRegistrationInfo>(); |
307 | 0 | for (ActivityRegistrationInfo ar : getActivityRegistrationsByStudent(studentId, contextInfo)) { |
308 | |
try { |
309 | 0 | if (getCourseOfferingService().getActivityOffering(ar.getActivityOfferingId(), contextInfo).getTermId().equals(termId)) { |
310 | 0 | ret.add(ar); |
311 | |
} |
312 | 0 | } catch (DoesNotExistException dne) { |
313 | 0 | throw new OperationFailedException("bad stuff in reg", dne); |
314 | 0 | } |
315 | |
} |
316 | |
|
317 | 0 | return Collections.unmodifiableList(ret); |
318 | |
} |
319 | |
|
320 | |
@Override |
321 | |
public List<String> searchForActivityRegistrationIds(QueryByCriteria criteria, ContextInfo contextInfo) |
322 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
323 | |
|
324 | 0 | List<String> ret = new ArrayList<String>(); |
325 | 0 | for (ActivityRegistrationInfo cr : searchForActivityRegistrations(criteria, contextInfo)) { |
326 | 0 | ret.add(cr.getId()); |
327 | |
} |
328 | |
|
329 | 0 | return Collections.unmodifiableList(ret); |
330 | |
} |
331 | |
|
332 | |
@Override |
333 | |
public RegistrationRequestInfo getRegistrationRequest(String registrationRequestId, ContextInfo contextInfo) |
334 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
335 | |
|
336 | 0 | RegistrationRequestInfo rrInfo = this.rrMap.get(registrationRequestId); |
337 | 0 | if (rrInfo == null) { |
338 | 0 | throw new DoesNotExistException(registrationRequestId + " does not exist"); |
339 | |
} |
340 | |
|
341 | 0 | return rrInfo; |
342 | |
} |
343 | |
|
344 | |
public List<RegistrationRequestInfo> getRegistrationRequests(ContextInfo contextInfo) |
345 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
346 | |
|
347 | 0 | return Collections.unmodifiableList(new ArrayList<RegistrationRequestInfo>(this.rrMap.values())); |
348 | |
} |
349 | |
|
350 | |
@Override |
351 | |
public List<RegistrationRequestInfo> getRegistrationRequestsByIds(List<String> registrationRequestIds, ContextInfo contextInfo) |
352 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
353 | |
|
354 | 0 | List<RegistrationRequestInfo> ret = new ArrayList<RegistrationRequestInfo>(); |
355 | 0 | for (String id : registrationRequestIds) { |
356 | 0 | ret.add(getRegistrationRequest(id, contextInfo)); |
357 | |
} |
358 | |
|
359 | 0 | return Collections.unmodifiableList(ret); |
360 | |
} |
361 | |
|
362 | |
@Override |
363 | |
public List<String> getRegistrationRequestIdsByType(String registrationRequestTypeKey, ContextInfo contextInfo) |
364 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
365 | |
|
366 | 0 | List<String> ret = new ArrayList<String>(); |
367 | 0 | for (RegistrationRequestInfo rr : getRegistrationRequests(contextInfo)) { |
368 | 0 | if (rr.getType().equals(registrationRequestTypeKey)) { |
369 | 0 | ret.add(rr.getId()); |
370 | |
} |
371 | |
} |
372 | |
|
373 | 0 | return Collections.unmodifiableList(ret); |
374 | |
} |
375 | |
|
376 | |
@Override |
377 | |
public List<RegistrationRequestInfo> getRegistrationRequestsByRequestor(String personId, ContextInfo contextInfo) |
378 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
379 | |
|
380 | 0 | List<RegistrationRequestInfo> ret = new ArrayList<RegistrationRequestInfo>(); |
381 | 0 | for (RegistrationRequestInfo rr : getRegistrationRequests(contextInfo)) { |
382 | 0 | if (rr.getRequestorId().equals(personId)) { |
383 | 0 | ret.add(rr); |
384 | |
} |
385 | |
} |
386 | |
|
387 | 0 | return Collections.unmodifiableList(ret); |
388 | |
} |
389 | |
|
390 | |
@Override |
391 | |
public List<RegistrationRequestInfo> getUnsubmittedRegistrationRequestsByRequestorAndTerm(String requestorId, String termId, ContextInfo contextInfo) |
392 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
393 | |
|
394 | 0 | List<RegistrationRequestInfo> ret = new ArrayList<RegistrationRequestInfo>(); |
395 | 0 | for (RegistrationRequestInfo rr : getRegistrationRequestsByRequestor(requestorId, contextInfo)) { |
396 | 0 | if (rr.getStateKey().equals(LprServiceConstants.LPRTRANS_NEW_STATE_KEY) && rr.getTermId().equals(termId)) { |
397 | 0 | ret.add(rr); |
398 | |
} |
399 | |
} |
400 | |
|
401 | 0 | return Collections.unmodifiableList(ret); |
402 | |
} |
403 | |
|
404 | |
@Override |
405 | |
public List<String> searchForRegistrationRequestIds(QueryByCriteria criteria, ContextInfo contextInfo) |
406 | |
throws InvalidParameterException,MissingParameterException, OperationFailedException, PermissionDeniedException { |
407 | |
|
408 | 0 | List<String> ret = new ArrayList<String>(); |
409 | 0 | for (RegistrationRequestInfo rr : searchForRegistrationRequests(criteria, contextInfo)) { |
410 | 0 | ret.add(rr.getId()); |
411 | |
} |
412 | |
|
413 | 0 | return Collections.unmodifiableList(ret); |
414 | |
} |
415 | |
|
416 | |
@Override |
417 | |
public List<ValidationResultInfo> validateRegistrationRequest(String validationTypeKey, String registrationRequestTypeKey, RegistrationRequestInfo registrationRequestInfo, ContextInfo contextInfo) |
418 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
419 | |
|
420 | 0 | List<ValidationResultInfo> results = new ArrayList<ValidationResultInfo>(); |
421 | |
|
422 | 0 | if (!registrationRequestTypeKey.equals(LprServiceConstants.LPRTRANS_REGISTER_TYPE_KEY)) { |
423 | 0 | results.add(makeValidationError("RegistrationRequest.type", "unknown type")); |
424 | |
} |
425 | |
|
426 | 0 | if (registrationRequestInfo.getRequestorId() == null) { |
427 | 0 | results.add(makeValidationError("RegistrationRequest.requestorId", "cannot be null")); |
428 | |
} |
429 | |
|
430 | 0 | if (registrationRequestInfo.getTermId() == null) { |
431 | 0 | results.add(makeValidationError("RegistrationRequest.termId", "cannot be null")); |
432 | |
} |
433 | |
|
434 | 0 | if (registrationRequestInfo.getRegistrationRequestItems() == null) { |
435 | 0 | results.add(makeValidationError("RegistrationRequest.registrationRequestItems", "cannot be null")); |
436 | 0 | } else if (registrationRequestInfo.getRegistrationRequestItems().size() == 0) { |
437 | 0 | results.add(makeValidationError("RegistrationRequest.registrationRequestItems", "cannot be empty")); |
438 | |
} |
439 | |
|
440 | 0 | for (RegistrationRequestItem item : registrationRequestInfo.getRegistrationRequestItems()) { |
441 | 0 | if (item.getStudentId() == null) { |
442 | 0 | results.add(makeValidationError("RegistrationRequestItem.studentId", "cannot be null")); |
443 | |
} |
444 | |
|
445 | 0 | if (item.getTypeKey().equals(LprServiceConstants.LPRTRANS_ITEM_ADD_TYPE_KEY)) { |
446 | 0 | if (item.getNewRegistrationGroupId() == null) { |
447 | 0 | results.add(makeValidationError("RegistrationRequestItem.newRegistrationGroupId", "cannot be null")); |
448 | |
} |
449 | |
|
450 | 0 | if (item.getExistingRegistrationGroupId() != null) { |
451 | 0 | results.add(makeValidationError("RegistrationRequestItem.existingRegistrationGroupId", "must be null")); |
452 | |
} |
453 | |
|
454 | 0 | if (item.getCredits() == null) { |
455 | 0 | results.add(makeValidationError("RegistrationRequestItem.credits", "cannot be null")); |
456 | |
} |
457 | |
|
458 | 0 | if (item.getGradingOptionId() == null) { |
459 | 0 | results.add(makeValidationError("RegistrationRequestItem.gradingOptionId", "cannot be null")); |
460 | |
} |
461 | 0 | } else if (item.getTypeKey().equals(LprServiceConstants.LPRTRANS_ITEM_DROP_TYPE_KEY)) { |
462 | 0 | if (item.getNewRegistrationGroupId() != null) { |
463 | 0 | results.add(makeValidationError("RegistrationRequestItem.newRegistrationGroupId", "must be null")); |
464 | |
} |
465 | |
|
466 | 0 | if (item.getExistingRegistrationGroupId() == null) { |
467 | 0 | results.add(makeValidationError("RegistrationRequestItem.existingRegistrationGroupId", "cannot be null")); |
468 | |
} |
469 | |
|
470 | 0 | if (item.getCredits() != null) { |
471 | 0 | results.add(makeValidationError("RegistrationRequestItem.credits", "must be null")); |
472 | |
} |
473 | |
|
474 | 0 | if (item.getGradingOptionId() != null) { |
475 | 0 | results.add(makeValidationError("RegistrationRequestItem.gradingOptionId", "must be null")); |
476 | |
} |
477 | 0 | } else if (item.getTypeKey().equals(LprServiceConstants.LPRTRANS_ITEM_SWAP_TYPE_KEY)) { |
478 | 0 | if (item.getNewRegistrationGroupId() == null) { |
479 | 0 | results.add(makeValidationError("RegistrationRequestItem.newRegistrationGroupId", "cannot be null")); |
480 | |
} |
481 | |
|
482 | 0 | if (item.getExistingRegistrationGroupId() == null) { |
483 | 0 | results.add(makeValidationError("RegistrationRequestItem.existingRegistrationGroupId", "cannot be null")); |
484 | |
} |
485 | |
|
486 | 0 | if (item.getCredits() == null) { |
487 | 0 | results.add(makeValidationError("RegistrationRequestItem.credits", "cannot be null")); |
488 | |
} |
489 | |
|
490 | 0 | if (item.getGradingOptionId() == null) { |
491 | 0 | results.add(makeValidationError("RegistrationRequestItem.gradingOptionId", "cannot be null")); |
492 | |
} |
493 | 0 | } else if (item.getTypeKey().equals(LprServiceConstants.LPRTRANS_ITEM_UPDATE_TYPE_KEY)) { |
494 | 0 | if (item.getNewRegistrationGroupId() != null) { |
495 | 0 | results.add(makeValidationError("RegistrationRequestItem.newRegistrationGroupId", "must be null")); |
496 | |
} |
497 | |
|
498 | 0 | if (item.getExistingRegistrationGroupId() == null) { |
499 | 0 | results.add(makeValidationError("RegistrationRequestItem.existingRegistrationGroupId", "cannot be null")); |
500 | |
} |
501 | |
} else { |
502 | 0 | results.add(makeValidationError("RegistrationRequestItem.typeKey", "unknown item type")); |
503 | |
} |
504 | |
} |
505 | |
|
506 | 0 | return Collections.unmodifiableList(results); |
507 | |
} |
508 | |
|
509 | |
@Override |
510 | |
public RegistrationRequestInfo createRegistrationRequest(String registrationRequestTypeKey, RegistrationRequestInfo registrationRequestInfo, ContextInfo contextInfo) |
511 | |
throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException { |
512 | |
|
513 | 0 | List<ValidationResultInfo> results = validateRegistrationRequest("any", registrationRequestTypeKey, registrationRequestInfo, contextInfo); |
514 | 0 | if (results.size() > 0) { |
515 | 0 | throw new DataValidationErrorException("data validation error, use validateRegistrationRequest()"); |
516 | |
} |
517 | |
|
518 | 0 | RegistrationRequestInfo rr = new RegistrationRequestInfo(registrationRequestInfo); |
519 | 0 | rr.setId(newId()); |
520 | 0 | rr.setTypeKey(registrationRequestTypeKey); |
521 | 0 | rr.setStateKey(LprServiceConstants.LPRTRANS_NEW_STATE_KEY); |
522 | 0 | rr.setMeta(newMeta(contextInfo)); |
523 | |
|
524 | 0 | this.rrMap.put(rr.getId(), rr); |
525 | 0 | return rr; |
526 | |
} |
527 | |
|
528 | |
@Override |
529 | |
public RegistrationRequestInfo createRegistrationRequestFromExisting(String registrationRequestId, ContextInfo contextInfo) |
530 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
531 | |
|
532 | 0 | RegistrationRequestInfo rr = new RegistrationRequestInfo(getRegistrationRequest(registrationRequestId, contextInfo)); |
533 | 0 | rr.setMeta(null); |
534 | 0 | rr.setId(newId()); |
535 | 0 | rr.setStateKey(LprServiceConstants.LPRTRANS_NEW_STATE_KEY); |
536 | |
|
537 | 0 | List<ValidationResultInfo> results = validateRegistrationRequest("any", rr.getTypeKey(), rr, contextInfo); |
538 | 0 | if (results.size() > 0) { |
539 | 0 | throw new OperationFailedException("data validation error in copy"); |
540 | |
} |
541 | |
|
542 | 0 | this.rrMap.put(rr.getId(), rr); |
543 | |
|
544 | 0 | return rr; |
545 | |
} |
546 | |
|
547 | |
@Override |
548 | |
public RegistrationRequestInfo updateRegistrationRequest(String registrationRequestId, RegistrationRequestInfo registrationRequestInfo, ContextInfo contextInfo) |
549 | |
throws DataValidationErrorException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException, ReadOnlyException, VersionMismatchException { |
550 | |
|
551 | 0 | if (!registrationRequestId.equals(registrationRequestInfo.getId())) { |
552 | 0 | throw new InvalidParameterException("The id parameter does not match the id on the info object"); |
553 | |
} |
554 | |
|
555 | 0 | RegistrationRequestInfo copy = new RegistrationRequestInfo(registrationRequestInfo); |
556 | 0 | RegistrationRequestInfo old = getRegistrationRequest(registrationRequestId, contextInfo); |
557 | 0 | if (!old.getMeta().getVersionInd().equals(copy.getMeta().getVersionInd())) { |
558 | 0 | throw new VersionMismatchException(old.getMeta().getVersionInd()); |
559 | |
} |
560 | |
|
561 | 0 | copy.setMeta(updateMeta(copy.getMeta(), contextInfo)); |
562 | 0 | this.rrMap.put(registrationRequestId, copy); |
563 | |
|
564 | 0 | return new RegistrationRequestInfo(copy); |
565 | |
} |
566 | |
|
567 | |
@Override |
568 | |
public StatusInfo deleteRegistrationRequest(String registrationRequestId, ContextInfo contextInfo) |
569 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
570 | |
|
571 | 0 | RegistrationRequest rr = getRegistrationRequest(registrationRequestId, contextInfo); |
572 | 0 | if (rr == null) { |
573 | 0 | throw new DoesNotExistException(registrationRequestId + " not found"); |
574 | |
} |
575 | |
|
576 | 0 | if (rr.getStateKey().equals(LprServiceConstants.LPRTRANS_SUCCEEDED_STATE_KEY) || |
577 | |
rr.getStateKey().equals(LprServiceConstants.LPRTRANS_FAILED_STATE_KEY)) { |
578 | 0 | throw new OperationFailedException("cannot delete a submitted registration request, sorry"); |
579 | |
} |
580 | |
|
581 | 0 | this.rrMap.remove(registrationRequestId); |
582 | 0 | return new StatusInfo(); |
583 | |
} |
584 | |
|
585 | |
@Override |
586 | |
public List<ValidationResultInfo> verifyRegistrationRequestForSubmission(String registrationRequestId, ContextInfo contextInfo) |
587 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
588 | |
|
589 | |
|
590 | 0 | return Collections.EMPTY_LIST; |
591 | |
} |
592 | |
|
593 | |
@Override |
594 | |
public RegistrationResponseInfo submitRegistrationRequest(String registrationRequestId, ContextInfo contextInfo) |
595 | |
throws AlreadyExistsException, DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
596 | |
|
597 | |
|
598 | 0 | RegistrationRequestInfo rr = getRegistrationRequest(registrationRequestId, contextInfo); |
599 | 0 | if (!rr.getStateKey().equals(LprServiceConstants.LPRTRANS_NEW_STATE_KEY)) { |
600 | 0 | throw new AlreadyExistsException(registrationRequestId + " already submitted"); |
601 | |
} |
602 | |
|
603 | |
|
604 | 0 | List<ValidationResultInfo> results = verifyRegistrationRequestForSubmission(registrationRequestId, contextInfo); |
605 | 0 | if (results.size() > 0) { |
606 | 0 | rr.setStateKey(LprServiceConstants.LPRTRANS_FAILED_STATE_KEY); |
607 | 0 | throw new OperationFailedException("registration failed, try verifying next time"); |
608 | |
} |
609 | |
|
610 | |
|
611 | |
|
612 | |
|
613 | |
|
614 | 0 | RegistrationResponseInfo response = new RegistrationResponseInfo(); |
615 | 0 | response.setRegistrationRequestId(rr.getId()); |
616 | |
|
617 | |
|
618 | 0 | for (RegistrationRequestItemInfo item : rr.getRegistrationRequestItems()) { |
619 | |
|
620 | |
|
621 | 0 | RegistrationGroup newrg = getCourseOfferingService().getRegistrationGroup(item.getNewRegistrationGroupId(), contextInfo); |
622 | 0 | RegistrationGroup existingrg = getCourseOfferingService().getRegistrationGroup(item.getExistingRegistrationGroupId(), contextInfo); |
623 | |
|
624 | |
|
625 | 0 | if (item.getTypeKey().equals(LprServiceConstants.LPRTRANS_ITEM_ADD_TYPE_KEY)) { |
626 | |
|
627 | |
|
628 | 0 | CourseRegistrationInfo cr = new CourseRegistrationInfo(); |
629 | 0 | cr.setId(newId()); |
630 | 0 | cr.setTypeKey(LprServiceConstants.REGISTRANT_TYPE_KEY); |
631 | 0 | cr.setStateKey(LprServiceConstants.REGISTERED_STATE_KEY); |
632 | 0 | cr.setMeta(newMeta(contextInfo)); |
633 | 0 | cr.setStudentId(item.getStudentId()); |
634 | 0 | cr.setCourseOfferingId(newrg.getCourseOfferingId()); |
635 | 0 | cr.setCredits(item.getCredits()); |
636 | 0 | cr.setGradingOptionId(item.getGradingOptionId()); |
637 | 0 | this.crMap.put(cr.getId(), cr); |
638 | |
|
639 | |
|
640 | 0 | List<RegistrationRequestItemInfo> items = this.xactionMap.get(cr.getId()); |
641 | 0 | if (items == null) { |
642 | 0 | items = new ArrayList<RegistrationRequestItemInfo>(); |
643 | 0 | this.xactionMap.put(cr.getId(), items); |
644 | |
} |
645 | |
|
646 | 0 | items.add(item); |
647 | |
|
648 | 0 | items = this.studentMap.get(item.getStudentId()); |
649 | 0 | if (items == null) { |
650 | 0 | items = new ArrayList<RegistrationRequestItemInfo>(); |
651 | 0 | this.xactionMap.put(item.getStudentId(), items); |
652 | |
} |
653 | |
|
654 | 0 | items.add(item); |
655 | |
|
656 | |
|
657 | 0 | for (String activityId : newrg.getActivityOfferingIds()) { |
658 | 0 | ActivityRegistrationInfo ar = new ActivityRegistrationInfo(); |
659 | 0 | ar.setId(newId()); |
660 | 0 | ar.setTypeKey(LprServiceConstants.REGISTRANT_TYPE_KEY); |
661 | 0 | ar.setStateKey(LprServiceConstants.REGISTERED_STATE_KEY); |
662 | 0 | ar.setMeta(newMeta(contextInfo)); |
663 | 0 | ar.setStudentId(item.getStudentId()); |
664 | 0 | ar.setActivityOfferingId(activityId); |
665 | 0 | this.arMap.put(ar.getId(), ar); |
666 | |
|
667 | |
|
668 | 0 | List<ActivityRegistrationInfo> ars = this.regMap.get(cr.getId()); |
669 | 0 | if (ars == null) { |
670 | 0 | ars = new ArrayList<ActivityRegistrationInfo>(); |
671 | 0 | this.regMap.put(cr.getId(), ars); |
672 | |
} |
673 | |
|
674 | 0 | ars.add(ar); |
675 | 0 | } |
676 | |
|
677 | |
|
678 | 0 | item.setStateKey(LprServiceConstants.LPRTRANS_SUCCEEDED_STATE_KEY); |
679 | |
|
680 | |
|
681 | 0 | RegistrationResponseItemInfo responseItem = new RegistrationResponseItemInfo(); |
682 | 0 | responseItem.setRegistrationRequestItemId(item.getId()); |
683 | 0 | OperationStatusInfo status = new OperationStatusInfo(); |
684 | 0 | status.setStatus("ok"); |
685 | 0 | responseItem.setOperationStatus(status); |
686 | 0 | responseItem.setCourseRegistrationId(cr.getId()); |
687 | 0 | response.getRegistrationResponseItems().add(responseItem); |
688 | |
|
689 | 0 | } else if (item.getTypeKey().equals(LprServiceConstants.LPRTRANS_ITEM_DROP_TYPE_KEY)) { |
690 | |
|
691 | 0 | } else if (item.getTypeKey().equals(LprServiceConstants.LPRTRANS_ITEM_SWAP_TYPE_KEY)) { |
692 | |
|
693 | 0 | } else if (item.getTypeKey().equals(LprServiceConstants.LPRTRANS_ITEM_UPDATE_TYPE_KEY)) { |
694 | |
|
695 | |
} |
696 | 0 | } |
697 | |
|
698 | 0 | rr.setStateKey(LprServiceConstants.LPRTRANS_SUCCEEDED_STATE_KEY); |
699 | |
|
700 | 0 | OperationStatusInfo status = new OperationStatusInfo(); |
701 | 0 | status.setStatus("ok"); |
702 | |
|
703 | 0 | return response; |
704 | |
} |
705 | |
|
706 | |
@Override |
707 | |
public List<RegistrationRequestItemInfo> getRegistrationRequestItemsForCourseRegistration(String courseRegistrationId, ContextInfo contextInfo) |
708 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
709 | |
|
710 | 0 | List <RegistrationRequestItemInfo> items = this.xactionMap.get(courseRegistrationId); |
711 | 0 | if (items == null) { |
712 | 0 | return Collections.EMPTY_LIST; |
713 | |
} else { |
714 | 0 | return Collections.unmodifiableList(items); |
715 | |
} |
716 | |
} |
717 | |
|
718 | |
@Override |
719 | |
public List<RegistrationRequestItemInfo> getRegistrationRequestItemsByCourseOfferingAndStudent(String courseOfferingId, String studentId, ContextInfo contextInfo) |
720 | |
throws InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
721 | |
|
722 | 0 | List <RegistrationRequestItemInfo> ret = new ArrayList<RegistrationRequestItemInfo>(); |
723 | |
|
724 | 0 | for (RegistrationRequestItemInfo rri : this.studentMap.get(studentId)) { |
725 | |
try { |
726 | 0 | for (RegistrationGroup rg : getCourseOfferingService().getRegistrationGroupsForCourseOffering(courseOfferingId, contextInfo)) { |
727 | 0 | if (rri.getNewRegistrationGroupId().equals(rg.getId()) || |
728 | |
rri.getExistingRegistrationGroupId().equals(rg.getId())) { |
729 | 0 | ret.add(rri); |
730 | |
} |
731 | |
} |
732 | 0 | } catch (DoesNotExistException dne) {} |
733 | |
} |
734 | |
|
735 | 0 | return Collections.unmodifiableList(ret); |
736 | |
} |
737 | |
|
738 | |
@Override |
739 | |
public List<ValidationResultInfo> checkStudentEligibility(String studentId, ContextInfo contextInfo) |
740 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
741 | |
|
742 | 0 | List<ValidationResultInfo> results = new ArrayList<ValidationResultInfo>(); |
743 | 0 | if (studentId.equals("norm")) { |
744 | 0 | results.add(makeValidationError("basic elegibility", "norm can't register")); |
745 | |
} |
746 | |
|
747 | 0 | return Collections.unmodifiableList(results); |
748 | |
} |
749 | |
|
750 | |
@Override |
751 | |
public List<ValidationResultInfo> checkStudentEligibilityForTerm(String studentId, String termId, ContextInfo contextInfo) |
752 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
753 | |
|
754 | 0 | List<ValidationResultInfo> results = new ArrayList<ValidationResultInfo>(); |
755 | 0 | if (studentId.equals("norm")) { |
756 | 0 | results.add(makeValidationError("elegibility for term", "norm can't register this term")); |
757 | |
} |
758 | |
|
759 | 0 | return Collections.unmodifiableList(results); |
760 | |
} |
761 | |
|
762 | |
@Override |
763 | |
public List<ValidationResultInfo> checkStudentEligibiltyForCourseOffering(String studentId, String courseOfferingId, ContextInfo contextInfo) |
764 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
765 | |
|
766 | 0 | List<ValidationResultInfo> results = new ArrayList<ValidationResultInfo>(); |
767 | 0 | if (studentId.equals("norm") && courseOfferingId.equals("recursion101")) { |
768 | 0 | results.add(makeValidationError("elegibility forcourse offering", "norm can't register in this class")); |
769 | |
} |
770 | |
|
771 | 0 | return Collections.unmodifiableList(results); |
772 | |
} |
773 | |
|
774 | |
@Override |
775 | |
public List<ValidationResultInfo> checkStudentEligibiltyForRegistrationGroup(String studentId, String registrationGroupId, ContextInfo contextInfo) |
776 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
777 | |
|
778 | 0 | return Collections.EMPTY_LIST; |
779 | |
} |
780 | |
|
781 | |
@Override |
782 | |
public List<CreditLoadInfo> calculateCreditLoadForRegistrationRequest(String registrationRequestId, ContextInfo contextInfo) |
783 | |
throws DoesNotExistException, InvalidParameterException, MissingParameterException, OperationFailedException, PermissionDeniedException { |
784 | |
|
785 | 0 | RegistrationRequest rr = getRegistrationRequest(registrationRequestId, contextInfo); |
786 | 0 | Map<String, CreditLoadInfo> map = new HashMap<String, CreditLoadInfo>(); |
787 | |
|
788 | 0 | for (RegistrationRequestItem item : rr.getRegistrationRequestItems()) { |
789 | 0 | CreditLoadInfo load = map.get(item.getStudentId()); |
790 | 0 | if (load == null) { |
791 | 0 | load = new CreditLoadInfo(); |
792 | 0 | load.setStudentId(item.getStudentId()); |
793 | 0 | load.setCreditLimit(CREDIT_LIMIT); |
794 | 0 | map.put(item.getStudentId(), load); |
795 | |
} |
796 | |
|
797 | 0 | if (item.getTypeKey().equals(LprServiceConstants.LPRTRANS_ITEM_ADD_TYPE_KEY)) { |
798 | 0 | load.setAdditionalCredits((new BigDecimal(item.getCredits())).add(new BigDecimal(load.getAdditionalCredits())).toString()); |
799 | 0 | } else if (item.getTypeKey().equals(LprServiceConstants.LPRTRANS_ITEM_DROP_TYPE_KEY)) { |
800 | |
|
801 | |
} |
802 | 0 | } |
803 | |
|
804 | 0 | return Collections.unmodifiableList(new ArrayList<CreditLoadInfo>(map.values())); |
805 | |
} |
806 | |
|
807 | |
|
808 | |
private static String newId() { |
809 | 0 | return Long.toString(++id); |
810 | |
} |
811 | |
|
812 | |
private static MetaInfo newMeta(ContextInfo contextInfo) { |
813 | 0 | MetaInfo meta = new MetaInfo(); |
814 | 0 | meta.setCreateId(contextInfo.getPrincipalId()); |
815 | 0 | meta.setCreateTime(new Date()); |
816 | 0 | meta.setUpdateId(contextInfo.getPrincipalId()); |
817 | 0 | meta.setUpdateTime(meta.getCreateTime()); |
818 | 0 | meta.setVersionInd("0"); |
819 | 0 | return meta; |
820 | |
} |
821 | |
|
822 | |
private static StatusInfo newStatus() { |
823 | 0 | StatusInfo status = new StatusInfo(); |
824 | 0 | status.setSuccess(Boolean.TRUE); |
825 | 0 | return status; |
826 | |
} |
827 | |
|
828 | |
private static MetaInfo updateMeta(MetaInfo old, ContextInfo contextInfo) { |
829 | 0 | MetaInfo meta = new MetaInfo(old); |
830 | 0 | meta.setUpdateId(contextInfo.getPrincipalId()); |
831 | 0 | meta.setUpdateTime(new Date()); |
832 | 0 | meta.setVersionInd((Integer.parseInt(meta.getVersionInd()) + 1) + ""); |
833 | 0 | return meta; |
834 | |
} |
835 | |
|
836 | |
private static ValidationResultInfo makeValidationError(String element, String message) { |
837 | 0 | ValidationResultInfo vr = new ValidationResultInfo(); |
838 | 0 | vr.setLevel(ValidationResult.ErrorLevel.ERROR); |
839 | 0 | vr.setElement(element); |
840 | 0 | vr.setMessage(message); |
841 | 0 | return vr; |
842 | |
} |
843 | |
} |