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.commons.lang.StringUtils;
20 import org.apache.log4j.Logger;
21 import org.kuali.rice.krad.util.GlobalVariables;
22 import org.kuali.rice.krad.util.KRADConstants;
23 import org.kuali.rice.krad.web.controller.UifControllerBase;
24 import org.kuali.rice.krad.web.form.UifFormBase;
25 import org.kuali.student.enrollment.acal.dto.TermInfo;
26 import org.kuali.student.enrollment.class2.courseoffering.form.ManageSOCForm;
27 import org.kuali.student.enrollment.class2.courseoffering.service.ManageSOCViewHelperService;
28 import org.kuali.student.enrollment.class2.courseoffering.util.ManageSocConstants;
29 import org.kuali.student.enrollment.uif.util.KSControllerHelper;
30 import org.kuali.student.r2.common.util.constants.CourseOfferingSetServiceConstants;
31 import org.springframework.stereotype.Controller;
32 import org.springframework.validation.BindingResult;
33 import org.springframework.web.bind.annotation.ModelAttribute;
34 import org.springframework.web.bind.annotation.RequestMapping;
35 import org.springframework.web.servlet.ModelAndView;
36
37 import javax.servlet.http.HttpServletRequest;
38 import javax.servlet.http.HttpServletResponse;
39
40
41
42
43
44
45
46
47 @Controller
48 @RequestMapping(value = "/manageSOC")
49 public class ManageSOCController extends UifControllerBase {
50
51 private final static Logger LOG = Logger.getLogger(ManageSOCController.class);
52
53 @Override
54 protected UifFormBase createInitialForm(@SuppressWarnings("unused") HttpServletRequest request) {
55 return new ManageSOCForm();
56 }
57
58 @RequestMapping(params = "methodToCall=lockSOC")
59 public ModelAndView lockSOC(@ModelAttribute("KualiForm") ManageSOCForm socForm, @SuppressWarnings("unused") BindingResult result,
60 @SuppressWarnings("unused") HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
61
62 LOG.debug("Locking SOC");
63
64 String dialogName = ManageSocConstants.ConfirmDialogs.LOCK;
65
66 if (!hasDialogBeenAnswered(dialogName, socForm)) {
67 return showDialog(dialogName, socForm, request, response);
68 }
69
70 boolean dialogAnswer = getBooleanDialogResponse(dialogName, socForm, request, response);
71 socForm.getDialogManager().resetDialogStatus(dialogName);
72
73 if (dialogAnswer) {
74
75 if (socForm.getSocInfo() == null) {
76 throw new RuntimeException("SocInfo not exists in the form. Please enter the term code and click on GO button");
77 }
78
79 if (!StringUtils.equals(CourseOfferingSetServiceConstants.OPEN_SOC_STATE_KEY, socForm.getSocInfo().getStateKey())) {
80 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, ManageSocConstants.MessageKeys.ERROR_INVALID_STATUS_FOR_LOCK);
81 return getUIFModelAndView(socForm);
82 }
83
84 ManageSOCViewHelperService viewHelper = (ManageSOCViewHelperService) KSControllerHelper.getViewHelperService(socForm);
85 viewHelper.lockSOC(socForm);
86
87 return buildModel(socForm, result, request, response);
88
89 } else {
90 return getUIFModelAndView(socForm);
91 }
92
93 }
94
95 @RequestMapping(params = "methodToCall=sendApprovedActivitiesToScheduler")
96 public ModelAndView sendApprovedActivitiesToScheduler(@ModelAttribute("KualiForm") ManageSOCForm socForm, @SuppressWarnings("unused") BindingResult result,
97 @SuppressWarnings("unused") HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
98
99 if (!StringUtils.equals(CourseOfferingSetServiceConstants.LOCKED_SOC_STATE_KEY, socForm.getSocInfo().getStateKey())) {
100 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, ManageSocConstants.MessageKeys.ERROR_INVALID_STATUS_FOR_SCHEDULE);
101 return getUIFModelAndView(socForm);
102 }
103
104 String dialogName = ManageSocConstants.ConfirmDialogs.MASS_SCHEDULING;
105
106 if (!hasDialogBeenAnswered(dialogName, socForm)) {
107 return showDialog(dialogName, socForm, request, response);
108 }
109
110 boolean dialogAnswer = getBooleanDialogResponse(dialogName, socForm, request, response);
111 socForm.getDialogManager().resetDialogStatus(dialogName);
112
113 if (dialogAnswer) {
114
115 ManageSOCViewHelperService viewHelper = (ManageSOCViewHelperService) KSControllerHelper.getViewHelperService(socForm);
116 viewHelper.startMassScheduling(socForm);
117 return buildModel(socForm, result, request, response);
118 } else {
119 return getUIFModelAndView(socForm);
120 }
121 }
122
123
124
125
126
127
128
129
130
131
132 @RequestMapping(params = "methodToCall=buildModel")
133 public ModelAndView buildModel(@ModelAttribute("KualiForm") ManageSOCForm socForm, @SuppressWarnings("unused") BindingResult result,
134 @SuppressWarnings("unused") HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) {
135
136 ManageSOCViewHelperService viewHelper = (ManageSOCViewHelperService) KSControllerHelper.getViewHelperService(socForm);
137 socForm.clear();
138
139 TermInfo term = viewHelper.getTermByCode(socForm.getTermCode());
140 socForm.setTermInfo(term);
141
142 viewHelper.buildModel(socForm);
143
144 return getUIFModelAndView(socForm);
145 }
146
147 @RequestMapping(params = "methodToCall=allowFinalEdits")
148 public ModelAndView allowFinalEdits(@ModelAttribute("KualiForm") ManageSOCForm socForm, @SuppressWarnings("unused") BindingResult result,
149 @SuppressWarnings("unused") HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
150
151 if (socForm.getSocInfo() == null) {
152 throw new RuntimeException("SocInfo not exists in the form. Please enter the term code and click on GO button");
153 }
154
155 if (!StringUtils.equals(CourseOfferingSetServiceConstants.SOC_SCHEDULING_STATE_COMPLETED, socForm.getSocInfo().getSchedulingStateKey())) {
156 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, ManageSocConstants.MessageKeys.ERROR_INVALID_STATUS_FOR_FINALEDIT);
157 return getUIFModelAndView(socForm);
158 }
159
160 String dialogName = ManageSocConstants.ConfirmDialogs.FINAL_EDITS;
161
162 if (!hasDialogBeenAnswered(dialogName, socForm)) {
163 return showDialog(dialogName, socForm, request, response);
164 }
165
166 boolean dialogAnswer = getBooleanDialogResponse(dialogName, socForm, request, response);
167 socForm.getDialogManager().resetDialogStatus(dialogName);
168
169 if (dialogAnswer) {
170
171 ManageSOCViewHelperService viewHelper = (ManageSOCViewHelperService) KSControllerHelper.getViewHelperService(socForm);
172 viewHelper.allowSOCFinalEdit(socForm);
173
174 return buildModel(socForm, result, request, response);
175
176 } else {
177 return getUIFModelAndView(socForm);
178 }
179 }
180
181 @RequestMapping(params = "methodToCall=publishSOC")
182 public ModelAndView publishSOC(@ModelAttribute("KualiForm") ManageSOCForm socForm, @SuppressWarnings("unused") BindingResult result,
183 @SuppressWarnings("unused") HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
184
185 if (socForm.getSocInfo() == null) {
186 throw new RuntimeException("SocInfo not exists in the form. Please enter the term code and click on GO button");
187 }
188
189 if (!StringUtils.equals(CourseOfferingSetServiceConstants.FINALEDITS_SOC_STATE_KEY, socForm.getSocInfo().getStateKey())) {
190 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, ManageSocConstants.MessageKeys.ERROR_INVALID_STATUS_FOR_PUBLISH);
191 return getUIFModelAndView(socForm);
192 }
193
194 String dialogName = ManageSocConstants.ConfirmDialogs.MASS_PUBLISHLING;
195
196 if (!hasDialogBeenAnswered(dialogName, socForm)) {
197 return showDialog(dialogName, socForm, request, response);
198 }
199
200 boolean dialogAnswer = getBooleanDialogResponse(dialogName, socForm, request, response);
201 socForm.getDialogManager().resetDialogStatus(dialogName);
202
203 if (dialogAnswer) {
204 ManageSOCViewHelperService viewHelper = (ManageSOCViewHelperService) KSControllerHelper.getViewHelperService(socForm);
205 viewHelper.publishSOC(socForm);
206 return buildModel(socForm, result, request, response);
207 } else {
208 return getUIFModelAndView(socForm);
209 }
210 }
211
212 @RequestMapping(params = "methodToCall=closeSOC")
213 public ModelAndView closeSOC(@ModelAttribute("KualiForm") ManageSOCForm socForm, @SuppressWarnings("unused") BindingResult result,
214 @SuppressWarnings("unused") HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
215 if (socForm.getSocInfo() == null) {
216 throw new RuntimeException("SocInfo not exists in the form. Please enter the term code and click on GO button");
217 }
218
219 if (!StringUtils.equals(CourseOfferingSetServiceConstants.PUBLISHED_SOC_STATE_KEY, socForm.getSocInfo().getStateKey())) {
220 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, ManageSocConstants.MessageKeys.ERROR_INVALID_STATUS_FOR_CLOSE);
221 return getUIFModelAndView(socForm);
222 }
223
224 String dialogName = ManageSocConstants.ConfirmDialogs.CLOSE_SET;
225
226 if (!hasDialogBeenAnswered(dialogName, socForm)) {
227 return showDialog(dialogName, socForm, request, response);
228 }
229
230 boolean dialogAnswer = getBooleanDialogResponse(dialogName, socForm, request, response);
231 socForm.getDialogManager().resetDialogStatus(dialogName);
232
233 if (dialogAnswer) {
234 ManageSOCViewHelperService viewHelper = (ManageSOCViewHelperService) KSControllerHelper.getViewHelperService(socForm);
235 viewHelper.closeSOC(socForm);
236
237 return buildModel(socForm, result, request, response);
238 } else {
239 return getUIFModelAndView(socForm);
240 }
241 }
242 }