View Javadoc

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 6/18/12
16   */
17  package org.kuali.student.enrollment.class2.courseoffering.controller;
18  
19  import org.apache.log4j.Logger;
20  import org.kuali.rice.krad.util.GlobalVariables;
21  import org.kuali.rice.krad.web.controller.UifControllerBase;
22  import org.kuali.rice.krad.web.form.UifFormBase;
23  import org.kuali.student.enrollment.acal.dto.TermInfo;
24  import org.kuali.student.enrollment.class2.courseoffering.form.CourseOfferingManagementForm;
25  import org.kuali.student.enrollment.class2.courseoffering.form.CourseOfferingRolloverManagementForm;
26  import org.kuali.student.enrollment.class2.courseoffering.form.DeleteTargetTermForm;
27  import org.kuali.student.enrollment.class2.courseoffering.service.CourseOfferingViewHelperService;
28  import org.kuali.student.enrollment.courseofferingset.dto.SocInfo;
29  import org.kuali.student.r2.common.util.constants.CourseOfferingSetServiceConstants;
30  import org.springframework.stereotype.Controller;
31  import org.springframework.validation.BindingResult;
32  import org.springframework.web.bind.annotation.ModelAttribute;
33  import org.springframework.web.bind.annotation.RequestMapping;
34  import org.springframework.web.bind.annotation.RequestMethod;
35  import org.springframework.web.servlet.ModelAndView;
36  
37  import javax.servlet.http.HttpServletRequest;
38  import javax.servlet.http.HttpServletResponse;
39  import java.util.Calendar;
40  import java.util.Date;
41  import java.util.List;
42  
43  /**
44   * This class //TODO ...
45   *
46   * @author Kuali Student Team
47   */
48  @Controller
49  @RequestMapping(value = "/deleteTargetTerm")
50  public class DeleteTargetTermController extends UifControllerBase {
51      final static Logger LOGGER = Logger.getLogger(DeleteTargetTermForm.class);
52      private CourseOfferingViewHelperService viewHelperService;
53  
54      @Override
55      protected UifFormBase createInitialForm(HttpServletRequest httpServletRequest) {
56          return new DeleteTargetTermForm();
57      }
58  
59      public CourseOfferingViewHelperService getViewHelperService(UifFormBase form) {
60          if (viewHelperService == null) {
61              if (form.getView().getViewHelperServiceClass() != null) {
62                  viewHelperService = (CourseOfferingViewHelperService) form.getView().getViewHelperService();
63              } else {
64                  viewHelperService = (CourseOfferingViewHelperService) form.getPostedView().getViewHelperService();
65              }
66          }
67          return viewHelperService;
68      }
69  
70      @Override
71      @RequestMapping(method = RequestMethod.GET, params = "methodToCall=start")
72      public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
73                                HttpServletRequest request, HttpServletResponse response) {
74          DeleteTargetTermForm theForm = (DeleteTargetTermForm) form;
75          Date date = Calendar.getInstance().getTime();
76          System.err.println(date.toString() + " ");
77          System.err.println(theForm);
78          return getUIFModelAndView(theForm);
79          // return super.start(theForm, result, request, response);
80      }
81  
82      @RequestMapping(params = "methodToCall=goTargetTerm")
83      public ModelAndView goTargetTerm(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
84                                       HttpServletRequest request, HttpServletResponse response) throws Exception {
85          LOGGER.info("In goTargetTerm");
86          CourseOfferingViewHelperService helperService = getViewHelperService(form);
87          DeleteTargetTermForm dttForm = (DeleteTargetTermForm) form;
88          List<TermInfo> termInfos = helperService.findTermByTermCode(dttForm.getTargetTermCode());
89          if (termInfos == null || termInfos.isEmpty()) {
90              // Must have a valid term
91              GlobalVariables.getMessageMap().putError("targetTermCode", "error.submit.sourceTerm"); // TODO: Change error
92              return getUIFModelAndView(form);
93          }
94  
95          TermInfo termInfo = termInfos.get(0);
96          // Fill in form data for target term
97          dttForm.setDisplayedTargetTermId(termInfo.getId());
98          String startDateStr = helperService.formatDate(termInfo.getStartDate());
99          String endDateStr = helperService.formatDate(termInfo.getEndDate());
100         dttForm.setTargetTermStartDate(startDateStr);
101         dttForm.setTargetTermEndDate(endDateStr);
102         return getUIFModelAndView(form);
103     }
104 
105     @RequestMapping(params = "methodToCall=deleteTargetTerm")
106     public ModelAndView deleteTargetTerm(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
107                                          HttpServletRequest request, HttpServletResponse response) throws Exception {
108         DeleteTargetTermForm dttForm = (DeleteTargetTermForm) form;
109         if (dttForm.getTargetTermCode() == null || dttForm.getTargetTermCode().length() == 0) {
110             GlobalVariables.getMessageMap().putError("targetTermCode", "error.submit.sourceTerm");
111             return getUIFModelAndView(form);
112         }
113         // Check for target SOC
114         CourseOfferingViewHelperService helperService = getViewHelperService(form);
115         SocInfo mainSoc = helperService.getMainSoc(dttForm.getDisplayedTargetTermId());
116         if (mainSoc == null) {
117             GlobalVariables.getMessageMap().putError("targetTermCode", "error.delete.targetTerm.noSoc");
118             return getUIFModelAndView(form);
119         }
120         if (!mainSoc.getStateKey().equals(CourseOfferingSetServiceConstants.DRAFT_SOC_STATE_KEY)) {
121             GlobalVariables.getMessageMap().putError("targetTermCode", "error.delete.targetTerm.notDraftSoc");
122             return getUIFModelAndView(form);
123         }
124         helperService.deleteTargetTerm(dttForm.getDisplayedTargetTermId(), dttForm);
125         return getUIFModelAndView(form);
126     }
127 }