1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.student.enrollment.class2.scheduleofclasses.controller;
18
19
20
21
22
23
24
25 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
26 import org.kuali.rice.krad.util.GlobalVariables;
27 import org.kuali.rice.krad.web.controller.UifControllerBase;
28 import org.kuali.rice.krad.web.form.UifFormBase;
29 import org.kuali.student.enrollment.acal.service.AcademicCalendarService;
30 import org.kuali.student.enrollment.class2.scheduleofclasses.form.ScheduleOfClassesSearchForm;
31 import org.kuali.student.enrollment.class2.scheduleofclasses.service.ScheduleOfClassesViewHelperService;
32 import org.kuali.student.enrollment.class2.scheduleofclasses.util.ScheduleOfClassesConstants;
33 import org.kuali.student.enrollment.class2.scheduleofclasses.util.ScheduleOfClassesUtil;
34 import org.kuali.student.enrollment.courseofferingset.service.CourseOfferingSetService;
35 import org.kuali.student.r2.common.dto.ContextInfo;
36 import org.kuali.student.r2.common.util.ContextUtils;
37 import org.kuali.student.r2.common.util.constants.AcademicCalendarServiceConstants;
38 import org.kuali.student.r2.common.util.constants.CourseOfferingSetServiceConstants;
39 import org.kuali.student.r2.core.atp.dto.AtpInfo;
40 import org.kuali.student.r2.core.atp.service.AtpService;
41 import org.kuali.student.r2.core.constants.AtpServiceConstants;
42 import org.springframework.stereotype.Controller;
43 import org.springframework.validation.BindingResult;
44 import org.springframework.web.bind.annotation.ModelAttribute;
45 import org.springframework.web.bind.annotation.RequestMapping;
46 import org.springframework.web.bind.annotation.RequestMethod;
47 import org.springframework.web.servlet.ModelAndView;
48
49 import javax.servlet.http.HttpServletRequest;
50 import javax.servlet.http.HttpServletResponse;
51 import javax.xml.namespace.QName;
52 import java.util.List;
53
54 @Controller
55 @RequestMapping(value = "/scheduleOfClassesSearch")
56 public class ScheduleOfClassesSearchController extends UifControllerBase {
57
58 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ScheduleOfClassesSearchController.class);
59 private ScheduleOfClassesViewHelperService viewHelperService;
60 private AcademicCalendarService acalService;
61 private CourseOfferingSetService courseOfferingSetService;
62 private AtpService atpService;
63
64 @Override
65 protected UifFormBase createInitialForm(HttpServletRequest request) {
66 return new ScheduleOfClassesSearchForm();
67 }
68
69 @Override
70 @RequestMapping(method = RequestMethod.GET, params = "methodToCall=start")
71 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
72 HttpServletRequest request, HttpServletResponse response) {
73 ScheduleOfClassesSearchForm scheduleOfClassesSearchForm = (ScheduleOfClassesSearchForm)form;
74 scheduleOfClassesSearchForm.setSearchType("course");
75
76 if(scheduleOfClassesSearchForm.getTermCode() == null){
77 ContextInfo context = ContextUtils.getContextInfo();
78 List<AtpInfo> atps = ScheduleOfClassesUtil.getValidSocTerms(getCourseOfferingSetService(), getAtpService(), context);
79
80 if(!atps.isEmpty()){
81 scheduleOfClassesSearchForm.setTermCode(ScheduleOfClassesUtil.getCurrentAtp(atps).getCode());
82 }
83 }
84
85 return super.start(form, result, request, response);
86 }
87
88
89
90
91
92 @RequestMapping(params = "methodToCall=show")
93 public ModelAndView show(@ModelAttribute("KualiForm") ScheduleOfClassesSearchForm theForm, BindingResult result,
94 HttpServletRequest request, HttpServletResponse response) throws Exception {
95
96
97 String termCode = theForm.getTermCode();
98 if (termCode != null && termCode.length() > 0) {
99 String termName = getAcademicCalendarService().getTerm(termCode, ContextUtils.createDefaultContextInfo()).getName();
100 theForm.setTermName(termName);
101 } else{
102 LOG.error("Error: term can't be empty");
103 GlobalVariables.getMessageMap().putError("termCode", ScheduleOfClassesConstants.SOC_MSG_ERROR_TERM_IS_EMPTY);
104 return getUIFModelAndView(theForm);
105 }
106
107
108 if (theForm.getSearchType().equals("course")){
109 String course = theForm.getCourse();
110 if (course != null && course.length() > 0) {
111 getViewHelperService(theForm).loadCourseOfferingsByTermAndCourseCode(termCode, course, theForm);
112 theForm.setSearchParameter("Course: " + course);
113 } else {
114 LOG.error("Error: search field can't be empty");
115 GlobalVariables.getMessageMap().putError("course", ScheduleOfClassesConstants.SOC_MSG_ERROR_COURSE_IS_EMPTY);
116 return getUIFModelAndView(theForm);
117 }
118 } else if (theForm.getSearchType().equals("instructor")){
119 String instructorId = theForm.getInstructor();
120 String instructorName = theForm.getInstructorName();
121 if ((instructorId != null && !instructorId.isEmpty()) || (instructorName != null && !instructorName.isEmpty())) {
122 getViewHelperService(theForm).loadCourseOfferingsByTermAndInstructor(termCode, instructorId, instructorName, theForm);
123 theForm.setSearchParameter("Instructor: " + instructorName);
124 } else {
125 LOG.error("Error: search field can't be empty");
126 GlobalVariables.getMessageMap().putError("course", ScheduleOfClassesConstants.SOC_MSG_ERROR_COURSE_IS_EMPTY);
127 return getUIFModelAndView(theForm);
128 }
129 } else if (theForm.getSearchType().equals("department")){
130 String departmentId = theForm.getDepartment();
131 String departmentName = theForm.getDepartmentName();
132 if ((departmentId != null && !departmentId.isEmpty()) || (departmentName != null && !departmentName.isEmpty())){
133 getViewHelperService(theForm).loadCourseOfferingsByTermAndDepartment(termCode, departmentId, departmentName, theForm);
134 theForm.setSearchParameter("Department: " + departmentName);
135 } else {
136 LOG.error("Error: search field can't be empty");
137 GlobalVariables.getMessageMap().putError("course", ScheduleOfClassesConstants.SOC_MSG_ERROR_COURSE_IS_EMPTY);
138 return getUIFModelAndView(theForm);
139 }
140 } else if (theForm.getSearchType().equals("titleDesc")){
141 String titleDesc = theForm.getTitleDesc();
142 if (titleDesc != null && titleDesc.length() > 0) {
143 getViewHelperService(theForm).loadCourseOfferingsByTitleAndDescription(termCode, titleDesc, theForm);
144 theForm.setSearchParameter("Title & Description: " + titleDesc);
145 } else {
146 LOG.error("Error: search field can't be empty");
147 GlobalVariables.getMessageMap().putError("course", ScheduleOfClassesConstants.SOC_MSG_ERROR_COURSE_IS_EMPTY);
148 return getUIFModelAndView(theForm);
149 }
150 }
151
152 return getUIFModelAndView(theForm, ScheduleOfClassesConstants.SOC_RESULT_PAGE);
153 }
154
155 @RequestMapping(params = "methodToCall=populateAOs")
156 public ModelAndView populateAOs(@ModelAttribute("KualiForm") ScheduleOfClassesSearchForm theForm, BindingResult result,
157 HttpServletRequest request, HttpServletResponse response) throws Exception {
158
159 String courseOfferingId = theForm.getCourseOfferingId();
160
161 if (courseOfferingId != null && courseOfferingId.length() > 0) {
162
163 if(theForm.getDisplayCoId() != null && !theForm.getDisplayCoId().isEmpty()) {
164 theForm.setDisplayCoIdAdd(theForm.getDisplayCoId());
165 theForm.setAoDisplayWrapperAddList(theForm.getAoDisplayWrapperList());
166 } else if ((theForm.getDisplayCoIdAdd() == null || theForm.getDisplayCoIdAdd().isEmpty()) && !theForm.getAoDisplayWrapperAddList().isEmpty()) {
167 theForm.getAoDisplayWrapperAddList().clear();
168 }
169 getViewHelperService(theForm).loadActivityOfferingsByCourseOfferingId(courseOfferingId, theForm);
170
171 theForm.setDisplayCoId(courseOfferingId);
172 } else {
173 LOG.error("Error: search field can't be empty");
174 GlobalVariables.getMessageMap().putError("course", ScheduleOfClassesConstants.SOC_MSG_ERROR_COURSE_IS_EMPTY);
175 return getUIFModelAndView(theForm);
176 }
177
178 return getUIFModelAndView(theForm, ScheduleOfClassesConstants.SOC_RESULT_PAGE);
179 }
180
181 public ScheduleOfClassesViewHelperService getViewHelperService(ScheduleOfClassesSearchForm theForm){
182 if (viewHelperService == null) {
183 if (theForm.getView().getViewHelperServiceClass() != null){
184 viewHelperService = (ScheduleOfClassesViewHelperService) theForm.getView().getViewHelperService();
185 }else{
186 viewHelperService= (ScheduleOfClassesViewHelperService) theForm.getPostedView().getViewHelperService();
187 }
188 }
189 return viewHelperService;
190 }
191
192 protected AcademicCalendarService getAcademicCalendarService() {
193 if(acalService == null) {
194 acalService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName(AcademicCalendarServiceConstants.NAMESPACE, AcademicCalendarServiceConstants.SERVICE_NAME_LOCAL_PART));
195 }
196 return this.acalService;
197 }
198
199 protected CourseOfferingSetService getCourseOfferingSetService() {
200 if(courseOfferingSetService == null) {
201
202 courseOfferingSetService = (CourseOfferingSetService) GlobalResourceLoader.getService(new QName(CourseOfferingSetServiceConstants.NAMESPACE, CourseOfferingSetServiceConstants.SERVICE_NAME_LOCAL_PART));
203 }
204 return this.courseOfferingSetService;
205 }
206
207 protected AtpService getAtpService() {
208 if(atpService == null) {
209 atpService = (AtpService) GlobalResourceLoader.getService(new QName(AtpServiceConstants.NAMESPACE, AtpServiceConstants.SERVICE_NAME_LOCAL_PART));
210 }
211 return this.atpService;
212 }
213
214 }