View Javadoc
1   /*
2    * Copyright 2006-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.kuali.student.enrollment.class2.registration.admin.controller;
18  
19  import org.apache.commons.lang.StringUtils;
20  import org.kuali.rice.core.api.util.io.SerializationUtils;
21  import org.kuali.rice.krad.uif.UifParameters;
22  import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
23  import org.kuali.rice.krad.util.GlobalVariables;
24  import org.kuali.rice.krad.web.controller.MethodAccessible;
25  import org.kuali.rice.krad.web.controller.UifControllerBase;
26  import org.kuali.rice.krad.web.form.UifFormBase;
27  import org.kuali.student.common.uif.util.KSControllerHelper;
28  import org.kuali.student.enrollment.class2.registration.admin.form.AdminRegistrationForm;
29  import org.kuali.student.enrollment.class2.registration.admin.form.RegistrationCourse;
30  import org.kuali.student.enrollment.class2.registration.admin.form.RegistrationResult;
31  import org.kuali.student.enrollment.class2.registration.admin.form.RegistrationResultItem;
32  import org.kuali.student.enrollment.class2.registration.admin.service.AdminRegistrationViewHelperService;
33  import org.kuali.student.enrollment.class2.registration.admin.util.AdminRegClientCache;
34  import org.kuali.student.enrollment.class2.registration.admin.util.AdminRegConstants;
35  import org.kuali.student.enrollment.class2.registration.admin.util.AdminRegistrationUtil;
36  import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
37  import org.kuali.student.enrollment.courseregistration.dto.RegistrationRequestInfo;
38  import org.kuali.student.enrollment.courseregistration.dto.RegistrationRequestItemInfo;
39  import org.kuali.student.r2.common.util.constants.LprServiceConstants;
40  import org.kuali.student.r2.lum.util.constants.LrcServiceConstants;
41  import org.slf4j.Logger;
42  import org.slf4j.LoggerFactory;
43  import org.springframework.stereotype.Controller;
44  import org.springframework.validation.BindingResult;
45  import org.springframework.web.bind.annotation.ModelAttribute;
46  import org.springframework.web.bind.annotation.RequestMapping;
47  import org.springframework.web.bind.annotation.RequestMethod;
48  import org.springframework.web.bind.annotation.ResponseBody;
49  import org.springframework.web.servlet.ModelAndView;
50  
51  import javax.servlet.http.HttpServletRequest;
52  import javax.servlet.http.HttpServletResponse;
53  import java.util.ArrayList;
54  import java.util.Collection;
55  import java.util.Date;
56  import java.util.HashMap;
57  import java.util.HashSet;
58  import java.util.List;
59  import java.util.Map;
60  import java.util.Set;
61  
62  /**
63   * Created with IntelliJ IDEA.
64   * User: Blue Team (SA)
65   * Date: 17 July 2014
66   * <p/>
67   * Controller for Admin Registration.
68   */
69  @Controller
70  @RequestMapping(value = "/adminreg")
71  public class AdminRegistrationController extends UifControllerBase {
72  
73      private static final Logger LOG = LoggerFactory.getLogger(AdminRegistrationController.class);
74  
75      ///////////////////////////////////////////////
76      //Initialization methods
77      //////////////////////////////////////////////
78  
79      @Override
80      protected AdminRegistrationForm createInitialForm(HttpServletRequest request) {
81          return new AdminRegistrationForm();
82      }
83  
84      @Override
85      @RequestMapping(params = "methodToCall=refresh")
86      public ModelAndView refresh(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, HttpServletRequest request,
87                                  HttpServletResponse response) throws Exception {
88          if (!(form instanceof AdminRegistrationForm)){
89              throw new RuntimeException("Unexpected type: " + form);
90          }
91          AdminRegistrationForm adminForm = (AdminRegistrationForm) form;
92          if(AdminRegConstants.REG_COLL_ID.equals(form.getUpdateComponentId())) {
93              adminForm.setRegisteredCourses(getViewHelper(form).getCourseRegForStudentAndTerm(adminForm.getPerson().getId(), adminForm.getTerm().getId()));
94          } else if(AdminRegConstants.WAITLIST_COLL_ID.equals(form.getUpdateComponentId())) {
95              adminForm.setWaitlistedCourses(getViewHelper(form).getCourseWaitListForStudentAndTerm(adminForm.getPerson().getId(), adminForm.getTerm().getId()));
96          }
97          return super.refresh(form, result, request, response);
98      }
99  
100     /**
101      * This method is called when the user has added or changed a course code in the input section when adding a new
102      * pending course to update the course title. It is called via AJAX on a conditional property refresh.
103      *
104      * @param form
105      * @param result
106      * @param request
107      * @param response
108      * @return
109      * @throws Exception
110      * @see org.kuali.student.enrollment.class2.registration.admin.service.impl.AdminRegistrationViewHelperServiceImpl#retrieveCourseTitle
111      */
112     @MethodAccessible
113     @RequestMapping(params = "methodToCall=refreshCourseTitle")
114     public ModelAndView refreshCourseTitle(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, HttpServletRequest request,
115                                            HttpServletResponse response) throws Exception {
116         return super.refresh(form, result, request, response);
117     }
118 
119     /**
120      * This method is called when the user has added or changed a course code in the input section when adding a new
121      * pending course to update the course title. It is called via AJAX on a conditional property refresh.
122      *
123      * @param form
124      * @param result
125      * @param request
126      * @param response
127      * @return
128      * @throws Exception
129      * @see org.kuali.student.enrollment.class2.registration.admin.service.impl.AdminRegistrationViewHelperServiceImpl#retrieveCourseTitle
130      */
131     @MethodAccessible
132     @RequestMapping(params = "methodToCall=refreshRegistrationResults")
133     public ModelAndView refreshRegistrationResults(@ModelAttribute("KualiForm") AdminRegistrationForm form, BindingResult result, HttpServletRequest request,
134                                                    HttpServletResponse response) throws Exception {
135 
136         // Reset the form to ready state.
137         form.setRegRequestId(null);
138         if (form.getCoursesInProcess() != null) {
139             form.getCoursesInProcess().clear();
140         }
141         form.setPendingDropCourse(null);
142         if (form.getCoursesInEdit() != null) {
143             form.getCoursesInEdit().clear();
144         }
145         form.getEditingIssues().clear();
146         form.setClientState(AdminRegConstants.ClientStates.READY);
147         return super.refresh(form, result, request, response);
148     }
149 
150     ///////////////////////////////////////////////
151     //Student and Term methods
152     //////////////////////////////////////////////
153 
154     /**
155      * This method is called when the user has entered a student id and a term code to get the studentInfo for the selected term
156      *
157      * @param form
158      * @param result
159      * @param request
160      * @param response
161      * @return
162      */
163     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=getStudentAndTermInfo")
164     public ModelAndView getStudentAndTermInfo(@ModelAttribute("KualiForm") AdminRegistrationForm form, BindingResult result,
165                                        HttpServletRequest request, HttpServletResponse response) {
166         long start = System.currentTimeMillis();
167 
168         form.clearCourseRegistrationValues();
169 
170         form.setPerson(this.getViewHelper(form).getStudentById(form.getPersonId()));
171         form.setTerm(this.getViewHelper(form).getTermByCode(form.getTermCode()));
172         form.setContextBar(getViewHelper(form).getContextBarInfo(form.getTerm()));
173         if (GlobalVariables.getMessageMap().hasErrors()) {
174             form.setClientState(AdminRegConstants.ClientStates.OPEN);
175             form.setDisplayRegistrationTab(false);
176             return getUIFModelAndView(form);
177         }
178 
179         form.setRegisteredCourses(getViewHelper(form).getCourseRegForStudentAndTerm(form.getPerson().getId(), form.getTerm().getId()));
180         form.setWaitlistedCourses(getViewHelper(form).getCourseWaitListForStudentAndTerm(form.getPerson().getId(), form.getTerm().getId()));
181 
182         form.setDisplayRegistrationTab(true);
183         form.getTermIssues().addAll(getViewHelper(form).checkStudentEligibilityForTermLocal(form.getPerson().getId().toUpperCase(), form.getTerm()));
184 
185         printTime(form.getMethodToCall(), start);
186 
187         form.setClientState(AdminRegConstants.ClientStates.READY);
188         return getUIFModelAndView(form);
189     }
190 
191     @MethodAccessible
192     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=cancelFailedEligibilityTerm")
193     public ModelAndView cancelFailedEligibilityTerm(@ModelAttribute("KualiForm") AdminRegistrationForm form, BindingResult result,
194                                                     HttpServletRequest request, HttpServletResponse response) {
195 
196         form.clearCourseRegistrationValues();
197         form.setDisplayRegistrationTab(false);
198         form.setClientState(AdminRegConstants.ClientStates.READY);
199         return getUIFModelAndView(form);
200     }
201 
202     @MethodAccessible
203     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=continueFailedEligibilityTerm")
204     public ModelAndView continueFailedEligibilityTerm(@ModelAttribute("KualiForm") AdminRegistrationForm form, BindingResult result,
205                                                       HttpServletRequest request, HttpServletResponse response) {
206 
207         form.clearCourseRegistrationValues();
208         form.setDisplayRegistrationTab(true);
209         form.setClientState(AdminRegConstants.ClientStates.READY);
210         return getUIFModelAndView(form);
211     }
212 
213     ///////////////////////////////////////////////
214     //Registration methods
215     //////////////////////////////////////////////
216 
217     //Method used for removing a course from registration
218     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=removeRegisterCourse")
219     public ModelAndView removeRegisterCourse(@ModelAttribute("KualiForm") AdminRegistrationForm form, BindingResult result,
220                                              HttpServletRequest request, HttpServletResponse response) {
221         return deleteLine(form, result, request, response);
222     }
223 
224     @MethodAccessible
225     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=register")
226     public ModelAndView register(@ModelAttribute("KualiForm") AdminRegistrationForm form, BindingResult result,
227                                  HttpServletRequest request, HttpServletResponse response) {
228         long start = System.currentTimeMillis();
229 
230         // Validate for existing courses.
231         getViewHelper(form).validateForRegistration(form);
232         if (GlobalVariables.getMessageMap().hasErrors()) {
233             form.setClientState(AdminRegConstants.ClientStates.READY);
234 
235             printTime(form.getMethodToCall(), start);
236 
237             return getUIFModelAndView(form);
238         }
239 
240         // Move courses to "In Process" list
241         form.getCoursesInProcess().clear();
242         form.getCoursesInProcess().addAll(form.getPendingCourses());
243 
244         // Set the necessary attributes on the pending courses.
245         for (RegistrationCourse course : form.getCoursesInProcess()) {
246             course.setActivities(getViewHelper(form).getRegistrationActivitiesForRegistrationCourse(course, form.getTerm().getCode()));
247         }
248         form.setConfirmationIssues(new ArrayList<String>());
249 
250         printTime(form.getMethodToCall(), start);
251 
252         return showDialog(AdminRegConstants.REG_CONFIRM_DIALOG, form, request, response);
253     }
254 
255     @MethodAccessible
256     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=submit")
257     public ModelAndView submit(@ModelAttribute("KualiForm") AdminRegistrationForm form, BindingResult result,
258                                HttpServletRequest request, HttpServletResponse response) {
259 
260         // Validate the input values.
261         form.getConfirmationIssues().clear();
262         getViewHelper(form).validateForSubmission(form);
263         if (!form.getConfirmationIssues().isEmpty()) {
264             return showDialog(AdminRegConstants.REG_CONFIRM_DIALOG, form, request, response);
265         }
266 
267         // Continue with registration submission
268         form.resetPendingCourseValues();
269         form.setRegRequestId(getViewHelper(form).submitCourses(form.getPerson().getId(), form.getTerm().getId(),
270                 form.getCoursesInProcess(), LprServiceConstants.REQ_ITEM_ADD_TYPE_KEY));
271 
272         // Set the client state to "Registering" so that we can prevent certain actions on UI.
273         form.setClientState(AdminRegConstants.ClientStates.REGISTERING);
274         return getUIFModelAndView(form);
275     }
276 
277     @MethodAccessible
278     @RequestMapping(method = RequestMethod.GET, params = "methodToCall=queryForRegistrationStatus")
279     @ResponseBody
280     public Map queryForRegistrationStatus(@ModelAttribute("KualiForm") AdminRegistrationForm form) {
281 
282         Map<String, Object> result = new HashMap<String, Object>();
283         Set<String> updateIds = new HashSet<String>();
284         List<String> growlMessages = new ArrayList<String>();
285 
286         // Only do polling while registration is in progress.
287         if ((!AdminRegConstants.ClientStates.REGISTERING.equals(form.getClientState()) || (form.getRegRequestId() == null))) {
288             result.put(AdminRegConstants.POLLING_STOP, true);
289             return result;
290         }
291 
292         // Retrieve registration request and check the state.
293         RegistrationRequestInfo regRequest = this.getViewHelper(form).getRegistrationRequest(form.getRegRequestId());
294         if ((regRequest.getStateKey().equals(LprServiceConstants.LPRTRANS_PROCESSING_STATE_KEY)) ||
295                 (regRequest.getStateKey().equals(LprServiceConstants.LPRTRANS_NEW_STATE_KEY))) {
296             return result;
297         }
298 
299         synchronized (form) {
300 
301             for (RegistrationRequestItemInfo item : regRequest.getRegistrationRequestItems()) {
302 
303                 // Move item to appropriate list based on the item state.
304                 RegistrationResult regResult = null;
305                 if (LprServiceConstants.REQ_ITEM_ADD_TYPE_KEY.equals(item.getTypeKey())) {
306                     regResult = handleAddRequestItem(form, item);
307                 } else if (LprServiceConstants.REQ_ITEM_UPDATE_TYPE_KEY.equals(item.getTypeKey())) {
308                     regResult = handleEditRequestItem(form, item);
309                 } else if (LprServiceConstants.REQ_ITEM_DROP_TYPE_KEY.equals(item.getTypeKey())) {
310                     regResult = handleDropRequestItem(form, item);
311                 }
312 
313                 if (regResult != null) {
314                     if (regResult.getCollectionId() != null) {
315                         updateIds.add(regResult.getCollectionId());
316                     }
317                     if (AdminRegConstants.ResultLevels.RESULT_LEVEL_SUCCESS.equals(regResult.getLevel())) {
318                         for (RegistrationResultItem resultItem : regResult.getItems()) {
319                             growlMessages.add(resultItem.getDescription());
320                         }
321 
322                     } else {
323                         form.getRegistrationResults().add(regResult);
324                     }
325                 }
326             }
327         }
328 
329         // Set the ajax return values.
330         result.put(AdminRegConstants.POLLING_GROWL_MESSAGES, growlMessages);
331         result.put(AdminRegConstants.POLLING_REFRESH, true);
332         result.put(AdminRegConstants.POLLING_CLIENT_STATE, AdminRegConstants.ClientStates.READY);
333         result.put(AdminRegConstants.POLLING_REGISTERED_CREDITS, form.getRegisteredCredits());
334         result.put(AdminRegConstants.POLLING_WAITLISTED_CREDITS, form.getWaitlistedCredits());
335 
336         // Return updateIds to UI, to refresh selected collections and stop the polling.
337         result.put(AdminRegConstants.POLLING_STOP, true);
338         result.put(AdminRegConstants.POLLING_UPDATE_IDS, updateIds);
339         return result;
340     }
341 
342     /**
343      * Handles a item that added a new course registration.
344      *
345      * @param form
346      * @param item
347      * @return
348      */
349     private RegistrationResult handleAddRequestItem(AdminRegistrationForm form, RegistrationRequestItemInfo item) {
350 
351         RegistrationResult result = null;
352         RegistrationCourse addCourse = AdminRegistrationUtil.retrieveFromCourseList(form.getCoursesInProcess(), item);
353         if (LprServiceConstants.LPRTRANS_ITEM_SUCCEEDED_STATE_KEY.equals(item.getStateKey())) {
354             if(item.getCourseRegistrationId()!=null) {
355                 result = this.getViewHelper(form).buildRegistrationResult(addCourse, form.getTerm(),
356                         AdminRegConstants.ADMIN_REG_MSG_INFO_SUCCESSFULLY_REGISTERED, item.getValidationResults());
357                 result.setCollectionId(AdminRegConstants.REG_COLL_ID);
358             } else {
359                 result = this.getViewHelper(form).buildRegistrationResult(addCourse, form.getTerm(),
360                         AdminRegConstants.ADMIN_REG_MSG_INFO_SUCCESSFULLY_WAITLISTED, item.getValidationResults());
361                 result.setCollectionId(AdminRegConstants.WAITLIST_COLL_ID);
362             }
363         } else if (LprServiceConstants.LPRTRANS_ITEM_FAILED_STATE_KEY.equals(item.getStateKey())) {
364             result = this.getViewHelper(form).buildRegistrationResult(addCourse, form.getTerm(), null, item.getValidationResults());
365 //            result.setOriginRequestTypeKey(item.getTypeKey());
366             result.setCollectionId(AdminRegConstants.REG_COLL_ID);
367         }
368 
369         return result;
370     }
371 
372     /**
373      * Handles an edited registration request item.
374      * <p/>
375      * If the request originated from an override, we need to remove the previous warning result from the registration
376      * result section and adds it to the registered courses, as well as remove the old pre-updated course from the
377      * registered courses section.
378      *
379      * @param form
380      * @param item
381      * @return
382      */
383     private RegistrationResult handleEditRequestItem(AdminRegistrationForm form, RegistrationRequestItemInfo item) {
384 
385         // Retrieve the course that was updated.
386         RegistrationResult result = null;
387         RegistrationCourse updatedCourse = AdminRegistrationUtil.retrieveFromCourseList(form.getCoursesInEdit(), item);
388         // Update the registered courses list with updated detail.
389         if (LprServiceConstants.LPRTRANS_ITEM_SUCCEEDED_STATE_KEY.equals(item.getStateKey())) {
390             result = this.getViewHelper(form).buildRegistrationResult(updatedCourse, form.getTerm(),
391                     AdminRegConstants.ADMIN_REG_MSG_INFO_SUCCESSFULLY_UPDATED, item.getValidationResults());
392             result.setCollectionId(AdminRegConstants.REG_COLL_ID);
393         } else if (LprServiceConstants.LPRTRANS_ITEM_FAILED_STATE_KEY.equals(item.getStateKey())) {
394             result = this.getViewHelper(form).buildRegistrationResult(updatedCourse, form.getTerm(), null, item.getValidationResults());
395             result.setOriginRequestTypeKey(item.getTypeKey());
396         }
397 
398         return result;
399     }
400 
401     /**
402      * Handles a drop registration request item.
403      *
404      * @param form
405      * @param item
406      * @return
407      */
408     private RegistrationResult handleDropRequestItem(AdminRegistrationForm form, RegistrationRequestItemInfo item) {
409 
410         // Retrieve the course that was updated.
411         RegistrationResult result = null;
412         RegistrationCourse dropCourse = form.getPendingDropCourse();
413         if (LprServiceConstants.LPRTRANS_ITEM_SUCCEEDED_STATE_KEY.equals(item.getStateKey())) {
414             result = this.getViewHelper(form).buildRegistrationResult(dropCourse, form.getTerm(),
415                     AdminRegConstants.ADMIN_REG_MSG_INFO_SUCCESSFULLY_DROPPED, item.getValidationResults());
416             result.setCollectionId(AdminRegConstants.REG_COLL_ID);
417         } else if (LprServiceConstants.LPRTRANS_ITEM_FAILED_STATE_KEY.equals(item.getStateKey())) {
418             result = this.getViewHelper(form).buildRegistrationResult(dropCourse, form.getTerm(), null, item.getValidationResults());
419             result.setOriginRequestTypeKey(item.getTypeKey());
420         }
421 
422         return result;
423     }
424 
425     ///////////////////////////////////////////////
426     //Manage Course methods
427     //////////////////////////////////////////////
428 
429     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=dropCourse")
430     public ModelAndView dropCourse(@ModelAttribute("KualiForm") AdminRegistrationForm form, BindingResult result,
431                                    HttpServletRequest request, HttpServletResponse response) {
432 
433         // Set the pending drop course with the selected course.
434         RegistrationCourse regCourse = getSelectedRegistrationCourse(form);
435 
436         String selectedCollectionId = form.getActionParamaterValue(UifParameters.SELECTED_COLLECTION_ID);
437         if (selectedCollectionId.equals(AdminRegConstants.REG_COLL_ID)) {
438             regCourse.setRegisteredDropDate(new Date());
439         } else if (selectedCollectionId.equals(AdminRegConstants.WAITLIST_COLL_ID)) {
440             regCourse.setWaitlistedDropDate(new Date());
441         }
442 
443         form.setPendingDropCourse(regCourse);
444         return showDialog(AdminRegConstants.DROP_COURSE_DIALOG, form, request, response);
445     }
446 
447     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=dropRegisteredCourse")
448     public ModelAndView confirmDropCourse(@ModelAttribute("KualiForm") AdminRegistrationForm form, BindingResult result,
449                                           HttpServletRequest request, HttpServletResponse response) throws Exception {
450         // Validate the input values.
451         form.getDropIssues().clear();
452         getViewHelper(form).validateForDrop(form);
453         if (!form.getDropIssues().isEmpty()) {
454             return showDialog(AdminRegConstants.DROP_COURSE_DIALOG, form, request, response);
455         }
456 
457         // Submit the drop request.
458         form.setRegRequestId(getViewHelper(form).submitCourse(form.getPerson().getId(), form.getTerm().getId(),
459                 form.getPendingDropCourse(), LprServiceConstants.REQ_ITEM_DROP_TYPE_KEY));
460 
461         // perform actual drop on item in the backend
462         form.setClientState(AdminRegConstants.ClientStates.REGISTERING);
463         return refresh(form, result, request, response);
464     }
465 
466     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=removeWaitlistCourse")
467     public ModelAndView removeWaitlistCourse(@ModelAttribute("KualiForm") AdminRegistrationForm form, BindingResult result,
468                                              HttpServletRequest request, HttpServletResponse response) {
469         return deleteLine(form, result, request, response);
470     }
471 
472     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=editCourse")
473     public ModelAndView editCourse(@ModelAttribute("KualiForm") AdminRegistrationForm form, BindingResult result,
474                                    HttpServletRequest request, HttpServletResponse response) throws Exception {
475 
476         form.getEditingIssues().clear();
477         RegistrationCourse regCourse = getSelectedRegistrationCourse(form);
478 
479         CourseOfferingInfo courseOffering = AdminRegClientCache.getCourseOfferingByCodeAndTerm(form.getTerm().getId(), regCourse.getCode());
480         if (regCourse.getCreditOptions() == null) {
481             regCourse.setCreditOptions(getViewHelper(form).getCourseOfferingCreditOptionValues(courseOffering.getCreditOptionId()));
482             if (regCourse.getCreditOptions().size() == 1) {
483                 regCourse.setCreditType(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_FIXED);
484             } else {
485                 regCourse.setCreditType(LrcServiceConstants.RESULT_VALUES_GROUP_TYPE_KEY_MULTIPLE);
486             }
487         }
488 
489         if (regCourse.getGradingOptions() == null) {
490             regCourse.setGradingOptions(getViewHelper(form).getGradingOptionsForCourseOffering(courseOffering));
491         }
492 
493         // May want to write your own copy/clone method or alternatively re-retrieve value from db on cancel
494         RegistrationCourse editingCourse = (RegistrationCourse) (SerializationUtils.clone(regCourse));
495         editingCourse.setOriginCourse(regCourse);
496         form.getCoursesInEdit().clear();
497         form.getCoursesInEdit().add(editingCourse);
498 
499         form.setClientState(AdminRegConstants.ClientStates.READY);
500         return showDialog(AdminRegConstants.COURSE_EDIT_DIALOG, form, request, response);
501     }
502 
503     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=saveEdit")
504     public ModelAndView saveEdit(@ModelAttribute("KualiForm") AdminRegistrationForm form, BindingResult result,
505                                  HttpServletRequest request, HttpServletResponse response) throws Exception {
506 
507         // Validate the input values.
508         form.getEditingIssues().clear();
509         getViewHelper(form).validateCourseEdit(form);
510         if (!form.getEditingIssues().isEmpty()) {
511             return showDialog(AdminRegConstants.COURSE_EDIT_DIALOG, form, request, response);
512         }
513 
514         // Continue with saving
515         // perform actual save on item in the backend
516         form.setRegRequestId(getViewHelper(form).submitCourses(form.getPerson().getId(), form.getTerm().getId(),
517                 form.getCoursesInEdit(), LprServiceConstants.REQ_ITEM_UPDATE_TYPE_KEY));
518 
519         form.setClientState(AdminRegConstants.ClientStates.REGISTERING);
520         //reset the dialog
521         form.getDialogManager().resetDialogStatus(AdminRegConstants.COURSE_EDIT_DIALOG);
522         return refresh(form, result, request, response);
523     }
524 
525     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=cancelEdit")
526     public ModelAndView cancelEdit(@ModelAttribute("KualiForm") AdminRegistrationForm form, BindingResult result,
527                                    HttpServletRequest request, HttpServletResponse response) throws Exception {
528 
529         form.getCoursesInEdit().clear();
530         form.getEditingIssues().clear();
531         form.setClientState(AdminRegConstants.ClientStates.READY);
532         //reset the dialog
533         form.getDialogManager().resetDialogStatus(AdminRegConstants.COURSE_EDIT_DIALOG);
534         return refresh(form, result, request, response);
535     }
536 
537     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=allowCourse")
538     public ModelAndView allowCourse(@ModelAttribute("KualiForm") AdminRegistrationForm form, BindingResult result,
539                                     HttpServletRequest request, HttpServletResponse response) {
540 
541         RegistrationResult regResult = (RegistrationResult) getSelectedCollectionObject(form);
542 
543         // Resubmit registration
544         form.setRegRequestId(getViewHelper(form).resubmitCourse(form.getPerson().getId(), form.getTerm().getId(),
545                 regResult.getCourse(), regResult.getOriginRequestTypeKey()));
546 
547         // Set the client state to "Registering" so that we can prevent certain actions on UI.
548         form.setClientState(AdminRegConstants.ClientStates.REGISTERING);
549         return getUIFModelAndView(form);
550     }
551 
552     //Method used for the deny button of the registration request
553     @RequestMapping(method = RequestMethod.POST, params = "methodToCall=denyCourse")
554     public ModelAndView denyCourse(@ModelAttribute("KualiForm") AdminRegistrationForm form, BindingResult result,
555                                    HttpServletRequest request, HttpServletResponse response) {
556         // would deny registration request here
557         return deleteLine(form, result, request, response);
558     }
559 
560     /**
561      * @param form
562      * @return
563      */
564     protected AdminRegistrationViewHelperService getViewHelper(UifFormBase form) {
565         return (AdminRegistrationViewHelperService) KSControllerHelper.getViewHelperService(form);
566     }
567 
568     private RegistrationCourse getSelectedRegistrationCourse(AdminRegistrationForm form) {
569         return (RegistrationCourse) this.getSelectedCollectionObject(form);
570     }
571 
572     private Object getSelectedCollectionObject(AdminRegistrationForm form) {
573 
574         String selectedCollectionPath = form.getActionParamaterValue(UifParameters.SELECTED_COLLECTION_PATH);
575         if (StringUtils.isBlank(selectedCollectionPath)) {
576             throw new RuntimeException("Selected collection path was not set for collection action");
577         }
578 
579         String selectedLine = form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX);
580         int selectedLineIndex = -1;
581         if (StringUtils.isNotBlank(selectedLine)) {
582             selectedLineIndex = Integer.parseInt(selectedLine);
583         }
584 
585         // Retrieving the select registration result.
586         Collection<Object> collection = ObjectPropertyUtils.getPropertyValue(form, selectedCollectionPath);
587         Object item = ((List) collection).get(selectedLineIndex);
588 
589         return item;
590 
591     }
592 
593     private void printTime(String methodName, long startTime){
594         LOG.info("***   " + methodName + ": " + (System.currentTimeMillis() - startTime));
595     }
596 
597 }