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