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.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 | |
|
44 | |
|
45 | |
|
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 | |
|
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 | |
|
76 | 0 | TermInfo matchingTerm = termList.get(0); |
77 | 0 | String targetTermCode = matchingTerm.getCode(); |
78 | 0 | form.setDisplayedTargetTermCode(targetTermCode); |
79 | |
|
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 | |
|
85 | 0 | Date endDate = matchingTerm.getEndDate(); |
86 | 0 | String endDateStr = format.format(endDate); |
87 | 0 | form.setTargetTermEndDate(endDateStr); |
88 | |
|
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 | |
|
103 | 0 | TermInfo matchingTerm = termList.get(0); |
104 | 0 | String sourceTermCode = matchingTerm.getCode(); |
105 | 0 | form.setDisplayedSourceTermCode(sourceTermCode); |
106 | |
|
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 | |
|
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 | |
|
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 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
|
212 | |
} |