1 package org.kuali.student.enrollment.class2.grading.controller;
2
3
4
5
6
7
8
9
10
11
12
13
14 import org.apache.commons.lang.StringUtils;
15 import org.kuali.rice.krad.uif.UifParameters;
16 import org.kuali.rice.krad.util.GlobalVariables;
17 import org.kuali.rice.krad.web.controller.UifControllerBase;
18 import org.kuali.rice.krad.web.form.UifFormBase;
19 import org.kuali.student.enrollment.class2.grading.dataobject.GradeStudent;
20 import org.kuali.student.enrollment.class2.grading.form.GradingForm;
21 import org.kuali.student.enrollment.class2.grading.form.StudentGradeForm;
22 import org.kuali.student.enrollment.class2.grading.service.GradingViewHelperService;
23 import org.kuali.student.enrollment.class2.grading.util.GradingConstants;
24 import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
25 import org.springframework.stereotype.Controller;
26 import org.springframework.validation.BindingResult;
27 import org.springframework.web.bind.annotation.ModelAttribute;
28 import org.springframework.web.bind.annotation.RequestMapping;
29 import org.springframework.web.bind.annotation.RequestMethod;
30 import org.springframework.web.servlet.ModelAndView;
31
32 import javax.servlet.http.HttpServletRequest;
33 import javax.servlet.http.HttpServletResponse;
34 import java.util.ArrayList;
35 import java.util.List;
36
37 @Controller
38 @RequestMapping(value = "/grading")
39 public class GradingController extends UifControllerBase {
40 protected UifFormBase createInitialForm(HttpServletRequest httpServletRequest) {
41 if (StringUtils.equals(httpServletRequest.getParameter("viewId"), "StudentGradeView")) {
42 return new StudentGradeForm();
43 } else {
44 return new GradingForm();
45 }
46 }
47
48 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=" + GradingConstants.LOAD_GRADES_ROSTER_METHOD)
49 public ModelAndView loadGradeRoster(@ModelAttribute("KualiForm") GradingForm gradingForm, BindingResult result,
50 HttpServletRequest request, HttpServletResponse response) throws Exception {
51
52 String selectedCourse = gradingForm.getSelectedCourse();
53 List<GradeStudent> students = ((GradingViewHelperService) gradingForm.getView().getViewHelperService()).loadStudents(selectedCourse,gradingForm);
54 gradingForm.setStudents(students);
55
56 return getUIFModelAndView(gradingForm, GradingConstants.GRADE_ROSTER_PAGE);
57 }
58
59 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=loadStudents")
60 public ModelAndView loadStudents(@ModelAttribute("KualiForm") GradingForm gradingForm, BindingResult result,
61 HttpServletRequest request, HttpServletResponse response) throws Exception {
62
63 int selectedLineIndex = -1;
64 String selectedLine = gradingForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX);
65 if (StringUtils.isNotBlank(selectedLine)) {
66 selectedLineIndex = Integer.parseInt(selectedLine);
67 }
68
69 CourseOfferingInfo selectedCourse = gradingForm.getCourseOfferingInfoList().get(selectedLineIndex);
70 String courseId = selectedCourse.getId();
71 gradingForm.setSelectedCourseOffering(selectedCourse);
72
73
74 resetValuesForPageChange(gradingForm);
75
76
77 gradingForm.setTitle(selectedCourse.getCourseOfferingCode() + " - " + selectedCourse.getCourseOfferingTitle());
78
79 List<GradeStudent> students = ((GradingViewHelperService) gradingForm.getView().getViewHelperService()).loadStudents(courseId,gradingForm);
80
81 if (students == null || students.isEmpty()){
82
83 GlobalVariables.getMessageMap().putInfo("firstName",GradingConstants.INFO_GRADE_STUDENTS_NOT_FOUND,selectedCourse.getCourseOfferingCode());
84 gradingForm.setReadOnly(true);
85 }else{
86 gradingForm.setStudents(students);
87 }
88
89 return getUIFModelAndView(gradingForm, GradingConstants.GRADE_ROSTER_PAGE);
90 }
91
92 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=" + GradingConstants.UNASSIGN_GRADE_METHOD)
93 public ModelAndView unassignGrade(@ModelAttribute("KualiForm") GradingForm gradingForm, BindingResult result,
94 HttpServletRequest request, HttpServletResponse response) {
95
96 String selectedCollectionPath = gradingForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
97 if (StringUtils.isBlank(selectedCollectionPath)) {
98 throw new RuntimeException("Selected collection was not set for unassign action, cannot unassign grade");
99 }
100
101 int selectedLineIndex = -1;
102 String selectedLine = gradingForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX);
103 if (StringUtils.isNotBlank(selectedLine)) {
104 selectedLineIndex = Integer.parseInt(selectedLine);
105 }
106
107 if (selectedLineIndex == -1) {
108 throw new RuntimeException(
109 "Selected line index was not set for delete unassign action, cannot unassign grade");
110 }
111
112
113 ((GradingViewHelperService) gradingForm.getView().getViewHelperService()).unAssignGrade(gradingForm.getView(),
114 gradingForm, selectedCollectionPath, selectedLineIndex);
115
116 return getUIFModelAndView(gradingForm, GradingConstants.GRADE_ROSTER_PAGE);
117 }
118
119 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=" + GradingConstants.BACK_TO_GRADING_METHOD)
120 public ModelAndView backToGrading(@ModelAttribute("KualiForm") GradingForm gradingForm, BindingResult result,
121 HttpServletRequest request, HttpServletResponse response) throws Exception {
122 return getUIFModelAndView(gradingForm, GradingConstants.SELECT_COURSE_OFFERING_PAGE);
123 }
124
125 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=" + GradingConstants.BACK_TO_TERM)
126 public ModelAndView backToTerm(@ModelAttribute("KualiForm") StudentGradeForm studentGradeForm, BindingResult result,
127 HttpServletRequest request, HttpServletResponse response) throws Exception {
128 return getUIFModelAndView(studentGradeForm, GradingConstants.STUDENT_TERM_RECORD_PAGE);
129 }
130
131 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=" + GradingConstants.SAVE_METHOD)
132 public ModelAndView save(@ModelAttribute("KualiForm") GradingForm gradingForm, BindingResult result,
133 HttpServletRequest request, HttpServletResponse response) throws Exception {
134
135 boolean success = ((GradingViewHelperService) gradingForm.getView().getViewHelperService()).saveGrades(gradingForm);
136
137 if (success){
138
139 GlobalVariables.getMessageMap().putInfo("firstName", GradingConstants.INFO_GRADE_ROSTER_SAVED);
140 }
141
142 gradingForm.setRenderFullView(false);
143
144 return getUIFModelAndView(gradingForm, GradingConstants.GRADE_ROSTER_PAGE);
145 }
146
147 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=" + GradingConstants.LOAD_COURSES_METHOD)
148 public ModelAndView loadCourses(@ModelAttribute("KualiForm") GradingForm gradingForm, BindingResult result,
149 HttpServletRequest request, HttpServletResponse response) throws Exception {
150
151 ((GradingViewHelperService) gradingForm.getView().getViewHelperService()).loadCourses(gradingForm);
152 return getUIFModelAndView(gradingForm, GradingConstants.SELECT_COURSE_OFFERING_PAGE);
153
154 }
155
156 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=" + GradingConstants.SUBMIT_METHOD)
157 public ModelAndView submit(@ModelAttribute("KualiForm") GradingForm gradingForm, BindingResult result,
158 HttpServletRequest request, HttpServletResponse response) throws Exception {
159
160 boolean success = ((GradingViewHelperService) gradingForm.getView().getViewHelperService()).submitGradeRoster(gradingForm);
161
162 if (success){
163
164 GlobalVariables.getMessageMap().putInfo("firstName",GradingConstants.INFO_GRADE_ROSTER_SUBMITTED);
165 }
166
167 return getUIFModelAndView(gradingForm, GradingConstants.SELECT_COURSE_OFFERING_PAGE);
168 }
169
170 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=" + GradingConstants.VIEW_GRADES)
171 public ModelAndView viewGrades(@ModelAttribute("KualiForm") StudentGradeForm studentGradeForm,
172 BindingResult result, HttpServletRequest request, HttpServletResponse response) throws Exception {
173
174 ((GradingViewHelperService) studentGradeForm.getView().getViewHelperService()).loadStudentGrades(studentGradeForm);
175
176 return getUIFModelAndView(studentGradeForm, GradingConstants.STUDENT_CREDIT_DETAILS_PAGE);
177 }
178
179 private void resetValuesForPageChange(GradingForm form){
180 form.setStudents(new ArrayList());
181 form.setReadOnly(false);
182 form.setRosterInfos(new ArrayList());
183 }
184
185 }