| 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 | 0 | public class GradingController extends UifControllerBase { |
| 40 | |
protected UifFormBase createInitialForm(HttpServletRequest httpServletRequest) { |
| 41 | 0 | if (StringUtils.equals(httpServletRequest.getParameter("viewId"), "StudentGradeView")) { |
| 42 | 0 | return new StudentGradeForm(); |
| 43 | |
} else { |
| 44 | 0 | 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 | 0 | String selectedCourse = gradingForm.getSelectedCourse(); |
| 53 | 0 | List<GradeStudent> students = ((GradingViewHelperService) gradingForm.getView().getViewHelperService()).loadStudents(selectedCourse,gradingForm); |
| 54 | 0 | gradingForm.setStudents(students); |
| 55 | |
|
| 56 | 0 | 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 | 0 | int selectedLineIndex = -1; |
| 64 | 0 | String selectedLine = gradingForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX); |
| 65 | 0 | if (StringUtils.isNotBlank(selectedLine)) { |
| 66 | 0 | selectedLineIndex = Integer.parseInt(selectedLine); |
| 67 | |
} |
| 68 | |
|
| 69 | 0 | CourseOfferingInfo selectedCourse = gradingForm.getCourseOfferingInfoList().get(selectedLineIndex); |
| 70 | 0 | String courseId = selectedCourse.getId(); |
| 71 | 0 | gradingForm.setSelectedCourseOffering(selectedCourse); |
| 72 | |
|
| 73 | |
|
| 74 | 0 | resetValuesForPageChange(gradingForm); |
| 75 | |
|
| 76 | |
|
| 77 | 0 | gradingForm.setTitle(selectedCourse.getCourseOfferingCode() + " - " + selectedCourse.getCourseOfferingTitle()); |
| 78 | |
|
| 79 | 0 | List<GradeStudent> students = ((GradingViewHelperService) gradingForm.getView().getViewHelperService()).loadStudents(courseId,gradingForm); |
| 80 | |
|
| 81 | 0 | if (students == null || students.isEmpty()){ |
| 82 | |
|
| 83 | 0 | GlobalVariables.getMessageMap().putInfo("firstName",GradingConstants.INFO_GRADE_STUDENTS_NOT_FOUND,selectedCourse.getCourseOfferingCode()); |
| 84 | 0 | gradingForm.setReadOnly(true); |
| 85 | |
}else{ |
| 86 | 0 | gradingForm.setStudents(students); |
| 87 | |
} |
| 88 | |
|
| 89 | 0 | 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 | 0 | String selectedCollectionPath = gradingForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH); |
| 97 | 0 | if (StringUtils.isBlank(selectedCollectionPath)) { |
| 98 | 0 | throw new RuntimeException("Selected collection was not set for unassign action, cannot unassign grade"); |
| 99 | |
} |
| 100 | |
|
| 101 | 0 | int selectedLineIndex = -1; |
| 102 | 0 | String selectedLine = gradingForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX); |
| 103 | 0 | if (StringUtils.isNotBlank(selectedLine)) { |
| 104 | 0 | selectedLineIndex = Integer.parseInt(selectedLine); |
| 105 | |
} |
| 106 | |
|
| 107 | 0 | if (selectedLineIndex == -1) { |
| 108 | 0 | throw new RuntimeException( |
| 109 | |
"Selected line index was not set for delete unassign action, cannot unassign grade"); |
| 110 | |
} |
| 111 | |
|
| 112 | |
|
| 113 | 0 | ((GradingViewHelperService) gradingForm.getView().getViewHelperService()).unAssignGrade(gradingForm.getView(), |
| 114 | |
gradingForm, selectedCollectionPath, selectedLineIndex); |
| 115 | |
|
| 116 | 0 | 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 | 0 | 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 | 0 | 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 | 0 | boolean success = ((GradingViewHelperService) gradingForm.getView().getViewHelperService()).saveGrades(gradingForm); |
| 136 | |
|
| 137 | 0 | if (success){ |
| 138 | |
|
| 139 | 0 | GlobalVariables.getMessageMap().putInfo("firstName", GradingConstants.INFO_GRADE_ROSTER_SAVED); |
| 140 | |
} |
| 141 | |
|
| 142 | 0 | gradingForm.setRenderFullView(false); |
| 143 | |
|
| 144 | 0 | 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 | 0 | ((GradingViewHelperService) gradingForm.getView().getViewHelperService()).loadCourses(gradingForm); |
| 152 | 0 | 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 | 0 | boolean success = ((GradingViewHelperService) gradingForm.getView().getViewHelperService()).submitGradeRoster(gradingForm); |
| 161 | |
|
| 162 | 0 | if (success){ |
| 163 | |
|
| 164 | 0 | GlobalVariables.getMessageMap().putInfo("firstName",GradingConstants.INFO_GRADE_ROSTER_SUBMITTED); |
| 165 | |
} |
| 166 | |
|
| 167 | 0 | 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 | 0 | ((GradingViewHelperService) studentGradeForm.getView().getViewHelperService()).loadStudentGrades(studentGradeForm); |
| 175 | |
|
| 176 | 0 | return getUIFModelAndView(studentGradeForm, GradingConstants.STUDENT_CREDIT_DETAILS_PAGE); |
| 177 | |
} |
| 178 | |
|
| 179 | |
private void resetValuesForPageChange(GradingForm form){ |
| 180 | 0 | form.setStudents(new ArrayList()); |
| 181 | 0 | form.setReadOnly(false); |
| 182 | 0 | form.setRosterInfos(new ArrayList()); |
| 183 | 0 | } |
| 184 | |
|
| 185 | |
} |