Coverage Report - org.kuali.student.enrollment.class2.courseoffering.controller.CourseOfferingRolloverController
 
Classes in this File Line Coverage Branch Coverage Complexity
CourseOfferingRolloverController
0%
0/82
0%
0/32
3.222
 
 1  
 /**
 2  
  * Copyright 2012 The Kuali Foundation Licensed under the
 3  
  * Educational Community License, Version 2.0 (the "License"); you may
 4  
  * not use this file except in compliance with the License. You may
 5  
  * obtain a copy of the License at
 6  
  *
 7  
  * http://www.osedu.org/licenses/ECL-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing,
 10  
  * software distributed under the License is distributed on an "AS IS"
 11  
  * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 12  
  * or implied. See the License for the specific language governing
 13  
  * permissions and limitations under the License.
 14  
  *
 15  
  * Created by Charles on 5/7/12
 16  
  */
 17  
 package org.kuali.student.enrollment.class2.courseoffering.controller;
 18  
 
 19  
 import org.kuali.rice.krad.web.controller.UifControllerBase;
 20  
 import org.kuali.rice.krad.web.form.UifFormBase;
 21  
 import org.kuali.student.enrollment.acal.dto.TermInfo;
 22  
 import org.kuali.student.enrollment.class2.courseoffering.form.CourseOfferingRolloverManagementForm;
 23  
 import org.kuali.student.enrollment.class2.courseoffering.service.CourseOfferingViewHelperService;
 24  
 import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
 25  
 import org.kuali.student.enrollment.courseofferingset.dto.SocInfo;
 26  
 import org.kuali.student.enrollment.courseofferingset.dto.SocRolloverResultInfo;
 27  
 import org.springframework.stereotype.Controller;
 28  
 import org.springframework.validation.BindingResult;
 29  
 import org.springframework.web.bind.annotation.ModelAttribute;
 30  
 import org.springframework.web.bind.annotation.RequestMapping;
 31  
 import org.springframework.web.bind.annotation.RequestMethod;
 32  
 import org.springframework.web.servlet.ModelAndView;
 33  
 
 34  
 import javax.servlet.http.HttpServletRequest;
 35  
 import javax.servlet.http.HttpServletResponse;
 36  
 import java.text.SimpleDateFormat;
 37  
 import java.util.ArrayList;
 38  
 import java.util.Calendar;
 39  
 import java.util.Date;
 40  
 import java.util.List;
 41  
 
 42  
 /**
 43  
  * This class //TODO ...
 44  
  *
 45  
  * @author Kuali Student Team
 46  
  */
 47  
 @Controller
 48  
 @RequestMapping(value = "/courseOfferingRollover")
 49  0
 public class CourseOfferingRolloverController extends UifControllerBase {
 50  
     private CourseOfferingViewHelperService viewHelperService;
 51  
 
 52  
     @Override
 53  
     protected UifFormBase createInitialForm(HttpServletRequest request) {
 54  0
         return new CourseOfferingRolloverManagementForm();
 55  
     }
 56  
 
 57  
     @Override
 58  
     @RequestMapping(method = RequestMethod.GET, params = "methodToCall=start")
 59  
     public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
 60  
                               HttpServletRequest request, HttpServletResponse response) {
 61  0
         CourseOfferingRolloverManagementForm theForm = (CourseOfferingRolloverManagementForm)form;
 62  0
         Date date = Calendar.getInstance().getTime();
 63  0
         System.err.println(date.toString() + " ");
 64  0
         System.err.println(theForm);
 65  0
         return getUIFModelAndView(theForm);
 66  
         // return super.start(theForm, result, request, response);
 67  
     }
 68  
 
 69  
     @RequestMapping(params = "methodToCall=goTargetTerm")
 70  
     public ModelAndView goTargetTerm(@ModelAttribute("KualiForm") CourseOfferingRolloverManagementForm form, BindingResult result,
 71  
                              HttpServletRequest request, HttpServletResponse response) throws Exception {
 72  0
         CourseOfferingViewHelperService helper = getViewHelperService(form);
 73  0
         List<TermInfo> termList = helper.findTermByTermCode(form.getTargetTermCode());
 74  0
         if (termList != null && termList.size() == 1) {
 75  
             // Get first term
 76  0
             TermInfo matchingTerm = termList.get(0);
 77  0
             String targetTermCode = matchingTerm.getCode();
 78  0
             form.setDisplayedTargetTermCode(targetTermCode);
 79  
             // Set the start date
 80  0
             Date startDate = matchingTerm.getStartDate();
 81  0
             SimpleDateFormat format = new SimpleDateFormat("EEE, MMMMM d, yyyy");
 82  0
             String startDateStr = format.format(startDate);
 83  0
             form.setTargetTermStartDate(startDateStr);
 84  
             // Set the end date
 85  0
             Date endDate = matchingTerm.getEndDate();
 86  0
             String endDateStr = format.format(endDate);
 87  0
             form.setTargetTermEndDate(endDateStr);
 88  
             // TODO: Put in last rollover date (Kirk says this may be unnecessary in new wireframes 5/18/2012)
 89  0
             form.setTargetTerm(matchingTerm);
 90  0
         } else {
 91  0
             form.setTargetTerm(null);
 92  
         }
 93  0
         return getUIFModelAndView(form);
 94  
     }
 95  
 
 96  
     @RequestMapping(params = "methodToCall=goSourceTerm")
 97  
     public ModelAndView goSourceTerm(@ModelAttribute("KualiForm") CourseOfferingRolloverManagementForm form, BindingResult result,
 98  
                              HttpServletRequest request, HttpServletResponse response) throws Exception {
 99  0
         CourseOfferingViewHelperService helper = getViewHelperService(form);
 100  0
         List<TermInfo> termList = helper.findTermByTermCode(form.getSourceTermCode());
 101  0
         if (termList != null && termList.size() == 1) {
 102  
             // Get first term
 103  0
             TermInfo matchingTerm = termList.get(0);
 104  0
             String sourceTermCode = matchingTerm.getCode();
 105  0
             form.setDisplayedSourceTermCode(sourceTermCode);
 106  
             // Set the start date
 107  0
             Date startDate = matchingTerm.getStartDate();
 108  0
             SimpleDateFormat format = new SimpleDateFormat("EEE, MMMMM d, yyyy");
 109  0
             String startDateStr = format.format(startDate);
 110  0
             form.setSourceTermStartDate(startDateStr);
 111  
             // Set the end date
 112  0
             Date endDate = matchingTerm.getEndDate();
 113  0
             String endDateStr = format.format(endDate);
 114  0
             form.setSourceTermEndDate(endDateStr);
 115  0
             form.setSourceTerm(matchingTerm);
 116  0
         } else {
 117  0
             form.setTargetTerm(null);
 118  
         }
 119  0
         return getUIFModelAndView(form);
 120  
     }
 121  
 
 122  
     @RequestMapping(params = "methodToCall=performRollover")
 123  
     public ModelAndView performRollover(@ModelAttribute("KualiForm") CourseOfferingRolloverManagementForm form, BindingResult result,
 124  
                                         HttpServletRequest request, HttpServletResponse response) throws Exception {
 125  0
         CourseOfferingViewHelperService helper =  getViewHelperService(form);
 126  
 
 127  0
         if (form.getSourceTerm() == null || form.getTargetTerm() == null) {
 128  0
             form.setStatusField("(setUp) Source/target term objects appear to be missing");
 129  0
             return getUIFModelAndView(form);
 130  
         }
 131  0
         form.setStatusField("");
 132  0
         String sourceTermId = form.getSourceTerm().getId();
 133  0
         String targetTermId = form.getTargetTerm().getId();
 134  
 
 135  0
         helper.performRollover(sourceTermId, targetTermId, form);
 136  0
         return getUIFModelAndView(form);
 137  
     }
 138  
 
 139  
     @RequestMapping(params = "methodToCall=setUpSourceTerm")
 140  
     public ModelAndView setUpSourceTerm(@ModelAttribute("KualiForm") CourseOfferingRolloverManagementForm form, BindingResult result,
 141  
                                         HttpServletRequest request, HttpServletResponse response) throws Exception {
 142  0
         CourseOfferingViewHelperService helper =  getViewHelperService(form);
 143  
         
 144  0
         if (form.getSourceTerm() == null || form.getTargetTerm() == null) {
 145  0
             form.setStatusField("(setUp) Source/target term objects appear to be missing");
 146  0
             return getUIFModelAndView(form);
 147  
         }
 148  0
         form.setStatusField("");
 149  
         // Delete previous SOC and course offerings (allows for us to redefine SOC/course offering later on
 150  
 
 151  0
         boolean success = helper.cleanSourceTerm(form.getSourceTerm().getId(), form);
 152  0
         if (success) {
 153  0
             helper.createSocCoFoAoForTerm(form.getSourceTerm().getId(), form);
 154  
         }
 155  0
         return getUIFModelAndView(form);
 156  
     }
 157  
 
 158  
     @RequestMapping(params = "methodToCall=performReverseRollover")
 159  
     public ModelAndView performReverseRollover(@ModelAttribute("KualiForm") CourseOfferingRolloverManagementForm form, BindingResult result,
 160  
                                             HttpServletRequest request, HttpServletResponse response) throws Exception {
 161  0
         CourseOfferingViewHelperService helper =  getViewHelperService(form);
 162  0
         if (form.getSourceTerm() == null || form.getTargetTerm() == null) {
 163  0
             form.setStatusField("(cleanUp) Source/target term objects appear to be missing");
 164  0
             return getUIFModelAndView(form);
 165  
         }
 166  0
         form.setStatusField("");
 167  
 
 168  0
         String sourceTermId = form.getSourceTerm().getId();
 169  0
         String targetTermId = form.getTargetTerm().getId();
 170  0
         SocRolloverResultInfo info = helper.performReverseRollover(sourceTermId, targetTermId, form);
 171  0
         if (info != null) {
 172  0
             form.setStatusField("Num items processed: " + info.getItemsProcessed());
 173  
         }
 174  0
         return getUIFModelAndView(form);
 175  
     }
 176  
 
 177  
     @RequestMapping(params = "methodToCall=cleanTargetTerm")
 178  
     public ModelAndView cleanTargetTerm(@ModelAttribute("KualiForm") CourseOfferingRolloverManagementForm form, BindingResult result,
 179  
                                                HttpServletRequest request, HttpServletResponse response) throws Exception {
 180  0
         CourseOfferingViewHelperService helper =  getViewHelperService(form);
 181  0
         if (form.getSourceTerm() == null || form.getTargetTerm() == null) {
 182  0
             form.setStatusField("(cleanUp) Source/target term objects appear to be missing");
 183  0
             return getUIFModelAndView(form);
 184  
         }
 185  0
         form.setStatusField("");
 186  
 
 187  0
         helper.cleanTargetTerm(form.getTargetTerm().getId(), form);
 188  0
         return getUIFModelAndView(form);
 189  
     }
 190  
 
 191  
     public CourseOfferingViewHelperService getViewHelperService(CourseOfferingRolloverManagementForm rolloverForm){
 192  0
         if (viewHelperService == null) {
 193  0
             if (rolloverForm.getView().getViewHelperServiceClass() != null){
 194  0
                 viewHelperService = (CourseOfferingViewHelperService) rolloverForm.getView().getViewHelperService();
 195  
             }else{
 196  0
                 viewHelperService= (CourseOfferingViewHelperService) rolloverForm.getPostedView().getViewHelperService();
 197  
             }
 198  
         }
 199  0
         return viewHelperService;
 200  
     }
 201  
 
 202  
 //    @RequestMapping(params = "methodToCall=goRolloverTerm")
 203  
 //    public ModelAndView goRolloverTerm(@ModelAttribute("KualiForm") CourseOfferingRolloverManagementForm form, BindingResult result,
 204  
 //                                     HttpServletRequest request, HttpServletResponse response) throws Exception {
 205  
 //        form.setRolloverSourceTerm("Fall 2011");
 206  
 //        form.setDateInitiated("March 12 2012");
 207  
 //        form.setCourseOfferingsNotAllowed("In progress");
 208  
 //        form.setDateCompleted("In progress");
 209  
 //        form.setActivityOfferingsNotAllowed("In progress");
 210  
 //        return getUIFModelAndView(form);
 211  
 //    }
 212  
 }