1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.enrollment.class1.krms.controller;
17
18 import org.kuali.rice.krad.uif.UifConstants;
19 import org.kuali.rice.krad.uif.UifParameters;
20 import org.kuali.rice.krad.util.KRADConstants;
21 import org.kuali.rice.krad.web.form.DocumentFormBase;
22 import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
23 import org.kuali.rice.krad.web.form.UifFormBase;
24 import org.kuali.rice.krms.controller.RuleEditorController;
25 import org.kuali.rice.krms.dto.RuleEditor;
26 import org.kuali.rice.krms.util.AgendaUtilities;
27 import org.kuali.rice.krms.util.KRMSConstants;
28 import org.kuali.rice.krms.util.PropositionTreeUtil;
29 import org.kuali.student.common.uif.util.KSControllerHelper;
30 import org.kuali.student.enrollment.class1.krms.dto.CORuleManagementWrapper;
31 import org.kuali.student.enrollment.class1.krms.util.EnrolKRMSConstants;
32 import org.kuali.student.lum.lu.ui.krms.dto.CluSetInformation;
33 import org.kuali.student.lum.lu.ui.krms.dto.CluSetRangeInformation;
34 import org.kuali.student.lum.lu.ui.krms.dto.LUPropositionEditor;
35 import org.kuali.student.lum.lu.ui.krms.dto.LURuleEditor;
36 import org.kuali.student.lum.lu.ui.krms.service.impl.LURuleViewHelperServiceImpl;
37 import org.kuali.student.lum.lu.ui.krms.util.CluSetRangeHelper;
38 import org.kuali.student.r2.lum.clu.dto.MembershipQueryInfo;
39 import org.springframework.validation.BindingResult;
40 import org.springframework.web.bind.annotation.ModelAttribute;
41 import org.springframework.web.bind.annotation.RequestMapping;
42 import org.springframework.web.servlet.ModelAndView;
43
44 import javax.servlet.http.HttpServletRequest;
45 import javax.servlet.http.HttpServletResponse;
46
47
48
49
50
51
52 public class EnrolRuleEditorController extends RuleEditorController {
53
54
55
56
57
58 @RequestMapping(params = "methodToCall=" + KRADConstants.Maintenance.METHOD_TO_CALL_EDIT)
59 public ModelAndView maintenanceEdit(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result,
60 HttpServletRequest request, HttpServletResponse response) throws Exception {
61
62 setupMaintenance(form, request, KRADConstants.MAINTENANCE_EDIT_ACTION);
63
64 return getUIFModelAndView(form);
65 }
66
67
68
69
70
71
72
73
74
75 @Override
76 @RequestMapping(params = "methodToCall=route")
77 public ModelAndView route(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
78 HttpServletRequest request, HttpServletResponse response) {
79 super.route(form, result, request, response);
80 return back(form, result, request, response);
81 }
82
83
84
85
86
87
88
89
90
91 @RequestMapping(params = "methodToCall=cancel")
92 @Override
93 public ModelAndView cancel(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
94 HttpServletRequest request, HttpServletResponse response) {
95
96 DocumentFormBase documentForm = (DocumentFormBase) form;
97 performWorkflowAction(documentForm, UifConstants.WorkflowAction.CANCEL, false);
98
99 return back(form,result,request,response);
100 }
101
102
103
104
105
106
107
108
109
110 @Override
111 @RequestMapping(params = "methodToCall=addRule")
112 public ModelAndView addRule(@ModelAttribute("KualiForm") UifFormBase form, @SuppressWarnings("unused") BindingResult result,
113 @SuppressWarnings("unused") HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) {
114
115
116 form.getClientStateForSyncing().clear();
117 MaintenanceDocumentForm document = (MaintenanceDocumentForm) form;
118
119 RuleEditor ruleEditor = AgendaUtilities.getSelectedRuleEditor(document);
120 LURuleEditor enrolRuleEditor = new LURuleEditor(ruleEditor.getKey(), true, ruleEditor.getRuleTypeInfo());
121 enrolRuleEditor.setParent(ruleEditor.getParent());
122 AgendaUtilities.getRuleWrapper(document).setRuleEditor(enrolRuleEditor);
123
124 this.getViewHelper(form).refreshInitTrees(enrolRuleEditor);
125
126 if(!form.getActionParameters().containsKey(UifParameters.NAVIGATE_TO_PAGE_ID)){
127 form.getActionParameters().put(UifParameters.NAVIGATE_TO_PAGE_ID, KRMSConstants.KRMS_RULE_MAINTENANCE_PAGE_ID);
128 }
129 return super.navigate(form, result, request, response);
130 }
131
132
133
134
135
136
137
138
139
140
141 @RequestMapping(params="methodToCall=viewCourseRange")
142 public ModelAndView viewCourseRange(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
143 HttpServletRequest request, HttpServletResponse response) {
144
145 MaintenanceDocumentForm document = (MaintenanceDocumentForm) form;
146 CORuleManagementWrapper ruleWrapper = (CORuleManagementWrapper) document.getDocument().getNewMaintainableObject().getDataObject();
147 LUPropositionEditor proposition = (LUPropositionEditor) PropositionTreeUtil.getProposition(ruleWrapper.getRuleEditor());
148
149 String index = form.getActionParameters().get("selectedIndex");
150 if ((proposition.getCluSet() != null) && (proposition.getCluSet().getCluSetRanges()!=null)){
151 ruleWrapper.setClusInRange(proposition.getCluSet().getCluSetRanges().get(Integer.valueOf(index)).getClusInRange());
152 }
153
154 return showDialog(EnrolKRMSConstants.KSKRMS_DIALOG_COURSERANGE_LOOKUP, form, request, response);
155 }
156
157
158
159
160
161
162
163
164
165
166 @RequestMapping(params = "methodToCall=addRange")
167 public ModelAndView addRange(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
168 HttpServletRequest request, HttpServletResponse response) {
169
170 LURuleEditor rule = (LURuleEditor) getRuleEditor(form);
171 LUPropositionEditor prop = (LUPropositionEditor) PropositionTreeUtil.getProposition(rule);
172
173 if(prop.getCluSet()==null){
174 prop.setCluSet(new CluSetInformation());
175 }
176
177
178 CluSetRangeHelper rangeHelper = prop.getCluSet().getRangeHelper();
179 if(!rangeHelper.validateCourseRange(prop)){
180 return getUIFModelAndView(form);
181 }
182
183 MembershipQueryInfo membershipQueryInfo = rangeHelper.buildMembershipQuery();
184
185
186 CluSetRangeInformation cluSetRange = new CluSetRangeInformation();
187 cluSetRange.setCluSetRangeLabel(rangeHelper.buildLabelFromQuery(membershipQueryInfo));
188 cluSetRange.setMembershipQueryInfo(membershipQueryInfo);
189 cluSetRange.setClusInRange(this.getViewHelper(form).getCoursesInRange(membershipQueryInfo));
190
191 if(!rangeHelper.validateCoursesInRange(prop, cluSetRange)) {
192 return getUIFModelAndView(form);
193 }
194
195 prop.getCluSet().getCluSetRanges().add(cluSetRange);
196
197
198 rangeHelper.reset();
199
200 return getUIFModelAndView(form);
201 }
202
203
204
205
206
207
208 protected LURuleViewHelperServiceImpl getViewHelper(UifFormBase form) {
209 return (LURuleViewHelperServiceImpl) KSControllerHelper.getViewHelperService(form);
210 }
211 }