1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.enrollment.class2.registration.controller;
17
18 import org.apache.commons.collections.CollectionUtils;
19 import org.apache.commons.lang.StringUtils;
20 import org.apache.ojb.broker.cache.RuntimeCacheException;
21 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
22 import org.kuali.rice.core.api.util.RiceKeyConstants;
23 import org.kuali.rice.krad.uif.UifParameters;
24 import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
25 import org.kuali.rice.krad.util.GlobalVariables;
26 import org.kuali.rice.krad.util.KRADConstants;
27 import org.kuali.rice.krad.web.controller.UifControllerBase;
28 import org.kuali.rice.krad.web.form.UifFormBase;
29 import org.kuali.student.r1.core.statement.dto.StatementTreeViewInfo;
30 import org.kuali.student.r1.core.statement.service.StatementService;
31 import org.kuali.student.enrollment.class2.registration.dto.ActivityOfferingWrapper;
32 import org.kuali.student.enrollment.class2.registration.dto.CourseOfferingWrapper;
33 import org.kuali.student.enrollment.class2.registration.dto.MeetingScheduleWrapper;
34 import org.kuali.student.enrollment.class2.registration.dto.RegistrationGroupWrapper;
35 import org.kuali.student.enrollment.class2.registration.form.RegistrationForm;
36 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo;
37 import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
38 import org.kuali.student.enrollment.courseoffering.dto.RegistrationGroupInfo;
39 import org.kuali.student.enrollment.courseoffering.infc.RegistrationGroup;
40 import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
41 import org.kuali.student.enrollment.courseregistration.dto.CourseRegistrationInfo;
42 import org.kuali.student.enrollment.courseregistration.dto.RegistrationRequestInfo;
43 import org.kuali.student.enrollment.courseregistration.dto.RegistrationRequestItemInfo;
44 import org.kuali.student.enrollment.courseregistration.dto.RegistrationResponseInfo;
45 import org.kuali.student.enrollment.courseregistration.infc.RegistrationRequest;
46 import org.kuali.student.enrollment.courseregistration.infc.RegistrationRequestItem;
47 import org.kuali.student.enrollment.courseregistration.service.CourseRegistrationService;
48 import org.kuali.student.r2.lum.course.service.CourseService;
49 import org.kuali.student.r2.lum.util.constants.CourseServiceConstants;
50 import org.kuali.student.r2.common.dto.ContextInfo;
51 import org.kuali.student.r2.common.dto.MeetingScheduleInfo;
52 import org.kuali.student.r2.common.dto.ValidationResultInfo;
53 import org.kuali.student.r2.common.exceptions.*;
54 import org.kuali.student.r2.common.infc.Context;
55 import org.kuali.student.r2.common.util.constants.LprServiceConstants;
56 import org.springframework.stereotype.Controller;
57 import org.springframework.validation.BindingResult;
58 import org.springframework.web.bind.annotation.ModelAttribute;
59 import org.springframework.web.bind.annotation.RequestMapping;
60 import org.springframework.web.bind.annotation.RequestMethod;
61 import org.springframework.web.servlet.ModelAndView;
62
63 import javax.servlet.http.HttpServletRequest;
64 import javax.servlet.http.HttpServletResponse;
65 import javax.xml.namespace.QName;
66 import java.util.ArrayList;
67 import java.util.Collection;
68 import java.util.Iterator;
69 import java.util.List;
70
71 @Controller
72 @RequestMapping(value = "/registration")
73
74 @Deprecated
75 public class RegistrationController extends UifControllerBase {
76
77 private transient CourseOfferingService courseOfferingService;
78 private transient StatementService statementService;
79 private transient CourseService courseService;
80 private transient CourseRegistrationService courseRegistrationService;
81
82 protected UifFormBase createInitialForm(HttpServletRequest httpServletRequest) {
83 return new RegistrationForm();
84 }
85
86 protected RegistrationRequestInfo generateNewRegRequestInfo(ContextInfo context, RegistrationForm regForm){
87 String id = context.getPrincipalId();
88 RegistrationRequestInfo info = new RegistrationRequestInfo();
89 info.setTermId(regForm.getTermId());
90 info.setStateKey(LprServiceConstants.LPRTRANS_ITEM_NEW_STATE_KEY);
91 info.setTypeKey(LprServiceConstants.LPRTRANS_REGISTER_TYPE_KEY);
92 info.setRequestorId(id);
93 info.setRegistrationRequestItems(new ArrayList<RegistrationRequestItemInfo>());
94 return info;
95 }
96
97 protected RegistrationRequestItemInfo generateRegRequestItem(RegistrationGroupWrapper regGroupWrapper, Context context){
98 RegistrationRequestItemInfo regRequestItem = new RegistrationRequestItemInfo();
99 regRequestItem.setTypeKey(LprServiceConstants.LPRTRANS_ITEM_ADD_TYPE_KEY);
100 regRequestItem.setStateKey(LprServiceConstants.LPRTRANS_ITEM_NEW_STATE_KEY);
101 regRequestItem.setStudentId(context.getPrincipalId());
102 regRequestItem.setNewRegistrationGroupId(regGroupWrapper.getRegistrationGroup().getId());
103
104 regRequestItem.setGradingOptionId("kuali.grading.option.RVG1");
105 regRequestItem.setName(regGroupWrapper.getRegistrationGroup().getName());
106 regRequestItem.setOkToHoldUntilList(false);
107 regRequestItem.setOkToWaitlist(true);
108 return regRequestItem;
109 }
110
111 protected RegistrationRequestItemInfo generateDropRegRequestItem(RegistrationGroupWrapper regGroupWrapper, Context context){
112 RegistrationRequestItemInfo regRequestItem = new RegistrationRequestItemInfo();
113 regRequestItem.setTypeKey(LprServiceConstants.LPRTRANS_ITEM_DROP_TYPE_KEY);
114 regRequestItem.setStateKey(LprServiceConstants.LPRTRANS_ITEM_NEW_STATE_KEY);
115 regRequestItem.setStudentId(context.getPrincipalId());
116 regRequestItem.setExistingRegistrationGroupId(regGroupWrapper.getRegistrationGroup().getId());
117
118 regRequestItem.setGradingOptionId("kuali.grading.option.RVG1");
119 regRequestItem.setName(regGroupWrapper.getRegistrationGroup().getName());
120 regRequestItem.setOkToHoldUntilList(false);
121 regRequestItem.setOkToWaitlist(true);
122 return regRequestItem;
123 }
124
125 protected RegistrationGroupWrapper findRegGroupByIndex(RegistrationForm registrationForm){
126
127 String selectedCollectionPath = registrationForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
128 if (StringUtils.isBlank(selectedCollectionPath)) {
129 throw new RuntimeException("Selected collection was not set for registration line action, cannot register line");
130 }
131
132 int selectedLineIndex = -1;
133 String selectedLine = registrationForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX);
134 if (StringUtils.isNotBlank(selectedLine)) {
135 selectedLineIndex = Integer.parseInt(selectedLine);
136 }
137
138 if (selectedLineIndex == -1) {
139 throw new RuntimeException("Selected line index was not set for registration line action, cannot register line");
140 }
141
142
143 Collection<Object> collection = ObjectPropertyUtils.getPropertyValue(registrationForm, selectedCollectionPath);
144 if (collection == null) {
145 throw new RuntimeException("Unable to get registration group collection property from RegistrationForm for path: " + selectedCollectionPath);
146 }
147
148 if (collection instanceof List) {
149 return (RegistrationGroupWrapper) ((List<Object>) collection).get(selectedLineIndex);
150 }
151 else {
152 throw new RuntimeException("Only List collection implementations are supported for findRegGroup by index method");
153 }
154 }
155
156 protected List<CourseRegistrationInfo> getCourseRegistrations(String studentId, String termKey, ContextInfo context) throws InvalidParameterException, MissingParameterException, DisabledIdentifierException, DoesNotExistException, PermissionDeniedException, OperationFailedException {
157 if (getCourseRegistrationService() != null) {
158 return getCourseRegistrationService().getCourseRegistrationsByStudentAndTerm(studentId, termKey, context);
159 }
160 return new ArrayList<CourseRegistrationInfo>(); }
161
162
163
164
165
166
167
168 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=showRegistration")
169 public ModelAndView showRegistration(@ModelAttribute("KualiForm") UifFormBase formBase, BindingResult result,
170 HttpServletRequest request, HttpServletResponse response) {
171 ContextInfo context = new ContextInfo();
172 RegistrationForm regForm = (RegistrationForm) formBase;
173 try {
174 regForm.setCourseRegistrations(getCourseRegistrations(context.getPrincipalId(), regForm.getTermId(), context));
175
176
177
178
179
180 List<RegistrationRequestInfo> regRequestInfos = new ArrayList<RegistrationRequestInfo>();
181 RegistrationRequestInfo regRequest = null;
182 if(regRequestInfos != null){
183 for(RegistrationRequestInfo info: regRequestInfos){
184 if(regRequest != null && regRequest.getMeta().getCreateTime().before(info.getMeta().getCreateTime())){
185 regRequest = info;
186 }
187 else if(regRequest == null){
188 regRequest = info;
189 }
190 }
191 }
192
193 regForm.setRegRequest(regRequest);
194 if(regRequest != null && regRequest.getRegistrationRequestItems() != null){
195 for(RegistrationRequestItemInfo item: regRequest.getRegistrationRequestItems()){
196 if(StringUtils.isNotBlank(item.getNewRegistrationGroupId())){
197 RegistrationGroupInfo regGroup = getCourseOfferingService().getRegistrationGroup(item.getNewRegistrationGroupId(), context);
198 CourseOfferingInfo courseOffering = getCourseOfferingService().getCourseOffering(regGroup.getCourseOfferingId(), context);
199 RegistrationGroupWrapper registrationGroupWrapper = new RegistrationGroupWrapper();
200 registrationGroupWrapper.setRegistrationGroup(regGroup);
201 registrationGroupWrapper.setCourseOffering(courseOffering);
202 registrationGroupWrapper.setActivityOfferingWrappers(getActivityOfferingInfos(regGroup, courseOffering, context));
203 regForm.getRegistrationGroupWrappersById().put(registrationGroupWrapper.getRegistrationGroup().getId(), registrationGroupWrapper);
204 }
205 if(StringUtils.isNotBlank(item.getExistingRegistrationGroupId())){
206 RegistrationGroupInfo regGroup = getCourseOfferingService().getRegistrationGroup(item.getExistingRegistrationGroupId(), context);
207 CourseOfferingInfo courseOffering = getCourseOfferingService().getCourseOffering(regGroup.getCourseOfferingId(), context);
208 RegistrationGroupWrapper registrationGroupWrapper = new RegistrationGroupWrapper();
209 registrationGroupWrapper.setRegistrationGroup(regGroup);
210 registrationGroupWrapper.setCourseOffering(courseOffering);
211 registrationGroupWrapper.setActivityOfferingWrappers(getActivityOfferingInfos(regGroup, courseOffering, context));
212 regForm.getRegistrationGroupWrappersById().put(registrationGroupWrapper.getRegistrationGroup().getId(), registrationGroupWrapper);
213 }
214 }
215 }
216
217
218 return getUIFModelAndView(regForm, "registrationPage");
219 } catch (InvalidParameterException e) {
220 throw new RuntimeException(e);
221 } catch (MissingParameterException e) {
222 throw new RuntimeException(e);
223 } catch (OperationFailedException e) {
224 throw new RuntimeException(e);
225 } catch (PermissionDeniedException e) {
226 throw new RuntimeException(e);
227 } catch (DisabledIdentifierException e) {
228 throw new RuntimeException(e);
229 } catch (DoesNotExistException e) {
230 throw new RuntimeException(e);
231 }
232 }
233
234
235
236
237 @RequestMapping(params = "methodToCall=searchCourseOfferings")
238 public ModelAndView searchCourseOfferings(@ModelAttribute("KualiForm") RegistrationForm registrationForm, BindingResult result,
239 HttpServletRequest request, HttpServletResponse response) {
240 ContextInfo context = new ContextInfo();
241
242 try {
243 List<String> courseOfferingIds = getCourseOfferingIds(registrationForm, context);
244 registrationForm.setCourseOfferingWrappers(new ArrayList<CourseOfferingWrapper>(courseOfferingIds.size()));
245
246 for (String coId : courseOfferingIds) {
247 CourseOfferingWrapper courseOfferingWrapper = new CourseOfferingWrapper();
248 String prereq = "none";
249 courseOfferingWrapper.setCourseOffering(getCourseOfferingService().getCourseOffering(coId, context));
250
251 List<StatementTreeViewInfo> statements = getCourseService().getCourseStatements(courseOfferingWrapper.getCourseOffering().getCourseId(),"KUALI.RULE", "en", context);
252 if(statements != null && !statements.isEmpty()){
253 for(StatementTreeViewInfo statement: statements){
254 if(statement.getType().equals("kuali.statement.type.course.academicReadiness.studentEligibilityPrereq")){
255 prereq = getStatementService().getNaturalLanguageForStatement(statement.getId(),"KUALI.RULE","en");
256 break;
257 }
258 }
259 }
260 courseOfferingWrapper.setPrereq(prereq);
261 List<RegistrationGroupInfo> regGroups = getRegistrationGroupInfos(coId, context);
262
263 List<RegistrationGroupWrapper> registrationGroupWrappers = new ArrayList<RegistrationGroupWrapper>(regGroups.size());
264 for (RegistrationGroupInfo regGroup : regGroups) {
265 RegistrationGroupWrapper registrationGroupWrapper = new RegistrationGroupWrapper();
266 registrationGroupWrapper.setRegistrationGroup(regGroup);
267 registrationGroupWrapper.setCourseOffering(courseOfferingWrapper.getCourseOffering());
268 registrationGroupWrapper.setActivityOfferingWrappers(getActivityOfferingInfos(regGroup, courseOfferingWrapper.getCourseOffering(), context));
269 registrationGroupWrappers.add(registrationGroupWrapper);
270 }
271 courseOfferingWrapper.setRegistrationGroupWrappers(registrationGroupWrappers);
272 registrationForm.getCourseOfferingWrappers().add(courseOfferingWrapper);
273 }
274
275 } catch (DoesNotExistException e) {
276 throw new RuntimeException(e);
277 } catch (InvalidParameterException e) {
278 throw new RuntimeException(e);
279 } catch (MissingParameterException e) {
280 throw new RuntimeException(e);
281 } catch (OperationFailedException e) {
282 throw new RuntimeException(e);
283 } catch (PermissionDeniedException e) {
284 throw new RuntimeException(e);
285 } catch (Exception e) {
286 throw new RuntimeException(e);
287 }
288 return getUIFModelAndView(registrationForm);
289 }
290
291 protected List<String> getCourseOfferingIds(RegistrationForm registrationForm, ContextInfo context) throws InvalidParameterException, MissingParameterException, DoesNotExistException, PermissionDeniedException, OperationFailedException {
292
293 if (StringUtils.isNotBlank(registrationForm.getCourseOfferingCode())) {
294 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_CUSTOM, "Searching by Course Offering Code is not yet implemented");
295 return new ArrayList<String>();
296 } else {
297 return getCourseOfferingService().getCourseOfferingIdsByTermAndSubjectArea(registrationForm.getTermId(), registrationForm.getSubjectArea(), context);
298 }
299 }
300
301 protected List<RegistrationGroupInfo> getRegistrationGroupInfos(String coId, ContextInfo context) throws InvalidParameterException, MissingParameterException, DoesNotExistException, PermissionDeniedException, OperationFailedException {
302 return getCourseOfferingService().getRegistrationGroupsForCourseOffering(coId, context);
303 }
304
305 protected List<ActivityOfferingWrapper> getActivityOfferingInfos(RegistrationGroup regGroup, CourseOfferingInfo courseOfferingInfo, ContextInfo context) throws InvalidParameterException, MissingParameterException, DoesNotExistException, PermissionDeniedException, OperationFailedException {
306
307
308 List<ActivityOfferingWrapper> activityOfferingWrappers = new ArrayList<ActivityOfferingWrapper>(regGroup.getActivityOfferingIds().size());
309 for (String activityId : regGroup.getActivityOfferingIds()) {
310 ActivityOfferingInfo activityOfferingInfo = getCourseOfferingService().getActivityOffering(activityId, context);
311 ActivityOfferingWrapper wrapper = new ActivityOfferingWrapper();
312 wrapper.setActivityOffering(activityOfferingInfo);
313 wrapper.setMeetingScheduleWrappers(setupMeetingScheduleInfos(courseOfferingInfo, activityOfferingInfo));
314 activityOfferingWrappers.add(wrapper);
315 }
316
317
318 StringBuilder builder = new StringBuilder();
319 for (ActivityOfferingWrapper a : activityOfferingWrappers) {
320 for (MeetingScheduleWrapper m : a.getMeetingScheduleWrappers()) {
321 if (StringUtils.isNotBlank(builder.toString())) {
322 builder.append(",");
323 }
324 builder.append(m.getJsScheduleObject());
325 }
326 }
327 String times = "[" + builder.toString() + "]";
328 for (ActivityOfferingWrapper a : activityOfferingWrappers) {
329 for (MeetingScheduleWrapper m : a.getMeetingScheduleWrappers()) {
330 m.setRegGroupTimesJsObject(times);
331 }
332 }
333 return activityOfferingWrappers;
334 }
335
336 protected List<MeetingScheduleWrapper> setupMeetingScheduleInfos(CourseOfferingInfo courseOfferingInfo, ActivityOfferingInfo activityOfferingInfo) {
337 List<MeetingScheduleWrapper> wrappers = new ArrayList<MeetingScheduleWrapper>();
338
339 List<MeetingScheduleInfo> list = new ArrayList<MeetingScheduleInfo> ();
340 for (MeetingScheduleInfo meetingScheduleInfo : list) {
341 MeetingScheduleWrapper wrapper = new MeetingScheduleWrapper(meetingScheduleInfo);
342 wrapper.setCourseTitle(courseOfferingInfo.getCourseOfferingTitle());
343 wrapper.setCourseOfferingCode(courseOfferingInfo.getCourseOfferingCode());
344 wrappers.add(wrapper);
345 }
346 return wrappers;
347 }
348
349 @RequestMapping(params = "methodToCall=dropClass")
350 public ModelAndView dropClass(@ModelAttribute("KualiForm") RegistrationForm registrationForm, BindingResult result,
351 HttpServletRequest request, HttpServletResponse response) {
352 ContextInfo context = new ContextInfo();
353 RegistrationGroupWrapper regGroupWrapper = findRegGroupByIndex(registrationForm);
354
355 try {
356 RegistrationRequestInfo regRequest = generateNewRegRequestInfo(context, registrationForm);
357 RegistrationRequestItemInfo regRequestItem = generateDropRegRequestItem(regGroupWrapper, context);
358
359 regRequest.getRegistrationRequestItems().add(regRequestItem);
360
361 String validationTypeKey = "FIXME";
362 String regRequestTypeKey = "FIXME";
363
364 List<ValidationResultInfo> validationResultInfos = getCourseRegistrationService().validateRegistrationRequest(validationTypeKey, regRequestTypeKey, regRequest, context);
365 if (CollectionUtils.isEmpty(validationResultInfos)) {
366 regRequest = getCourseRegistrationService().createRegistrationRequest(regRequestTypeKey, regRequest, context);
367 registrationForm.getRegistrationGroupWrappersById().put(regGroupWrapper.getRegistrationGroup().getId(), regGroupWrapper);
368 } else {
369 StringBuilder builder = new StringBuilder("Found multiple ValidationResultInfo objects after Registration Request validation:\n");
370 for (ValidationResultInfo resultInfo : validationResultInfos) {
371 builder.append(resultInfo.getMessage()).append("\n");
372 }
373 throw new RuntimeException(builder.toString());
374 }
375
376 processSubmitRegRequest(regRequest, registrationForm, true);
377 } catch (InvalidParameterException e) {
378 throw new RuntimeException(e);
379 } catch (DataValidationErrorException e) {
380 throw new RuntimeException(e);
381 } catch (DoesNotExistException e) {
382 throw new RuntimeException(e);
383 } catch (PermissionDeniedException e) {
384 throw new RuntimeException(e);
385 } catch (OperationFailedException e) {
386 throw new RuntimeException(e);
387 } catch (MissingParameterException e) {
388 throw new RuntimeException(e);
389 } catch (ReadOnlyException e) {
390 throw new RuntimeException(e);
391 }
392
393
394 return getUIFModelAndView(registrationForm);
395 }
396
397 @RequestMapping(params = "methodToCall=registerClass")
398 public ModelAndView registerClass(@ModelAttribute("KualiForm") RegistrationForm registrationForm, BindingResult result,
399 HttpServletRequest request, HttpServletResponse response) {
400 ContextInfo context = new ContextInfo();
401 RegistrationGroupWrapper regGroupWrapper = findRegGroupByIndex(registrationForm);
402
403 try {
404 RegistrationRequestInfo regRequest = generateNewRegRequestInfo(context, registrationForm);
405 RegistrationRequestItemInfo regRequestItem = generateRegRequestItem(regGroupWrapper, context);
406
407 regRequest.getRegistrationRequestItems().add(regRequestItem);
408
409 String validationTypeKey = "FIXME";
410 String regRequestTypeKey = "FIXME";
411
412 List<ValidationResultInfo> validationResultInfos = getCourseRegistrationService().validateRegistrationRequest(validationTypeKey, regRequestTypeKey, regRequest, context);
413 if (CollectionUtils.isEmpty(validationResultInfos)) {
414 regRequest = getCourseRegistrationService().createRegistrationRequest(regRequestTypeKey, regRequest, context);
415 registrationForm.getRegistrationGroupWrappersById().put(regGroupWrapper.getRegistrationGroup().getId(), regGroupWrapper);
416 } else {
417 StringBuilder builder = new StringBuilder("Found multiple ValidationResultInfo objects after Registration Request validation:\n");
418 for (ValidationResultInfo resultInfo : validationResultInfos) {
419 builder.append(resultInfo.getMessage()).append("\n");
420 }
421 throw new RuntimeException(builder.toString());
422 }
423
424 processSubmitRegRequest(regRequest, registrationForm, true);
425 } catch (InvalidParameterException e) {
426 throw new RuntimeException(e);
427 } catch (DataValidationErrorException e) {
428 throw new RuntimeException(e);
429 } catch (DoesNotExistException e) {
430 throw new RuntimeException(e);
431 } catch (PermissionDeniedException e) {
432 throw new RuntimeException(e);
433 } catch (OperationFailedException e) {
434 throw new RuntimeException(e);
435 } catch (MissingParameterException e) {
436 throw new RuntimeException(e);
437 } catch (ReadOnlyException e) {
438 throw new RuntimeException(e);
439 }
440
441
442 return getUIFModelAndView(registrationForm);
443 }
444
445 @RequestMapping(params = "methodToCall=submitRegistration")
446 public ModelAndView submitRegistration(@ModelAttribute("KualiForm") RegistrationForm registrationForm, BindingResult result,
447 HttpServletRequest request, HttpServletResponse response) {
448 processSubmitRegRequest(registrationForm.getRegRequest(), registrationForm, false);
449 return getUIFModelAndView(registrationForm);
450 }
451
452 protected void processSubmitRegRequest(RegistrationRequestInfo regRequest, RegistrationForm registrationForm, boolean oneClick) {
453 ContextInfo context = new ContextInfo();
454 try {
455 String validationTypeKey = "FIXME";
456 String regRequestTypeKey = "FIXME";
457
458
459 List<ValidationResultInfo> validationResultInfos = getCourseRegistrationService().validateRegistrationRequest(validationTypeKey, regRequestTypeKey, regRequest, context);
460 if (CollectionUtils.isEmpty(validationResultInfos)) {
461
462 RegistrationResponseInfo regResponse = getCourseRegistrationService().submitRegistrationRequest(regRequest.getId(), context);
463
464 if (!regResponse.getHasFailed()) {
465 GlobalVariables.getMessageMap().putInfo("GLOBAL_INFO", "enroll.registrationSuccessful");
466
467
468 if (!oneClick) {
469 registrationForm.setRegRequest(null);
470 }
471 registrationForm.setCourseRegistrations(getCourseRegistrations(context.getPrincipalId(), registrationForm.getTermId(), context));
472 } else {
473 if (regResponse.getMessages().isEmpty()) {
474 GlobalVariables.getMessageMap().putError("GLOBAL_ERRORS", "enroll.registrationUnsuccessful");
475 }
476 }
477
478 if (!regResponse.getMessages().isEmpty()) {
479 for (String message : regResponse.getMessages()) {
480 GlobalVariables.getMessageMap().putError("GLOBAL_ERRORS", "error.enroll.requirementsNotMet", message);
481 }
482 }
483 } else {
484 GlobalVariables.getMessageMap().putError("GLOBAL_ERRORS", "enroll.registrationUnsuccessful");
485 StringBuilder builder = new StringBuilder("Found multiple ValidationResultInfo objects after Registration Request validation:\n");
486 for (ValidationResultInfo resultInfo : validationResultInfos) {
487 builder.append(resultInfo.getMessage()).append("\n");
488 }
489 throw new RuntimeException(builder.toString());
490 }
491 } catch (DoesNotExistException e) {
492 throw new RuntimeException(e);
493 } catch (InvalidParameterException e) {
494 throw new RuntimeException(e);
495 } catch (MissingParameterException e) {
496 throw new RuntimeException(e);
497 } catch (OperationFailedException e) {
498 throw new RuntimeException(e);
499 } catch (PermissionDeniedException e) {
500 throw new RuntimeException(e);
501 } catch (AlreadyExistsException e) {
502 throw new RuntimeException(e);
503 } catch (DisabledIdentifierException e) {
504 throw new RuntimeException(e);
505 }
506 }
507
508
509
510
511 @RequestMapping(params = "methodToCall=removeFromCart")
512 public ModelAndView removeFromCart(@ModelAttribute("KualiForm") RegistrationForm registrationForm, BindingResult result,
513 HttpServletRequest request, HttpServletResponse response) {
514 ContextInfo context = new ContextInfo();
515
516 RegistrationRequest regRequest = registrationForm.getRegRequest();
517 String id = registrationForm.getActionParamaterValue("itemId");
518 String regGroupId = "";
519
520 if(StringUtils.isBlank(id)){
521 RegistrationGroupWrapper regGroupWrapper = findRegGroupByIndex(registrationForm);
522 regGroupId = regGroupWrapper.getRegistrationGroup().getId();
523 }
524
525 if(regRequest != null){
526 List<? extends RegistrationRequestItem> items = regRequest.getRegistrationRequestItems();
527 if(items != null && !items.isEmpty()){
528 Iterator<? extends RegistrationRequestItem> it = items.iterator();
529 while(it.hasNext()){
530 RegistrationRequestItem item = it.next();
531 if(StringUtils.isNotBlank(id) && item.getId().equals(id)){
532 it.remove();
533 break;
534 }
535 else if(StringUtils.isNotBlank(regGroupId) && StringUtils.isNotBlank(item.getNewRegistrationGroupId())
536 && item.getNewRegistrationGroupId().equals(regGroupId)){
537 it.remove();
538 break;
539 }
540 }
541 }
542 }
543
544 try {
545 String validationTypeKey = "FIXME";
546 String regRequestTypeKey = "FIXME";
547
548 List<ValidationResultInfo> validationResultInfos = getCourseRegistrationService().validateRegistrationRequest(validationTypeKey, regRequestTypeKey, registrationForm.getRegRequest(), context);
549 if (CollectionUtils.isEmpty(validationResultInfos)) {
550 RegistrationRequestInfo regRequestInfo = getCourseRegistrationService().updateRegistrationRequest(registrationForm.getRegRequest().getId(), registrationForm.getRegRequest(), context);
551 registrationForm.setRegRequest(getCourseRegistrationService().getRegistrationRequest(regRequestInfo.getId(),context));
552 } else {
553 StringBuilder builder = new StringBuilder("Found multiple ValidationResultInfo objects after Registration Request validation:\n");
554 for (ValidationResultInfo resultInfo : validationResultInfos) {
555 builder.append(resultInfo.getMessage()).append("\n");
556 }
557 throw new RuntimeException(builder.toString());
558 }
559 } catch (InvalidParameterException e) {
560 throw new RuntimeException(e);
561 } catch (DoesNotExistException e) {
562 throw new RuntimeException(e);
563 } catch (DataValidationErrorException e) {
564 throw new RuntimeException(e);
565 } catch (PermissionDeniedException e) {
566 throw new RuntimeException(e);
567 } catch (VersionMismatchException e) {
568 throw new RuntimeException(e);
569 } catch (OperationFailedException e) {
570 throw new RuntimeException(e);
571 } catch (MissingParameterException e) {
572 throw new RuntimeException(e);
573 } catch (ReadOnlyException e) {
574 throw new RuntimeException(e);
575 }
576
577 return getUIFModelAndView(registrationForm);
578 }
579
580
581
582
583 @RequestMapping(params = "methodToCall=addToCart")
584 public ModelAndView addToCart(@ModelAttribute("KualiForm") RegistrationForm registrationForm, BindingResult result,
585 HttpServletRequest request, HttpServletResponse response) {
586 ContextInfo context = new ContextInfo();
587
588 RegistrationGroupWrapper regGroupWrapper = findRegGroupByIndex(registrationForm);
589
590 try {
591
592 if (registrationForm.getRegRequest() == null ||
593 (registrationForm.getRegRequest() != null && StringUtils.isBlank(registrationForm.getRegRequest().getId()))) {
594 RegistrationRequestInfo regRequest = generateNewRegRequestInfo(context, registrationForm);
595 registrationForm.setRegRequest(regRequest);
596 }
597
598 RegistrationRequestItemInfo regRequestItem = generateRegRequestItem(regGroupWrapper, context);
599 registrationForm.getRegRequest().getRegistrationRequestItems().add(regRequestItem);
600
601 String validationTypeKey = "FIXME";
602 String regRequestTypeKey = "FIXME";
603 List<ValidationResultInfo> validationResultInfos = getCourseRegistrationService().validateRegistrationRequest(validationTypeKey, regRequestTypeKey, registrationForm.getRegRequest(), context);
604 if (CollectionUtils.isEmpty(validationResultInfos)) {
605 if (StringUtils.isBlank(registrationForm.getRegRequest().getId())) {
606 RegistrationRequestInfo regRequestInfo = getCourseRegistrationService().createRegistrationRequest(regRequestTypeKey, registrationForm.getRegRequest(), context);
607 regRequestInfo = getCourseRegistrationService().getRegistrationRequest(regRequestInfo.getId(),context);
608 registrationForm.setRegRequest(regRequestInfo);
609 } else {
610 getCourseRegistrationService().updateRegistrationRequest(registrationForm.getRegRequest().getId(), registrationForm.getRegRequest(), context);
611 RegistrationRequestInfo regRequestInfo = getCourseRegistrationService().getRegistrationRequest(registrationForm.getRegRequest().getId(),context);
612 registrationForm.setRegRequest(regRequestInfo);
613 }
614
615 registrationForm.getRegistrationGroupWrappersById().put(regGroupWrapper.getRegistrationGroup().getId(), regGroupWrapper);
616 } else {
617 StringBuilder builder = new StringBuilder("Found multiple ValidationResultInfo objects after Registration Request validation:\n");
618 for (ValidationResultInfo resultInfo : validationResultInfos) {
619 builder.append(resultInfo.getMessage()).append("\n");
620 }
621 throw new RuntimeException(builder.toString());
622 }
623 } catch (InvalidParameterException e) {
624 throw new RuntimeException(e);
625 } catch (DoesNotExistException e) {
626 throw new RuntimeException(e);
627 } catch (DataValidationErrorException e) {
628 throw new RuntimeException(e);
629 } catch (PermissionDeniedException e) {
630 throw new RuntimeException(e);
631 } catch (VersionMismatchException e) {
632 throw new RuntimeException(e);
633 } catch (OperationFailedException e) {
634 throw new RuntimeException(e);
635 } catch (MissingParameterException e) {
636 throw new RuntimeException(e);
637 } catch (ReadOnlyException e) {
638 throw new RuntimeException(e);
639 }
640
641 return getUIFModelAndView(registrationForm);
642 }
643
644 protected void processValidationResults(List<ValidationResultInfo> validationResultInfos, String operation) {
645 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_CUSTOM, "Found errors while trying to " + operation);
646 for (ValidationResultInfo resultInfo : validationResultInfos) {
647 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_CUSTOM, resultInfo.getMessage());
648 }
649 }
650
651 protected CourseOfferingService getCourseOfferingService() {
652 if (courseOfferingService == null) {
653 courseOfferingService = (CourseOfferingService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/courseOffering", "CourseOfferingService"));
654 }
655
656 return courseOfferingService;
657 }
658
659 protected CourseRegistrationService getCourseRegistrationService() {
660 if (courseRegistrationService == null) {
661 courseRegistrationService = (CourseRegistrationService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/courseRegistrationService", "CourseRegistrationService"));
662 }
663 return courseRegistrationService;
664 }
665
666 protected StatementService getStatementService() {
667 if (statementService == null) {
668 statementService = (StatementService) GlobalResourceLoader.getService(new QName("http://student.kuali.org/wsdl/statement", "StatementService"));
669 }
670 return statementService;
671 }
672
673 protected CourseService getCourseService() {
674 if (courseService == null) {
675 courseService = (CourseService) GlobalResourceLoader.getService(new QName(CourseServiceConstants.COURSE_NAMESPACE, "CourseService"));
676 }
677 return courseService;
678 }
679 }