1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
45
46
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
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
91 GlobalVariables.getMessageMap().putError("targetTermCode", "error.submit.sourceTerm");
92 return getUIFModelAndView(form);
93 }
94
95 TermInfo termInfo = termInfos.get(0);
96
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
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 }