1 package org.kuali.student.enrollment.class1.krms.controller;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.kuali.rice.krad.uif.UifParameters;
5 import org.kuali.rice.krad.util.GlobalVariables;
6 import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
7 import org.kuali.rice.krad.web.form.UifFormBase;
8 import org.kuali.rice.krms.dto.AgendaEditor;
9 import org.kuali.rice.krms.dto.PropositionEditor;
10 import org.kuali.rice.krms.dto.RuleEditor;
11 import org.kuali.rice.krms.dto.RuleManager;
12 import org.kuali.rice.krms.util.AgendaUtilities;
13 import org.kuali.rice.krms.util.KRMSConstants;
14 import org.kuali.student.enrollment.class1.krms.dto.AORuleEditor;
15 import org.kuali.student.enrollment.class1.krms.dto.AORuleManagementWrapper;
16 import org.kuali.student.enrollment.class1.krms.service.impl.AORuleViewHelperServiceImpl;
17 import org.kuali.student.enrollment.class1.krms.util.EnrolKRMSConstants;
18 import org.kuali.student.enrollment.class1.krms.service.impl.AORuleEditorMaintainableImpl;
19 import org.springframework.stereotype.Controller;
20 import org.springframework.validation.BindingResult;
21 import org.springframework.web.bind.annotation.ModelAttribute;
22 import org.springframework.web.bind.annotation.RequestMapping;
23 import org.springframework.web.servlet.ModelAndView;
24
25 import javax.servlet.http.HttpServletRequest;
26 import javax.servlet.http.HttpServletResponse;
27 import java.util.Map;
28
29
30
31
32
33
34 @Controller
35 @RequestMapping(value = "/activityOfferingRules")
36 public class AORuleEditorController extends EnrolRuleEditorController {
37
38
39
40
41
42
43
44
45 @Override
46 @RequestMapping(params = "methodToCall=addRule")
47 public ModelAndView addRule(@ModelAttribute("KualiForm") UifFormBase form, @SuppressWarnings("unused") BindingResult result,
48 @SuppressWarnings("unused") HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) {
49
50 form.getActionParameters().put(UifParameters.NAVIGATE_TO_PAGE_ID, EnrolKRMSConstants.KSKRMS_RULE_AO_MAINTENANCE_PAGE_ID);
51
52 form.getClientStateForSyncing().clear();
53
54 AORuleEditor ruleEditor = (AORuleEditor) AgendaUtilities.retrieveSelectedRuleEditor(this.getMaintenanceDocumentForm( form));
55
56 this.getViewHelper(form).refreshInitTrees(ruleEditor);
57 return super.navigate(form, result, request, response);
58 }
59
60
61
62
63
64
65
66
67
68
69
70 @RequestMapping(params = "methodToCall=goToRuleView")
71 public ModelAndView goToRuleView(@ModelAttribute("KualiForm") UifFormBase form, @SuppressWarnings("unused") BindingResult result,
72 @SuppressWarnings("unused") HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) {
73
74 form.getActionParameters().put(UifParameters.NAVIGATE_TO_PAGE_ID, EnrolKRMSConstants.KSKRMS_RULE_AO_MAINTENANCE_PAGE_ID);
75 return super.goToRuleView(form, result, request, response);
76 }
77
78
79
80
81
82
83
84
85
86
87 @RequestMapping(params = "methodToCall=cancelEditRule")
88 public ModelAndView cancelEditRule(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
89 HttpServletRequest request, HttpServletResponse response) {
90
91 form.getActionParameters().put(UifParameters.NAVIGATE_TO_PAGE_ID, EnrolKRMSConstants.KSKRMS_AGENDA_AO_MAINTENANCE_PAGE_ID);
92 return super.cancelEditRule(form, result, request, response);
93 }
94
95
96
97
98
99
100
101
102
103
104 @RequestMapping(params = "methodToCall=updateRule")
105 public ModelAndView updateRule(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
106 HttpServletRequest request, HttpServletResponse response) {
107
108 form.getActionParameters().put(UifParameters.NAVIGATE_TO_PAGE_ID, EnrolKRMSConstants.KSKRMS_AGENDA_AO_MAINTENANCE_PAGE_ID);
109
110
111 MaintenanceDocumentForm ruleMaintenanceForm = this.getMaintenanceDocumentForm( form);
112 AORuleManagementWrapper aoRuleMgtWrapper = (AORuleManagementWrapper) AgendaUtilities.getRuleWrapper(ruleMaintenanceForm);
113 aoRuleMgtWrapper.setAgendaDirty(true);
114
115 return super.updateRule(form, result, request, response);
116 }
117
118
119
120
121
122
123
124
125
126
127 @RequestMapping(params = "methodToCall=getSelectedKey")
128 public ModelAndView getSelectedKey(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
129 HttpServletRequest request, HttpServletResponse response) {
130
131
132 Map<String, String> states = (Map<String, String>) form.getClientStateForSyncing().get(EnrolKRMSConstants.KSKRMS_RULE_AO_TABS_ID);
133 states.put(KRMSConstants.KRMS_PARM_ACTIVE_TAB, EnrolKRMSConstants.KSKRMS_RULE_AO_EDITWITHOBJECT_ID);
134
135
136 String selectedKey = request.getParameter(KRMSConstants.KRMS_PARM_SELECTED_KEY);
137 getRuleEditor(form).setSelectedKey(selectedKey);
138
139 return this.goToEditProposition(form, result, request, response);
140 }
141
142
143
144
145
146
147
148
149
150
151 @RequestMapping(params = "methodToCall=compareRules")
152 public ModelAndView compareRules(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
153 HttpServletRequest request, HttpServletResponse response) {
154
155 MaintenanceDocumentForm document = this.getMaintenanceDocumentForm( form);
156 AORuleManagementWrapper ruleWrapper = (AORuleManagementWrapper) document.getDocument().getNewMaintainableObject().getDataObject();
157
158 RuleEditor aoRuleEditor = ruleWrapper.getRuleEditor();
159
160 if(aoRuleEditor == null) {
161 String ruleId = document.getActionParamaterValue(KRMSConstants.KRMS_PARM_RULE_KEY);
162 if ((ruleId != null) && (StringUtils.isNotBlank(ruleId))) {
163
164 aoRuleEditor = AgendaUtilities.getSelectedRuleEditor(ruleWrapper, ruleId);
165 }
166 }
167
168 if (aoRuleEditor != null){
169 RuleEditor cluRuleEditor = ((AORuleEditor) aoRuleEditor).getCluEditor();
170
171 ruleWrapper.setCompareTree(this.getViewHelper(form).buildCompareTree(cluRuleEditor, aoRuleEditor));
172 ruleWrapper.setCompareLightBoxHeader(aoRuleEditor.getRuleTypeInfo().getDescription());
173 }
174
175
176 return showDialog(EnrolKRMSConstants.KSKRMS_DIALOG_COMPARE_CLU_CO_AO, form, request, response);
177 }
178
179
180
181
182
183
184
185
186
187
188 @RequestMapping(params = "methodToCall=viewCoAndCluRules")
189 public ModelAndView viewCoAndCluRules(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
190 HttpServletRequest request, HttpServletResponse response) {
191
192 MaintenanceDocumentForm document = this.getMaintenanceDocumentForm( form);
193 Object dataObject = document.getDocument().getNewMaintainableObject().getDataObject();
194 if (dataObject instanceof AORuleManagementWrapper) {
195 AORuleManagementWrapper ruleWrapper = (AORuleManagementWrapper) dataObject;
196 String ruleId = document.getActionParamaterValue("ruleKey");
197 RuleEditor aoRuleEditor;
198 if ((ruleId != null) && (StringUtils.isNotBlank(ruleId))) {
199
200 aoRuleEditor = AgendaUtilities.getSelectedRuleEditor(ruleWrapper, ruleId);
201 } else {
202
203 aoRuleEditor = ruleWrapper.getRuleEditor();
204 }
205
206 RuleEditor cluRuleEditor = null;
207 if (aoRuleEditor != null) {
208 cluRuleEditor = ((AORuleEditor) aoRuleEditor).getCluEditor();
209
210 ruleWrapper.setCompareTree(this.getViewHelper(form).buildMultiViewTree(cluRuleEditor, aoRuleEditor.getParent()));
211 ruleWrapper.setCompareLightBoxHeader(aoRuleEditor.getRuleTypeInfo().getDescription());
212 }
213 }
214
215
216 return showDialog(EnrolKRMSConstants.KSKRMS_DIALOG_VIEW_CLU_CO, form, request, response);
217 }
218
219
220
221
222
223
224
225
226
227
228 @RequestMapping(params = "methodToCall=deleteRuleStatements")
229 public ModelAndView deleteRuleStatements(@ModelAttribute("KualiForm") UifFormBase form, @SuppressWarnings("unused") BindingResult result,
230 @SuppressWarnings("unused") HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) {
231
232 MaintenanceDocumentForm document = this.getMaintenanceDocumentForm( form);
233 RuleManager ruleWrapper = AgendaUtilities.getRuleWrapper(document);
234 String ruleKey = AgendaUtilities.getRuleKey(document);
235
236 AgendaEditor agenda = AgendaUtilities.getSelectedAgendaEditor(ruleWrapper, ruleKey);
237 if (agenda != null) {
238 RuleEditor ruleEditor = agenda.getRuleEditors().get(ruleKey);
239 if(ruleEditor.getProposition() != null){
240 ruleEditor.setProposition(null);
241 }
242 else{
243 form.getClientStateForSyncing().clear();
244 ruleEditor.setDummy(false);
245 }
246
247 compareRulePropositions(this.getMaintenanceDocumentForm( form), ruleEditor);
248 this.getViewHelper(form).refreshViewTree(ruleEditor);
249
250 }
251
252 return getUIFModelAndView(document);
253 }
254
255
256
257
258
259
260
261
262
263 @RequestMapping(params = "methodToCall=copyEditCoRule")
264 public ModelAndView copyEditCoRule(@ModelAttribute("KualiForm") UifFormBase form, @SuppressWarnings("unused") BindingResult result,
265 @SuppressWarnings("unused") HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) {
266
267
268 form.getClientStateForSyncing().clear();
269 MaintenanceDocumentForm document = this.getMaintenanceDocumentForm( form);
270
271 AORuleEditor ruleEditor = (AORuleEditor) AgendaUtilities.getSelectedRuleEditor(document);
272 AORuleEditor enrolRuleEditor = new AORuleEditor(ruleEditor.getKey(), false, ruleEditor.getRuleTypeInfo());
273 enrolRuleEditor.setParent(ruleEditor.getParent());
274 enrolRuleEditor.setCluEditor(ruleEditor.getCluEditor());
275
276 PropositionEditor parentProp = ruleEditor.getParent().getPropositionEditor();
277 AORuleEditorMaintainableImpl aoMaintainable = (AORuleEditorMaintainableImpl) document.getDocument().getNewMaintainableObject();
278 aoMaintainable.initPropositionEditor(parentProp);
279
280 enrolRuleEditor.setProposition(((AORuleViewHelperServiceImpl) this.getViewHelper(form)).copyCOProposition(parentProp));
281 AgendaUtilities.getRuleWrapper(document).setRuleEditor(enrolRuleEditor);
282
283 this.getViewHelper(form).refreshInitTrees(enrolRuleEditor);
284 form.getActionParameters().put(UifParameters.NAVIGATE_TO_PAGE_ID, EnrolKRMSConstants.KSKRMS_RULE_AO_MAINTENANCE_PAGE_ID);
285
286
287 AORuleManagementWrapper aoRuleMgtWrapper = (AORuleManagementWrapper) AgendaUtilities.getRuleWrapper(document);
288 aoRuleMgtWrapper.setCopyEditCORuleDirty(true);
289
290 return super.navigate(form, result, request, response);
291
292 }
293
294
295
296
297
298
299
300
301
302
303 @Override
304 @RequestMapping(params = "methodToCall=deleteRule")
305 public ModelAndView deleteRule(@ModelAttribute("KualiForm") UifFormBase form, @SuppressWarnings("unused") BindingResult result,
306 @SuppressWarnings("unused") HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) {
307
308 MaintenanceDocumentForm document = this.getMaintenanceDocumentForm( form);
309 RuleManager ruleWrapper = AgendaUtilities.getRuleWrapper(document);
310 String ruleKey = AgendaUtilities.getRuleKey(document);
311
312 AgendaEditor agenda = AgendaUtilities.getSelectedAgendaEditor(ruleWrapper, ruleKey);
313 if (agenda != null) {
314 AORuleEditor ruleEditor = (AORuleEditor) agenda.getRuleEditors().get(ruleKey);
315
316
317 if (ruleEditor.getId() != null) {
318 agenda.getDeletedRules().add(ruleEditor);
319 }
320
321 AORuleEditor dummyRule = new AORuleEditor(ruleEditor.getKey(), true, ruleEditor.getRuleTypeInfo());
322 dummyRule.setParent(ruleEditor.getParent());
323 dummyRule.setCluEditor(ruleEditor.getCluEditor());
324 agenda.getRuleEditors().put(ruleEditor.getKey(), dummyRule);
325 }
326
327
328 AORuleManagementWrapper aoRuleMgtWrapper = (AORuleManagementWrapper) ruleWrapper;
329 aoRuleMgtWrapper.setAgendaDirty(true);
330
331 return getUIFModelAndView(document);
332 }
333
334 protected void compareRulePropositions(MaintenanceDocumentForm form, RuleEditor ruleEditor) {
335
336 RuleManager ruleWrapper = (RuleManager) form.getDocument().getNewMaintainableObject().getDataObject();
337
338
339 if (ruleEditor.getProposition() != null) {
340 if (!this.getViewHelper(form).compareRules(ruleWrapper.getRuleEditor())) {
341 GlobalVariables.getMessageMap().putInfoForSectionId(KRMSConstants.KRMS_RULE_TREE_GROUP_ID, EnrolKRMSConstants.KSKRMS_MSG_INFO_AO_RULE_CHANGED);
342 } else if (GlobalVariables.getMessageMap().containsMessageKey(KRMSConstants.KRMS_RULE_TREE_GROUP_ID)) {
343 GlobalVariables.getMessageMap().removeAllInfoMessagesForProperty(KRMSConstants.KRMS_RULE_TREE_GROUP_ID);
344 }
345 }
346 }
347
348 }
349
350