1 package org.kuali.student.enrollment.class2.courseoffering.controller;
2
3 import org.apache.commons.lang.BooleanUtils;
4 import org.apache.commons.lang.StringUtils;
5 import org.kuali.rice.core.api.criteria.Predicate;
6 import org.kuali.rice.core.api.criteria.PredicateFactory;
7 import org.kuali.rice.core.api.criteria.QueryByCriteria;
8 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
9 import org.kuali.rice.core.api.util.RiceKeyConstants;
10 import org.kuali.rice.krad.uif.UifConstants;
11 import org.kuali.rice.krad.uif.UifParameters;
12 import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
13 import org.kuali.rice.krad.util.GlobalVariables;
14 import org.kuali.rice.krad.util.KRADConstants;
15 import org.kuali.rice.krad.web.controller.UifControllerBase;
16 import org.kuali.rice.krad.web.form.UifFormBase;
17 import org.kuali.student.enrollment.acal.dto.TermInfo;
18 import org.kuali.student.enrollment.acal.service.AcademicCalendarService;
19 import org.kuali.student.enrollment.class2.courseoffering.dto.ActivityOfferingWrapper;
20 import org.kuali.student.enrollment.class2.courseoffering.dto.CourseOfferingCopyWrapper;
21 import org.kuali.student.enrollment.class2.courseoffering.dto.CourseOfferingEditWrapper;
22 import org.kuali.student.enrollment.class2.courseoffering.dto.ExistingCourseOffering;
23 import org.kuali.student.enrollment.class2.courseoffering.dto.RegistrationGroupWrapper;
24 import org.kuali.student.enrollment.class2.courseoffering.form.CourseOfferingManagementForm;
25 import org.kuali.student.enrollment.class2.courseoffering.service.CourseOfferingManagementViewHelperService;
26 import org.kuali.student.enrollment.class2.courseoffering.service.impl.CourseOfferingManagementViewHelperServiceImpl;
27 import org.kuali.student.enrollment.class2.courseoffering.util.ActivityOfferingConstants;
28 import org.kuali.student.enrollment.class2.courseoffering.util.CourseOfferingConstants;
29 import org.kuali.student.enrollment.class2.courseoffering.util.CourseOfferingResourceLoader;
30 import org.kuali.student.enrollment.class2.courseoffering.util.ViewHelperUtil;
31 import org.kuali.student.enrollment.common.util.ContextBuilder;
32 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo;
33 import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
34 import org.kuali.student.enrollment.courseoffering.dto.FormatOfferingInfo;
35 import org.kuali.student.enrollment.courseoffering.dto.RegistrationGroupInfo;
36 import org.kuali.student.enrollment.courseoffering.service.CourseOfferingService;
37 import org.kuali.student.r1.common.search.dto.*;
38 import org.kuali.student.r2.common.constants.CommonServiceConstants;
39 import org.kuali.student.r2.common.dto.ContextInfo;
40 import org.kuali.student.r2.common.dto.LocaleInfo;
41 import org.kuali.student.r2.common.exceptions.*;
42 import org.kuali.student.r2.common.util.ContextUtils;
43 import org.kuali.student.r2.common.util.constants.AcademicCalendarServiceConstants;
44 import org.kuali.student.r2.common.util.constants.CourseOfferingServiceConstants;
45 import org.kuali.student.r2.common.util.constants.CourseOfferingSetServiceConstants;
46 import org.kuali.student.r2.core.organization.dto.OrgInfo;
47 import org.kuali.student.r2.core.organization.service.OrganizationService;
48 import org.kuali.student.r2.lum.clu.service.CluService;
49 import org.kuali.student.r2.lum.course.dto.CourseInfo;
50 import org.kuali.student.r2.lum.course.service.CourseService;
51 import org.kuali.student.r2.lum.lrc.dto.ResultValuesGroupInfo;
52 import org.kuali.student.r2.lum.lrc.service.LRCService;
53 import org.springframework.stereotype.Controller;
54 import org.springframework.validation.BindingResult;
55 import org.springframework.web.bind.annotation.ModelAttribute;
56 import org.springframework.web.bind.annotation.RequestMapping;
57 import org.springframework.web.servlet.ModelAndView;
58
59 import javax.servlet.http.HttpServletRequest;
60 import javax.servlet.http.HttpServletResponse;
61 import javax.xml.namespace.QName;
62 import java.util.*;
63
64 import static org.kuali.rice.core.api.criteria.PredicateFactory.equal;
65
66 @Controller
67 @RequestMapping(value = "/courseOfferingManagement")
68 public class CourseOfferingManagementController extends UifControllerBase {
69 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(CourseOfferingManagementController.class);
70 private CluService luService;
71 private transient LRCService lrcService;
72 private CourseService courseService;
73 private AcademicCalendarService academicCalendarService;
74
75 private CourseOfferingManagementViewHelperService viewHelperService;
76 private OrganizationService organizationService;
77
78 @Override
79 protected UifFormBase createInitialForm(HttpServletRequest request) {
80 return new CourseOfferingManagementForm();
81 }
82
83 @Override
84 @RequestMapping(params = "methodToCall=start")
85 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
86 HttpServletRequest request, HttpServletResponse response) {
87
88
89
90 if (form.getView() != null) {
91 String methodToCall = request.getParameter(KRADConstants.DISPATCH_REQUEST_PARAMETER);
92 checkViewAuthorization(form, methodToCall);
93 }
94
95
96
97
98
99 String[] methodToCalls = request.getParameterValues(KRADConstants.DISPATCH_REQUEST_PARAMETER);
100 for (String methodToCall : methodToCalls) {
101 if (StringUtils.equals(methodToCall,KRADConstants.RETURN_METHOD_TO_CALL)){
102 if (StringUtils.equals(((CourseOfferingManagementForm)form).getRadioSelection(),CourseOfferingConstants.COURSEOFFERING_COURSE_OFFERING_CODE)){
103 form.setPageId(CourseOfferingConstants.MANAGE_AO_PAGE);
104 } else if (StringUtils.equals(((CourseOfferingManagementForm)form).getRadioSelection(),CourseOfferingConstants.COURSEOFFERING_SUBJECT_CODE)){
105 form.setPageId(CourseOfferingConstants.MANAGE_CO_PAGE);
106 }
107 break;
108 }
109 }
110 return getUIFModelAndView(form);
111 }
112
113
114
115
116
117
118
119
120
121
122
123 @RequestMapping(params = "methodToCall=show")
124 public ModelAndView show(@ModelAttribute("KualiForm") CourseOfferingManagementForm theForm, BindingResult result,
125 HttpServletRequest request, HttpServletResponse response) throws Exception {
126
127
128 String termCode = theForm.getTermCode();
129 List<TermInfo> termList = getViewHelperService(theForm).findTermByTermCode(termCode);
130
131 if (termList != null && termList.size() == 1) {
132
133 theForm.setTermInfo(termList.get(0));
134 } else if (termList.size()>1) {
135 LOG.error("Error: Found more than one Term for term code: "+termCode);
136 GlobalVariables.getMessageMap().putError("termCode", CourseOfferingConstants.COURSEOFFERING_MSG_ERROR_FOUND_MORE_THAN_ONE_TERM, termCode);
137 theForm.getCourseOfferingEditWrapperList().clear();
138 return getUIFModelAndView(theForm);
139 } else{
140 LOG.error("Error: Can't find any Term for term code: "+termCode);
141 GlobalVariables.getMessageMap().putError("termCode", CourseOfferingConstants.COURSEOFFERING_MSG_ERROR_NO_TERM_IS_FOUND, termCode);
142 theForm.getCourseOfferingEditWrapperList().clear();
143 return getUIFModelAndView(theForm);
144 }
145
146
147 if (theForm.getRadioSelection().equals("subjectCode")){
148
149
150 theForm.setSubjectCode(theForm.getInputCode());
151 theForm.setSubjectCodeDescription("");
152 getViewHelperService(theForm).loadCourseOfferingsByTermAndSubjectCode(theForm.getTermInfo().getId(), theForm.getInputCode(),theForm);
153 if(!theForm.getCourseOfferingEditWrapperList().isEmpty()) {
154 theForm.setSubjectCode(theForm.getCourseOfferingEditWrapperList().get(0).getCoInfo().getSubjectArea());
155 String longNameDescr = getOrgNameDescription(theForm.getSubjectCode());
156 theForm.setSubjectCodeDescription(longNameDescr);
157 }
158
159 return getUIFModelAndView(theForm, CourseOfferingConstants.MANAGE_CO_PAGE);
160
161 } else {
162
163 String courseOfferingCode = theForm.getInputCode();
164 theForm.setCourseOfferingCode(courseOfferingCode);
165
166 List<CourseOfferingInfo> courseOfferingList = getViewHelperService(theForm).findCourseOfferingsByTermAndCourseOfferingCode(termCode, courseOfferingCode, theForm);
167
168 if (!courseOfferingList.isEmpty() && courseOfferingList.size() == 1 ) {
169
170 CourseOfferingInfo coToShow = courseOfferingList.get(0);
171
172 return prepareManageAOsModelAndView(theForm, coToShow);
173
174 } else if (courseOfferingList.size()>1) {
175
176 LOG.error("Error: Found more than one Course Offering for a Course Offering Code: "+courseOfferingCode+" in term: "+termCode);
177
178 GlobalVariables.getMessageMap().putError("inputCode", CourseOfferingConstants.COURSEOFFERING_MSG_ERROR_FOUND_MORE_THAN_ONE_COURSE_OFFERING, courseOfferingCode, termCode);
179 theForm.getCourseOfferingEditWrapperList().clear();
180 theForm.setActivityWrapperList(null);
181
182 return getUIFModelAndView(theForm);
183
184 } else {
185
186 LOG.error("Error: Can't find any Course Offering for a Course Offering Code: "+courseOfferingCode+" in term: "+termCode);
187
188 GlobalVariables.getMessageMap().putError("inputCode", CourseOfferingConstants.COURSEOFFERING_MSG_ERROR_NO_COURSE_OFFERING_IS_FOUND, "Course Offering", courseOfferingCode, termCode);
189 theForm.getCourseOfferingEditWrapperList().clear();
190 theForm.setActivityWrapperList(null);
191
192 return getUIFModelAndView(theForm);
193 }
194 }
195 }
196
197 private ModelAndView prepareManageAOsModelAndView(CourseOfferingManagementForm theForm, CourseOfferingInfo coToShow) throws Exception {
198 CourseOfferingEditWrapper wrapper = new CourseOfferingEditWrapper(coToShow);
199
200 theForm.getCourseOfferingEditWrapperList().clear();
201 theForm.getCourseOfferingEditWrapperList().add(wrapper);
202 theForm.setTheCourseOffering(coToShow);
203 theForm.setFormatIdForNewAO(null);
204 theForm.setActivityIdForNewAO(null);
205 theForm.setNoOfActivityOfferings(null);
206 getViewHelperService(theForm).loadActivityOfferingsByCourseOffering(coToShow, theForm);
207 getViewHelperService(theForm).loadPreviousAndNextCourseOffering(theForm, coToShow);
208
209 return getUIFModelAndView(theForm, CourseOfferingConstants.MANAGE_AO_PAGE);
210 }
211
212 @RequestMapping(params = "methodToCall=manageRegGroups")
213 public ModelAndView manageRegGroups(@ModelAttribute("KualiForm") CourseOfferingManagementForm theForm, BindingResult result,
214 HttpServletRequest request, HttpServletResponse response) throws Exception {
215 String courseOfferingId = theForm.getTheCourseOffering().getId();
216 List<FormatOfferingInfo> formatOfferingList =
217 getCourseOfferingService().getFormatOfferingsByCourseOffering(courseOfferingId, getContextInfo());
218 theForm.setFormatOfferingName(formatOfferingList.get(0).getName());
219 theForm.setFormatOfferingIdForViewRG(formatOfferingList.get(0).getId());
220 List<ActivityOfferingWrapper> filteredAOs = getAOsForSelectedFO(formatOfferingList.get(0).getId(), theForm);
221 theForm.setFilteredAOsForSelectedFO(filteredAOs);
222
223
224 List<RegistrationGroupInfo> rgInfos = getCourseOfferingService().getRegistrationGroupsByFormatOffering(formatOfferingList.get(0).getId(), getContextInfo());
225 List<RegistrationGroupWrapper> filteredRGs = getRGsForSelectedFO(rgInfos, filteredAOs);
226 theForm.setFilteredRGsForSelectedFO(filteredRGs);
227 if(rgInfos != null && rgInfos.size()>0) {
228
229
230
231
232 getViewHelperService(theForm).validateRegistrationGroupsForFormatOffering(rgInfos, theForm.getFormatOfferingIdForViewRG(), theForm);
233 }
234 return getUIFModelAndView(theForm, CourseOfferingConstants.REG_GROUP_PAGE);
235
236 }
237
238 @RequestMapping(params = "methodToCall=filterAOsAndRGsPerFO")
239 public ModelAndView filterAOsAndRGsPerFO (@ModelAttribute("KualiForm") CourseOfferingManagementForm theForm, BindingResult result,
240 HttpServletRequest request, HttpServletResponse response) throws Exception {
241
242 List<ActivityOfferingWrapper> filteredAOs = getAOsForSelectedFO(theForm.getFormatOfferingIdForViewRG(), theForm);
243 theForm.setFilteredAOsForSelectedFO(filteredAOs);
244 if(!filteredAOs.isEmpty()){
245 theForm.setFormatOfferingName(filteredAOs.get(0).getFormatOffering().getName());
246 }
247
248
249 List<RegistrationGroupInfo> rgInfos = getCourseOfferingService().getRegistrationGroupsByFormatOffering(theForm.getFormatOfferingIdForViewRG(), getContextInfo());
250 List<RegistrationGroupWrapper> filteredRGs = getRGsForSelectedFO(rgInfos, filteredAOs);
251 theForm.setFilteredRGsForSelectedFO(filteredRGs);
252 if(rgInfos != null && rgInfos.size()>0) {
253 getViewHelperService(theForm).validateRegistrationGroupsForFormatOffering(rgInfos, theForm.getFormatOfferingIdForViewRG(), theForm);
254 }
255
256 return getUIFModelAndView(theForm, CourseOfferingConstants.REG_GROUP_PAGE);
257
258 }
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286 @RequestMapping(params = "methodToCall=generateUnconstrainedRegGroups")
287 public ModelAndView generateUnconstrainedRegGroups (@ModelAttribute("KualiForm") CourseOfferingManagementForm theForm, BindingResult result,
288 HttpServletRequest request, HttpServletResponse response) throws Exception {
289 List<RegistrationGroupInfo> rgInfos = getCourseOfferingService().generateRegistrationGroupsForFormatOffering(theForm.getFormatOfferingIdForViewRG(), getContextInfo());
290 List<ActivityOfferingWrapper> filteredAOs = theForm.getFilteredAOsForSelectedFO();
291 List<RegistrationGroupWrapper> filteredRGs = getRGsForSelectedFO(rgInfos, filteredAOs);
292 theForm.setFilteredRGsForSelectedFO(filteredRGs);
293
294 return getUIFModelAndView(theForm, CourseOfferingConstants.REG_GROUP_PAGE);
295 }
296
297 @RequestMapping(params = "methodToCall=loadPreviousCO")
298 public ModelAndView loadPreviousCO(@ModelAttribute("KualiForm") CourseOfferingManagementForm theForm, BindingResult result,
299 HttpServletRequest request, HttpServletResponse response) throws Exception {
300
301 CourseOfferingEditWrapper wrapper = new CourseOfferingEditWrapper(theForm.getPreviousCourseOffering());
302
303 theForm.getCourseOfferingEditWrapperList().clear();
304 theForm.getCourseOfferingEditWrapperList().add(wrapper);
305 theForm.setTheCourseOffering(theForm.getPreviousCourseOffering());
306 theForm.setInputCode(wrapper.getCoInfo().getCourseOfferingCode());
307
308 getViewHelperService(theForm).loadActivityOfferingsByCourseOffering(theForm.getPreviousCourseOffering(), theForm);
309 getViewHelperService(theForm).loadPreviousAndNextCourseOffering(theForm,theForm.getPreviousCourseOffering());
310
311 return getUIFModelAndView(theForm);
312 }
313
314 @RequestMapping(params = "methodToCall=loadNextCO")
315 public ModelAndView loadNextCO(@ModelAttribute("KualiForm") CourseOfferingManagementForm theForm, BindingResult result,
316 HttpServletRequest request, HttpServletResponse response) throws Exception {
317
318 CourseOfferingEditWrapper wrapper = new CourseOfferingEditWrapper(theForm.getNextCourseOffering());
319
320 theForm.getCourseOfferingEditWrapperList().clear();
321 theForm.getCourseOfferingEditWrapperList().add(wrapper);
322 theForm.setTheCourseOffering(theForm.getNextCourseOffering());
323 theForm.setInputCode(wrapper.getCoInfo().getCourseOfferingCode());
324
325 getViewHelperService(theForm).loadActivityOfferingsByCourseOffering(theForm.getNextCourseOffering(), theForm);
326 getViewHelperService(theForm).loadPreviousAndNextCourseOffering(theForm,theForm.getNextCourseOffering());
327
328 return getUIFModelAndView(theForm);
329 }
330
331 @RequestMapping(params = "methodToCall=loadAOs")
332 public ModelAndView loadAOs(@ModelAttribute("KualiForm") CourseOfferingManagementForm theForm, BindingResult result,
333 HttpServletRequest request, HttpServletResponse response) throws Exception {
334 Object selectedObject = _getSelectedObject(theForm, "Manage");
335 if(selectedObject instanceof CourseOfferingEditWrapper){
336 CourseOfferingEditWrapper coWrapper = (CourseOfferingEditWrapper)selectedObject;
337 CourseOfferingInfo theCourseOffering = coWrapper.getCoInfo();
338
339 theForm.setCourseOfferingCode(theCourseOffering.getCourseOfferingCode());
340 theForm.setInputCode(theCourseOffering.getCourseOfferingCode());
341 theForm.setRadioSelection(CourseOfferingConstants.COURSEOFFERING_COURSE_OFFERING_CODE);
342
343 return prepareManageAOsModelAndView(theForm, theCourseOffering);
344 }
345 else{
346
347 return getUIFModelAndView(theForm, CourseOfferingConstants.MANAGE_CO_PAGE);
348 }
349 }
350
351 @RequestMapping(params = "methodToCall=copyCourseOfferingCreateCopy")
352 public ModelAndView copyCourseOfferingCreateCopy(
353 @ModelAttribute("KualiForm") CourseOfferingManagementForm theForm,
354 BindingResult result,
355 HttpServletRequest request,
356 HttpServletResponse response) throws Exception {
357
358 CourseOfferingCopyWrapper copyWrapper = theForm.getCourseOfferingCopyWrapper();
359 CourseOfferingInfo courseOfferingInfo = copyWrapper.getCoInfo();
360 List<String> optionKeys = new ArrayList<String>();
361
362 if (copyWrapper.isExcludeSchedulingInformation()) {
363 optionKeys.add(CourseOfferingSetServiceConstants.NO_SCHEDULE_OPTION_KEY);
364 }
365 if (copyWrapper.isExcludeInstructorInformation()) {
366 optionKeys.add(CourseOfferingSetServiceConstants.NO_INSTRUCTORS_OPTION_KEY);
367 }
368 if (copyWrapper.isExcludeCancelledActivityOfferings()) {
369 optionKeys.add(CourseOfferingSetServiceConstants.IGNORE_CANCELLED_AO_OPTION_KEY);
370 }
371
372 optionKeys.add(CourseOfferingServiceConstants.APPEND_COURSE_OFFERING_IN_SUFFIX_OPTION_KEY);
373
374 CourseOfferingInfo courseOffering =
375 getCourseOfferingService().rolloverCourseOffering(
376 courseOfferingInfo.getId(), copyWrapper.getTermId(), optionKeys, getContextInfo());
377 ExistingCourseOffering newWrapper = new ExistingCourseOffering(courseOffering);
378 CourseInfo course = getCourseInfo(copyWrapper.getCourseOfferingCode());
379 newWrapper.setCredits(ViewHelperUtil.getCreditCount(courseOffering, course));
380 newWrapper.setGrading(getGradingOption(courseOffering.getGradingOptionId()));
381 copyWrapper.getExistingOfferingsInCurrentTerm().add(newWrapper);
382 return getUIFModelAndView(theForm, CourseOfferingConstants.MANAGE_CO_PAGE);
383 }
384
385 private TermInfo getTerm(String termCode){
386 QueryByCriteria.Builder qBuilder = QueryByCriteria.Builder.create();
387 List<Predicate> pList = new ArrayList<Predicate>();
388 Predicate p = null;
389
390 qBuilder.setPredicates();
391 if (StringUtils.isNotBlank(termCode)){
392 p = equal("atpCode", termCode);
393 pList.add(p);
394 }
395
396 qBuilder.setPredicates(p);
397
398 try {
399 List<TermInfo> terms = getAcademicCalendarService().searchForTerms(qBuilder.build(),getContextInfo());
400 if (terms.size() > 1){
401
402 return null;
403 }else if (terms.isEmpty()){
404 return null;
405 }
406 return terms.get(0);
407 } catch (Exception e) {
408 throw new RuntimeException(e);
409 }
410
411 }
412
413 private CourseInfo getCourseInfo(String courseName) {
414
415 CourseInfo returnCourseInfo = null;
416 String courseId = null;
417 List<SearchParam> searchParams = new ArrayList<SearchParam>();
418 List <CourseInfo> courseInfoList = new ArrayList<CourseInfo>();
419
420 SearchParam qpv1 = new SearchParam();
421 qpv1.setKey("lu.criteria.code");
422 qpv1.setValue(courseName);
423 searchParams.add(qpv1);
424
425 SearchRequest searchRequest = new SearchRequest();
426 searchRequest.setParams(searchParams);
427 searchRequest.setSearchKey("lu.search.cluByCode");
428
429 try {
430 SearchResult searchResult = getCluService().search(searchRequest);
431 if (searchResult.getRows().size() > 0) {
432 for(SearchResultRow row : searchResult.getRows()){
433 List<SearchResultCell> srCells = row.getCells();
434 if(srCells != null && srCells.size() > 0){
435 for(SearchResultCell cell : srCells){
436 if ("lu.resultColumn.cluId".equals(cell.getKey())) {
437 courseId = cell.getValue();
438 returnCourseInfo = getCourseService().getCourse(courseId, ContextUtils.getContextInfo());
439 courseInfoList.add(returnCourseInfo);
440 }
441 }
442 }
443 }
444 }
445 } catch (Exception e) {
446 throw new RuntimeException(e);
447 }
448
449 if (courseInfoList.size() > 1){
450 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_CUSTOM, "Multiple matches found for the course code");
451 return null;
452 }
453
454 if (courseInfoList.isEmpty()){
455 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, RiceKeyConstants.ERROR_CUSTOM, "No match found for the course code");
456 return null;
457 }
458
459 return courseInfoList.get(0);
460
461 }
462
463 private String getGradingOption(String gradingOptionId)throws Exception{
464 String gradingOption = "";
465 if(StringUtils.isNotBlank(gradingOptionId)){
466 ResultValuesGroupInfo rvg = getLrcService().getResultValuesGroup(gradingOptionId, getContextInfo());
467 if(rvg!= null && StringUtils.isNotBlank(rvg.getName())){
468 gradingOption = rvg.getName();
469 }
470 }
471
472 return gradingOption;
473 }
474
475 private List<ActivityOfferingWrapper> getAOsForSelectedFO(String theFOId, CourseOfferingManagementForm theForm) {
476 List<ActivityOfferingWrapper> fullAOs = theForm.getActivityWrapperList();
477 List<ActivityOfferingWrapper> filterdAOList = theForm.getFilteredAOsForSelectedFO();
478 filterdAOList.clear();
479
480 for (ActivityOfferingWrapper ao: fullAOs) {
481 String formatOfferingId =ao.getAoInfo().getFormatOfferingId();
482 if (formatOfferingId.equals(theFOId) ){
483 filterdAOList.add(ao);
484 }
485 }
486 return filterdAOList;
487 }
488
489 private List<RegistrationGroupWrapper> getRGsForSelectedFO(List<RegistrationGroupInfo> rgInfos, List<ActivityOfferingWrapper> filteredAOs) {
490
491 List<RegistrationGroupWrapper> filterdRGList = new ArrayList<RegistrationGroupWrapper>();
492
493 HashMap<String, ActivityOfferingWrapper> filteredAOsHM = new HashMap<String, ActivityOfferingWrapper>();
494 for (ActivityOfferingWrapper wrapper : filteredAOs) {
495 filteredAOsHM.put(wrapper.getAoInfo().getId(), wrapper);
496 }
497
498 for (RegistrationGroupInfo rgInfo : rgInfos) {
499 RegistrationGroupWrapper rgWrapper = new RegistrationGroupWrapper();
500 rgWrapper.setRgInfo(rgInfo);
501 String aoActivityCodeText = "", aoStateNameText = "", aoTypeNameText = "", aoInstructorText = "", aoMaxEnrText = "";
502 for (String aoID : rgInfo.getActivityOfferingIds()) {
503 if (filteredAOsHM.get(aoID).getAoInfo().getActivityCode() != null && !filteredAOsHM.get(aoID).getAoInfo().getActivityCode().equalsIgnoreCase("")) {
504 aoActivityCodeText = aoActivityCodeText + filteredAOsHM.get(aoID).getAoInfo().getActivityCode() + "<br/>";
505 }
506 if (filteredAOsHM.get(aoID).getStateName() != null && !filteredAOsHM.get(aoID).getStateName().equalsIgnoreCase("")) {
507 aoStateNameText = aoStateNameText + filteredAOsHM.get(aoID).getStateName() + "<br/>";
508 }
509 if (filteredAOsHM.get(aoID).getTypeName() != null && !filteredAOsHM.get(aoID).getTypeName().equalsIgnoreCase("")) {
510 aoTypeNameText = aoTypeNameText + filteredAOsHM.get(aoID).getTypeName() + "<br/>";
511 }
512 if (filteredAOsHM.get(aoID).getFirstInstructorDisplayName() != null && !filteredAOsHM.get(aoID).getFirstInstructorDisplayName().equalsIgnoreCase("")) {
513 aoInstructorText = aoInstructorText + filteredAOsHM.get(aoID).getFirstInstructorDisplayName() + "<br/>";
514 }
515 if (filteredAOsHM.get(aoID).getAoInfo().getMaximumEnrollment() != null) {
516 aoMaxEnrText = aoMaxEnrText + Integer.toString(filteredAOsHM.get(aoID).getAoInfo().getMaximumEnrollment()) + "<br/>";
517 }
518 }
519 if (aoActivityCodeText.length() > 0) {
520 aoActivityCodeText = aoActivityCodeText.substring(0, aoActivityCodeText.lastIndexOf("<br/>"));
521 }
522 if (aoStateNameText.length() > 0) {
523 aoStateNameText = aoStateNameText.substring(0, aoStateNameText.lastIndexOf("<br/>"));
524 }
525 if (aoTypeNameText.length() > 0) {
526 aoTypeNameText = aoTypeNameText.substring(0, aoTypeNameText.lastIndexOf("<br/>"));
527 }
528 if (aoInstructorText.length() > 0) {
529 aoInstructorText = aoInstructorText.substring(0, aoInstructorText.lastIndexOf("<br/>"));
530 }
531 if (aoMaxEnrText.length() > 0) {
532 aoMaxEnrText = aoMaxEnrText.substring(0, aoMaxEnrText.lastIndexOf("<br/>"));
533 }
534
535 rgWrapper.setAoActivityCodeText(aoActivityCodeText);
536 rgWrapper.setAoStateNameText(aoStateNameText);
537 rgWrapper.setAoTypeNameText(aoTypeNameText);
538 rgWrapper.setAoInstructorText(aoInstructorText);
539 rgWrapper.setAoMaxEnrText(aoMaxEnrText);
540 filterdRGList.add(rgWrapper);
541 }
542
543 return filterdRGList;
544 }
545
546 protected AcademicCalendarService getAcademicCalendarService() {
547 if(academicCalendarService == null) {
548 academicCalendarService = (AcademicCalendarService) GlobalResourceLoader.getService(new QName(AcademicCalendarServiceConstants.NAMESPACE, AcademicCalendarServiceConstants.SERVICE_NAME_LOCAL_PART));
549 }
550 return this.academicCalendarService;
551 }
552
553 private CluService getCluService() {
554 if(luService == null) {
555 luService = CourseOfferingResourceLoader.loadCluService();
556 }
557 return luService;
558 }
559
560 protected LRCService getLrcService() {
561 if(lrcService == null) {
562 lrcService = CourseOfferingResourceLoader.loadLrcService();
563 }
564 return this.lrcService;
565 }
566
567 private CourseService getCourseService() {
568 if(courseService == null) {
569 courseService = CourseOfferingResourceLoader.loadCourseService();
570 }
571 return courseService;
572 }
573
574 @RequestMapping(params = "methodToCall=copyCourseOfferingCancel")
575 public ModelAndView copyCourseOfferingCancel(
576 @ModelAttribute("KualiForm") CourseOfferingManagementForm theForm,
577 BindingResult result,
578 HttpServletRequest request,
579 HttpServletResponse response) throws Exception {
580 return getUIFModelAndView(theForm, CourseOfferingConstants.MANAGE_CO_PAGE);
581 }
582
583 @RequestMapping(params = "methodToCall=copyCourseOffering")
584 public ModelAndView copyCourseOffering(
585 @ModelAttribute("KualiForm") CourseOfferingManagementForm theForm,
586 BindingResult result,
587 HttpServletRequest request,
588 HttpServletResponse response) throws Exception {
589 Object selectedObject = _getSelectedObject(theForm, "Copy");
590 if(selectedObject instanceof CourseOfferingEditWrapper){
591
592
593 CourseOfferingEditWrapper courseOfferingEditWrapper = (CourseOfferingEditWrapper)selectedObject;
594 CourseOfferingInfo courseOfferingInfo = courseOfferingEditWrapper.getCoInfo();
595
596
597 getViewHelperService(theForm).loadActivityOfferingsByCourseOffering(courseOfferingInfo, theForm);
598
599
600 CourseOfferingCopyWrapper coCopyWrapper = new CourseOfferingCopyWrapper();
601
602
603 coCopyWrapper.setCoInfo(courseOfferingInfo);
604 coCopyWrapper.setCourseOfferingCode(courseOfferingInfo.getCourseOfferingCode());
605 coCopyWrapper.setCourseTitle(courseOfferingInfo.getCourseOfferingTitle());
606 coCopyWrapper.setTermId(courseOfferingInfo.getTermId());
607 coCopyWrapper.setCreditCount(courseOfferingInfo.getCreditCnt());
608 coCopyWrapper.setGradingOption(courseOfferingInfo.getGradingOption());
609 coCopyWrapper.setStudentRegistrationGradingOptionsList(courseOfferingInfo.getStudentRegistrationGradingOptions());
610 coCopyWrapper.setFinalExamType(courseOfferingInfo.getFinalExamType());
611 coCopyWrapper.setWaitlistLevelTypeKey(courseOfferingInfo.getWaitlistLevelTypeKey());
612 coCopyWrapper.setWaitlistTypeKey(courseOfferingInfo.getWaitlistTypeKey());
613 coCopyWrapper.setIsHonors(courseOfferingInfo.getIsHonorsOffering());
614 coCopyWrapper.setActivityOfferingWrapperList(theForm.getActivityWrapperList());
615
616
617 theForm.setCourseOfferingCopyWrapper(coCopyWrapper);
618 } else {
619 theForm.setCourseOfferingCopyWrapper(null);
620 }
621 return getUIFModelAndView(theForm, CourseOfferingConstants.COPY_CO_PAGE);
622 }
623
624
625 @RequestMapping(params = "methodToCall=selectAllActivityOfferings")
626 public ModelAndView selectAllActivityOfferings(
627 @ModelAttribute("KualiForm")
628 CourseOfferingManagementForm theForm,
629 BindingResult result,
630 HttpServletRequest request,
631 HttpServletResponse response) throws Exception {
632 List<ActivityOfferingWrapper> list = theForm.getActivityWrapperList();
633 for (ActivityOfferingWrapper listElement : list) {
634 listElement.setIsChecked(true);
635 }
636 return getUIFModelAndView(theForm);
637 }
638
639
640 @RequestMapping(params = "methodToCall=loadCOs")
641 public ModelAndView loadCOs(@ModelAttribute("KualiForm") CourseOfferingManagementForm theForm, BindingResult result,
642 HttpServletRequest request, HttpServletResponse response) throws Exception {
643 CourseOfferingInfo theCourseOffering = theForm.getTheCourseOffering();
644 String subjectCode = theCourseOffering.getSubjectArea();
645 String termId = theForm.getTermInfo().getId();
646 theForm.setRadioSelection("subjectCode");
647 theForm.setInputCode(subjectCode);
648 getViewHelperService(theForm).loadCourseOfferingsByTermAndSubjectCode(termId, subjectCode, theForm);
649 return getUIFModelAndView(theForm, CourseOfferingConstants.MANAGE_CO_PAGE);
650 }
651
652
653
654
655 @RequestMapping(params = "methodToCall=copyAO")
656 public ModelAndView copyAO( @ModelAttribute("KualiForm") CourseOfferingManagementForm form, BindingResult result,
657 HttpServletRequest request, HttpServletResponse response) {
658 ActivityOfferingWrapper selectedAO = (ActivityOfferingWrapper)_getSelectedObject(form, "copy");
659 try{
660 CourseOfferingResourceLoader.loadCourseOfferingService().copyActivityOffering(selectedAO.getAoInfo().getId(), ContextBuilder.loadContextInfo());
661
662
663 getViewHelperService(form).loadActivityOfferingsByCourseOffering(form.getTheCourseOffering(), form);
664 }catch (Exception e){
665 throw new RuntimeException(e);
666 }
667
668 return getUIFModelAndView(form);
669 }
670
671
672
673
674 @RequestMapping(params = "methodToCall=cancelDeleteAOs")
675 public ModelAndView cancelDeleteAOs(@ModelAttribute("KualiForm") CourseOfferingManagementForm theForm, BindingResult result,
676 HttpServletRequest request, HttpServletResponse response) throws Exception {
677 getViewHelperService(theForm).loadActivityOfferingsByCourseOffering(theForm.getTheCourseOffering(), theForm);
678 return getUIFModelAndView(theForm, CourseOfferingConstants.MANAGE_AO_PAGE);
679 }
680
681
682
683
684
685 @RequestMapping(params = "methodToCall=deleteSelectedAoList")
686 public ModelAndView deleteSelectedAoList(@ModelAttribute("KualiForm") CourseOfferingManagementForm theForm, BindingResult result,
687 HttpServletRequest request, HttpServletResponse response) throws Exception {
688
689 List<ActivityOfferingWrapper> selectedAolist = theForm.getSelectedToDeleteList();
690
691 try{
692 for(ActivityOfferingWrapper ao : selectedAolist) {
693 CourseOfferingResourceLoader.loadCourseOfferingService().deleteActivityOfferingCascaded(ao.getAoInfo().getId(), ContextBuilder.loadContextInfo());
694 }
695 } catch (Exception e) {
696 throw new RuntimeException(e);
697 }
698
699 getViewHelperService(theForm).loadActivityOfferingsByCourseOffering(theForm.getTheCourseOffering(), theForm);
700 if(selectedAolist.size() > 0) {
701 GlobalVariables.getMessageMap().putWarningForSectionId("manageActivityOfferingsPage",
702 CourseOfferingConstants.COURSEOFFERING_MSG_ERROR_SELECTED_AO_TO_DELETE);
703 }
704
705 return getUIFModelAndView(theForm, CourseOfferingConstants.MANAGE_AO_PAGE);
706
707 }
708
709
710
711
712 @RequestMapping(params = "methodToCall=deleteCoConfirmation")
713 public ModelAndView deleteCoConfirmation(@ModelAttribute("KualiForm") CourseOfferingManagementForm theForm, BindingResult result,
714 HttpServletRequest request, HttpServletResponse response) throws Exception {
715
716 CourseOfferingInfo theCourseOffering = null;
717
718 String selectedCollectionPath = theForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
719 if (!StringUtils.isBlank(selectedCollectionPath)) {
720 Object selectedObject = _getSelectedObject(theForm, "deleteCo");
721 theCourseOffering = ((CourseOfferingEditWrapper) selectedObject).getCoInfo();
722 theForm.setTheCourseOffering(theCourseOffering);
723
724 try {
725 getViewHelperService(theForm).loadActivityOfferingsByCourseOffering(theCourseOffering, theForm);
726 } catch (Exception e) {
727 e.printStackTrace();
728 throw new RuntimeException(e);
729 }
730 }
731
732 if(theCourseOffering == null) {
733 theCourseOffering = theForm.getTheCourseOffering();
734 }
735 if(theCourseOffering == null) {
736 throw new RuntimeException("No Course Offering selected!");
737 }
738
739 String termId = theCourseOffering.getTermId();
740 String subjectCode = theCourseOffering.getSubjectArea();
741 theForm.setCourseOfferingCode(theCourseOffering.getCourseOfferingCode());
742
743
744 if (theForm.getActivityWrapperList().isEmpty()) {
745 try {
746 getViewHelperService(theForm).loadActivityOfferingsByCourseOffering(theCourseOffering, theForm);
747 } catch (Exception e) {
748 e.printStackTrace();
749 throw new RuntimeException(e);
750 }
751
752 }
753 for (ActivityOfferingWrapper ao : theForm.getActivityWrapperList()) {
754
755 if (!ao.isLegalToDelete()) {
756 LOG.error("Error: Course Offering cannot be deleted.");
757 GlobalVariables.getMessageMap().putErrorForSectionId("KS-CourseOfferingManagement-CourseOfferingListSection",
758 CourseOfferingConstants.COURSEOFFERING_MSG_ERROR_CO_CANNOT_DELETE);
759 return getUIFModelAndView(theForm, CourseOfferingConstants.MANAGE_CO_PAGE);
760 }
761 }
762
763 return getUIFModelAndView(theForm, CourseOfferingConstants.CO_DELETE_CONFIRM_PAGE);
764 }
765
766
767
768
769 @RequestMapping(params = "methodToCall=deleteCo")
770 public ModelAndView deleteCo(@ModelAttribute("KualiForm") CourseOfferingManagementForm theForm, BindingResult result,
771 HttpServletRequest request, HttpServletResponse response) {
772 CourseOfferingInfo theCourseOffering = theForm.getTheCourseOffering();
773 if(theCourseOffering == null) {
774 throw new RuntimeException("No Course Offering selected!");
775 }
776
777 String termId = theCourseOffering.getTermId();
778 String subjectCode = theCourseOffering.getSubjectArea();
779
780 if (theForm.getActivityWrapperList().isEmpty()) {
781 try {
782 getViewHelperService(theForm).loadActivityOfferingsByCourseOffering(theCourseOffering, theForm);
783 } catch (Exception e) {
784 e.printStackTrace();
785 throw new RuntimeException(e);
786 }
787
788 }
789 try {
790 for (ActivityOfferingWrapper ao : theForm.getActivityWrapperList()) {
791
792 if (!ao.isLegalToDelete()) {
793 LOG.error("Error: Course Offering cannot be deleted.");
794 GlobalVariables.getMessageMap().putErrorForSectionId("KS-CourseOfferingManagement-CourseOfferingListSection",
795 CourseOfferingConstants.COURSEOFFERING_MSG_ERROR_CO_CANNOT_DELETE);
796 return getUIFModelAndView(theForm, CourseOfferingConstants.MANAGE_CO_PAGE);
797 }
798 }
799 CourseOfferingResourceLoader.loadCourseOfferingService().deleteCourseOfferingCascaded(theCourseOffering.getId(), ContextBuilder.loadContextInfo());
800
801 getViewHelperService(theForm).loadCourseOfferingsByTermAndSubjectCode(termId, subjectCode, theForm);
802
803 } catch (Exception e) {
804 throw new RuntimeException(e);
805 }
806
807 return getUIFModelAndView(theForm, CourseOfferingConstants.MANAGE_CO_PAGE);
808 }
809
810
811
812
813 @RequestMapping(params = "methodToCall=cancelDeleteCo")
814 public ModelAndView cancelDeleteCo(@ModelAttribute("KualiForm") CourseOfferingManagementForm theForm, BindingResult result,
815 HttpServletRequest request, HttpServletResponse response) {
816 CourseOfferingInfo theCourseOffering = theForm.getTheCourseOffering();
817 if(theCourseOffering == null) {
818 throw new RuntimeException("No Course Offering selected!");
819 }
820
821 String termId = theCourseOffering.getTermId();
822 String subjectCode = theCourseOffering.getSubjectArea();
823
824 if (theForm.getActivityWrapperList().isEmpty()) {
825 try {
826 getViewHelperService(theForm).loadActivityOfferingsByCourseOffering(theCourseOffering, theForm);
827 } catch (Exception e) {
828 e.printStackTrace();
829 throw new RuntimeException(e);
830 }
831
832 }
833
834 try {
835 getViewHelperService(theForm).loadCourseOfferingsByTermAndSubjectCode(termId, subjectCode, theForm);
836 } catch (Exception e) {
837 e.printStackTrace();
838 }
839
840 return getUIFModelAndView(theForm, CourseOfferingConstants.MANAGE_CO_PAGE);
841 }
842
843
844
845
846 @RequestMapping(params = "methodToCall=edit")
847 public ModelAndView edit(@ModelAttribute("KualiForm") CourseOfferingManagementForm theForm, BindingResult result,
848 HttpServletRequest request, HttpServletResponse response) throws Exception {
849
850 Properties urlParameters = new Properties();
851 Object selectedObject = _getSelectedObject(theForm, "edit");
852
853 if(selectedObject instanceof CourseOfferingEditWrapper){
854
855 CourseOfferingInfo courseOfferingInfo = ((CourseOfferingEditWrapper) selectedObject).getCoInfo();
856 urlParameters = _buildCOURLParameters(courseOfferingInfo,KRADConstants.Maintenance.METHOD_TO_CALL_EDIT,false,getContextInfo());
857
858 }else if(selectedObject instanceof ActivityOfferingWrapper) {
859
860 ActivityOfferingWrapper aoWrapper = (ActivityOfferingWrapper)selectedObject;
861
862 urlParameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.Maintenance.METHOD_TO_CALL_EDIT);
863 urlParameters.put(ActivityOfferingConstants.ACTIVITY_OFFERING_WRAPPER_ID, aoWrapper.getAoInfo().getId());
864 urlParameters.put(ActivityOfferingConstants.ACTIVITYOFFERING_COURSE_OFFERING_ID, theForm.getTheCourseOffering().getId());
865 urlParameters.put(KRADConstants.DATA_OBJECT_CLASS_ATTRIBUTE, ActivityOfferingWrapper.class.getName());
866 urlParameters.put(UifConstants.UrlParams.SHOW_HOME, BooleanUtils.toStringTrueFalse(false));
867
868 } else {
869 throw new RuntimeException("Invalid type. Does not support for now");
870 }
871
872 return super.performRedirect(theForm, KRADConstants.Maintenance.REQUEST_MAPPING_MAINTENANCE, urlParameters);
873
874 }
875
876
877
878
879 @RequestMapping(params = "methodToCall=selectedAoActions")
880 public ModelAndView selectedAoActions(@ModelAttribute("KualiForm") CourseOfferingManagementForm theForm, BindingResult result,
881 HttpServletRequest request, HttpServletResponse response) throws Exception {
882
883 if (StringUtils.equals(theForm.getSelectedOfferingAction(), CourseOfferingConstants.ACTIVITY_OFFERING_DELETE_ACTION)){
884 return confirmDelete(theForm, result, request, response);
885 }
886
887 if (StringUtils.equals(theForm.getSelectedOfferingAction(), CourseOfferingConstants.ACTIVITY_OFFERING_DRAFT_ACTION) ||
888 StringUtils.equals(theForm.getSelectedOfferingAction(), CourseOfferingConstants.ACTIVITY_OFFERING_SCHEDULING_ACTION)) {
889 getViewHelperService(theForm).changeActivityOfferingsState(theForm.getActivityWrapperList(), theForm.getSelectedOfferingAction());
890 }
891
892
893 CourseOfferingInfo theCourseOffering = theForm.getTheCourseOffering();
894 getViewHelperService(theForm).loadActivityOfferingsByCourseOffering(theCourseOffering, theForm);
895 getViewHelperService(theForm).loadPreviousAndNextCourseOffering(theForm, theCourseOffering);
896
897 return getUIFModelAndView(theForm, CourseOfferingConstants.MANAGE_AO_PAGE);
898 }
899
900 @RequestMapping(params = "methodToCall=selectedCOActions")
901 public ModelAndView selectedCOActions(@ModelAttribute("KualiForm") CourseOfferingManagementForm theForm, BindingResult result,
902 HttpServletRequest request, HttpServletResponse response) throws Exception {
903
904 if (StringUtils.equals(theForm.getSelectedOfferingAction(),CourseOfferingConstants.ACTIVITY_OFFERING_SCHEDULING_ACTION)) {
905
906
907
908
909
910
911
912
913 getViewHelperService(theForm).markCourseOfferingsForScheduling(theForm.getCourseOfferingEditWrapperList());
914 }
915
916 return getUIFModelAndView(theForm);
917
918 }
919
920 private void loadSelectedCOsForScheduling(CourseOfferingManagementForm theForm){
921 String textToDisplay = StringUtils.EMPTY;
922 int count = 1;
923 for (CourseOfferingEditWrapper co : theForm.getCourseOfferingEditWrapperList()) {
924 if (co.getIsChecked()){
925 textToDisplay = textToDisplay + co.getCoInfo().getCourseOfferingCode() + ",";
926 count++;
927 }
928 }
929 theForm.setToBeScheduledCourseOfferingsUI(StringUtils.stripEnd(textToDisplay,","));
930 theForm.setToBeScheduledCourseOfferingsCount(count-1);
931 }
932
933
934
935
936 @RequestMapping(params = "methodToCall=confirmDelete")
937 public ModelAndView confirmDelete(@ModelAttribute("KualiForm") CourseOfferingManagementForm theForm, BindingResult result,
938 HttpServletRequest request, HttpServletResponse response) throws Exception {
939
940 Collection<Object> collection;
941 Object selectedObject;
942 List<ActivityOfferingWrapper> aoList = theForm.getActivityWrapperList();
943 List<ActivityOfferingWrapper> selectedIndexList = theForm.getSelectedToDeleteList();
944 boolean bEncounteredNonDraftAOInDeletion = false;
945 boolean bLegalAOInDeletion = false;
946
947
948 selectedIndexList.clear();
949
950 String selectedCollectionPath = theForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
951 if (StringUtils.isNotBlank(selectedCollectionPath)) {
952
953 int selectedLineIndex = -1;
954 String selectedLine = theForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX);
955 if (StringUtils.isNotBlank(selectedLine)) {
956 selectedLineIndex = Integer.parseInt(selectedLine);
957 }
958
959 if (selectedLineIndex == -1) {
960 throw new RuntimeException("Selected line index was not set");
961 }
962
963 collection = ObjectPropertyUtils.getPropertyValue(theForm, selectedCollectionPath);
964
965 selectedObject = ((List<Object>) collection).get(selectedLineIndex);
966
967 selectedIndexList.add((ActivityOfferingWrapper) selectedObject);
968 }
969 else {
970
971 selectedIndexList.clear();
972 for(ActivityOfferingWrapper ao : aoList) {
973 if(ao.isLegalToDelete() && ao.getIsChecked()) {
974 selectedIndexList.add(ao);
975 bLegalAOInDeletion = true;
976 } else if (ao.getIsChecked()){
977 if (!bEncounteredNonDraftAOInDeletion) {
978 bEncounteredNonDraftAOInDeletion = true;
979 }
980 }
981 }
982 }
983
984 if (selectedIndexList.isEmpty()) {
985 if (bEncounteredNonDraftAOInDeletion) {
986 GlobalVariables.getMessageMap().putError("manageActivityOfferingsPage",
987 CourseOfferingConstants.AO_NOT_DRAFT_FOR_DELETION_ERROR);
988 } else {
989 GlobalVariables.getMessageMap().putError("manageActivityOfferingsPage",
990 CourseOfferingConstants.COURSEOFFERING_MSG_ERROR_FOUND_NO_DRAFT_AO_SELECTED);
991 }
992 return getUIFModelAndView(theForm);
993 }
994
995
996
997
998
999
1000
1001 return getUIFModelAndView(theForm, CourseOfferingConstants.AO_DELETE_CONFIRM_PAGE);
1002 }
1003
1004
1005
1006
1007 @RequestMapping(params = "methodToCall=view")
1008 public ModelAndView view(@ModelAttribute("KualiForm") CourseOfferingManagementForm theForm, BindingResult result,
1009 HttpServletRequest request, HttpServletResponse response) throws Exception {
1010
1011 Properties urlParameters = new Properties();
1012 String controllerPath = "inquiry";
1013 Object selectedObject = _getSelectedObject(theForm, "view");
1014
1015 if(selectedObject instanceof CourseOfferingInfo){
1016 urlParameters = _buildCOURLParameters((CourseOfferingInfo)selectedObject,KRADConstants.START_METHOD,true,getContextInfo());
1017 } else if(selectedObject instanceof ActivityOfferingWrapper) {
1018 ActivityOfferingWrapper aoWrapper = (ActivityOfferingWrapper)selectedObject;
1019 urlParameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.START_METHOD);
1020 urlParameters.put(ActivityOfferingConstants.ACTIVITYOFFERING_ID, aoWrapper.getAoInfo().getId());
1021 urlParameters.put(KRADConstants.DATA_OBJECT_CLASS_ATTRIBUTE, ActivityOfferingInfo.class.getName());
1022 } else {
1023 throw new RuntimeException("Invalid type. Does not support for now");
1024 }
1025
1026 return super.performRedirect(theForm,controllerPath, urlParameters);
1027 }
1028
1029 @RequestMapping(params = "methodToCall=addActivityOfferings")
1030 public ModelAndView addActivityOfferings(@ModelAttribute("KualiForm") CourseOfferingManagementForm theForm, BindingResult result,
1031 HttpServletRequest request, HttpServletResponse response) throws Exception {
1032
1033 String activityId = theForm.getActivityIdForNewAO();
1034 String formatId = theForm.getFormatIdForNewAO();
1035 int aoCount = Integer.parseInt(theForm.getNoOfActivityOfferings());
1036
1037 getViewHelperService(theForm).createActivityOfferings(formatId, activityId, aoCount, theForm);
1038
1039 theForm.setFormatIdForNewAO(null);
1040 theForm.setActivityIdForNewAO(null);
1041 theForm.setNoOfActivityOfferings(null);
1042
1043 return getUIFModelAndView(theForm);
1044
1045 }
1046
1047 @RequestMapping(params = "methodToCall=createCourseOffering")
1048 public ModelAndView createCourseOffering(@ModelAttribute("KualiForm") CourseOfferingManagementForm theForm, BindingResult result,
1049 HttpServletRequest request, HttpServletResponse response) throws Exception {
1050
1051 String termCode = theForm.getTermCode();
1052
1053 Properties props = new Properties();
1054 props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.START_METHOD);
1055 props.put("targetTermCode",termCode);
1056 props.put(KRADConstants.DATA_OBJECT_CLASS_ATTRIBUTE, "org.kuali.student.enrollment.class2.courseoffering.dto.CourseOfferingCreateWrapper");
1057
1058 return super.performRedirect(theForm,"courseOffering", props);
1059 }
1060
1061 @RequestMapping(params = "methodToCall=markSubjectCodeReadyForScheduling")
1062 public ModelAndView markSubjectCodeReadyForScheduling(@ModelAttribute("KualiForm") CourseOfferingManagementForm theForm) throws Exception {
1063 CourseOfferingManagementViewHelperServiceImpl helperService = (CourseOfferingManagementViewHelperServiceImpl) theForm.getView().getViewHelperService();
1064
1065 helperService.markCourseOfferingsForScheduling(theForm.getCourseOfferingEditWrapperList(), false);
1066 return getUIFModelAndView(theForm);
1067 }
1068
1069
1070
1071
1072
1073 @RequestMapping(params = "methodToCall=viewTheCO")
1074 public ModelAndView viewTheCO(@ModelAttribute("KualiForm") CourseOfferingManagementForm theForm, BindingResult result,
1075 HttpServletRequest request, HttpServletResponse response) throws Exception {
1076
1077 CourseOfferingInfo theCourseOfferingInfo = theForm.getTheCourseOffering();
1078 Properties urlParameters = _buildCOURLParameters(theCourseOfferingInfo,KRADConstants.START_METHOD,false,getContextInfo());
1079 String controllerPath = KRADConstants.PARAM_MAINTENANCE_VIEW_MODE_INQUIRY;
1080 return super.performRedirect(theForm,controllerPath, urlParameters);
1081 }
1082
1083
1084
1085
1086
1087 @RequestMapping(params = "methodToCall=editTheCO")
1088 public ModelAndView editTheCO(@ModelAttribute("KualiForm") CourseOfferingManagementForm theForm, BindingResult result,
1089 HttpServletRequest request, HttpServletResponse response) throws Exception {
1090
1091 CourseOfferingInfo theCourseOfferingInfo = theForm.getTheCourseOffering();
1092 Properties urlParameters = _buildCOURLParameters(theCourseOfferingInfo,KRADConstants.Maintenance.METHOD_TO_CALL_EDIT,false,getContextInfo());
1093 String controllerPath = KRADConstants.Maintenance.REQUEST_MAPPING_MAINTENANCE;
1094 return super.performRedirect(theForm,controllerPath, urlParameters);
1095 }
1096
1097 private Properties _buildCOURLParameters(CourseOfferingInfo courseOfferingInfo, String methodToCall, boolean readOnlyView, ContextInfo context){
1098 Properties props = new Properties();
1099 props.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, methodToCall);
1100 props.put("coInfo.id", courseOfferingInfo.getId());
1101 props.put(KRADConstants.DATA_OBJECT_CLASS_ATTRIBUTE, CourseOfferingEditWrapper.class.getName());
1102 props.put(UifConstants.UrlParams.SHOW_HOME, BooleanUtils.toStringTrueFalse(false));
1103 return props;
1104 }
1105
1106 private Object _getSelectedObject(CourseOfferingManagementForm theForm, String actionLink){
1107 String selectedCollectionPath = theForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
1108 if (StringUtils.isBlank(selectedCollectionPath)) {
1109 throw new RuntimeException("Selected collection was not set for " + actionLink);
1110 }
1111
1112 int selectedLineIndex = -1;
1113 String selectedLine = theForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX);
1114 if (StringUtils.isNotBlank(selectedLine)) {
1115 selectedLineIndex = Integer.parseInt(selectedLine);
1116 }
1117
1118 if (selectedLineIndex == -1) {
1119 throw new RuntimeException("Selected line index was not set");
1120 }
1121
1122 Collection<Object> collection = ObjectPropertyUtils.getPropertyValue(theForm, selectedCollectionPath);
1123 Object selectedObject = ((List<Object>) collection).get(selectedLineIndex);
1124
1125 return selectedObject;
1126 }
1127
1128
1129 public String getOrgNameDescription(String orgShortName) {
1130 String shortName = "shortName";
1131 String longName = "";
1132
1133 QueryByCriteria.Builder qBuilder = QueryByCriteria.Builder.create();
1134 if (StringUtils.isNotBlank(orgShortName) && !orgShortName.isEmpty()) {
1135 qBuilder.setPredicates(PredicateFactory.or(
1136 PredicateFactory.equal(shortName, orgShortName)));
1137 } else {
1138 throw new RuntimeException("Org short name is null!");
1139 }
1140 try {
1141 QueryByCriteria query = qBuilder.build();
1142
1143 OrganizationService organizationService = getOrganizationService();
1144
1145 java.util.List<OrgInfo> orgInfos = organizationService.searchForOrgs(query, getContextInfo());
1146 if (!orgInfos.isEmpty()){
1147 longName = orgInfos.get(0).getLongName();
1148 }
1149 } catch (Exception e) {
1150 e.printStackTrace();
1151 throw new RuntimeException("Error! No long name description found.",e);
1152 }
1153 return longName;
1154 }
1155
1156 public CourseOfferingManagementViewHelperService getViewHelperService(CourseOfferingManagementForm theForm){
1157
1158 if (viewHelperService == null) {
1159 if (theForm.getView().getViewHelperServiceClass() != null){
1160 viewHelperService = (CourseOfferingManagementViewHelperService) theForm.getView().getViewHelperService();
1161 }else{
1162 viewHelperService= (CourseOfferingManagementViewHelperService) theForm.getPostedView().getViewHelperService();
1163 }
1164 }
1165
1166 return viewHelperService;
1167 }
1168
1169 public CourseOfferingService getCourseOfferingService() {
1170 return CourseOfferingResourceLoader.loadCourseOfferingService();
1171 }
1172
1173 private OrganizationService getOrganizationService(){
1174 if(organizationService == null) {
1175 organizationService = (OrganizationService) GlobalResourceLoader.getService(new QName(CommonServiceConstants.REF_OBJECT_URI_GLOBAL_PREFIX + "organization", "OrganizationService"));
1176
1177 }
1178 return organizationService;
1179 }
1180
1181 public ContextInfo getContextInfo() {
1182 ContextInfo contextInfo = new ContextInfo();
1183 contextInfo.setAuthenticatedPrincipalId(GlobalVariables.getUserSession().getPrincipalId());
1184 contextInfo.setPrincipalId(GlobalVariables.getUserSession().getPrincipalId());
1185 LocaleInfo localeInfo = new LocaleInfo();
1186 localeInfo.setLocaleLanguage(Locale.getDefault().getLanguage());
1187 localeInfo.setLocaleRegion(Locale.getDefault().getCountry());
1188 contextInfo.setLocale(localeInfo);
1189 return contextInfo;
1190 }
1191 }