1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.student.enrollment.class2.courseoffering.controller;
18
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.rice.krad.util.GlobalVariables;
21 import org.kuali.rice.krad.util.KRADConstants;
22 import org.kuali.rice.krad.web.form.DocumentFormBase;
23 import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
24 import org.kuali.student.common.uif.form.KSUifMaintenanceDocumentForm;
25 import org.kuali.student.enrollment.class2.courseoffering.dto.CourseOfferingEditWrapper;
26 import org.kuali.student.enrollment.class2.courseoffering.util.CourseOfferingConstants;
27 import org.kuali.student.enrollment.common.util.EnrollConstants;
28 import org.kuali.student.r2.core.class1.search.CourseOfferingManagementSearchImpl;
29 import org.springframework.stereotype.Controller;
30 import org.springframework.validation.BindingResult;
31 import org.springframework.web.bind.annotation.ModelAttribute;
32 import org.springframework.web.bind.annotation.RequestMapping;
33 import org.springframework.web.servlet.ModelAndView;
34
35 import javax.servlet.http.HttpServletRequest;
36 import javax.servlet.http.HttpServletResponse;
37 import java.util.Properties;
38
39
40
41
42
43
44
45 @Controller
46 @RequestMapping(value = "/courseOfferingEdit")
47 public class CourseOfferingEditController extends CourseOfferingBaseController {
48
49 @Override
50 protected MaintenanceDocumentForm createInitialForm(HttpServletRequest request) {
51 return new KSUifMaintenanceDocumentForm();
52 }
53
54 @Override
55 public ModelAndView maintenanceEdit(@ModelAttribute("KualiForm") MaintenanceDocumentForm form, BindingResult result,
56 HttpServletRequest request, HttpServletResponse response) throws Exception {
57
58 setupMaintenance(form, request, KRADConstants.MAINTENANCE_EDIT_ACTION);
59
60
61
62 if (form.getView() != null) {
63 String methodToCall = request.getParameter(KRADConstants.DISPATCH_REQUEST_PARAMETER);
64 checkViewAuthorization(form, methodToCall);
65 String crossListedAlias = request.getParameter("editCrossListedCoAlias");
66 if(StringUtils.equals(crossListedAlias, "true")) {
67 Object selectedObject = form.getDocument().getNewMaintainableObject().getDataObject();
68 if(selectedObject instanceof CourseOfferingEditWrapper) {
69 ((CourseOfferingEditWrapper) selectedObject).setEditCrossListedCoAlias(true);
70 }
71 }
72 }
73
74 return getUIFModelAndView(form);
75 }
76
77 @Override
78 @RequestMapping(params = "methodToCall=route")
79 public ModelAndView route(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
80 HttpServletRequest request, HttpServletResponse response) {
81
82 super.route(form, result, request, response);
83
84 if( GlobalVariables.getMessageMap().hasErrors() ) {
85 return handleRouteForErrors( form );
86 }
87
88 return handleRouteForCoEdit(form);
89 }
90
91
92 private ModelAndView handleRouteForCoEdit( DocumentFormBase form ) {
93
94 String urlToRedirectTo;
95 Properties urlParameters = new Properties();
96
97 GlobalVariables.getUifFormManager().removeSessionForm(form);
98
99
100 CourseOfferingEditWrapper dataObject = (CourseOfferingEditWrapper)((MaintenanceDocumentForm)form).getDocument().getNewMaintainableObject().getDataObject();
101
102
103 if (StringUtils.isEmpty(dataObject.getExamPeriodId())) {
104 urlParameters.put(EnrollConstants.GROWL_MESSAGE, CourseOfferingConstants.COURSE_OFFERING_EDIT_SUCCESS_WITH_MISSING_EXAMPERIOD);
105 } else if (!StringUtils.equals(dataObject.getCourseOfferingInfo().getFinalExamType(), CourseOfferingConstants.COURSEOFFERING_FINAL_EXAM_TYPE_STANDARD)) {
106 urlParameters.put(EnrollConstants.GROWL_MESSAGE, CourseOfferingConstants.COURSE_OFFERING_EDIT_SUCCESS);
107 }
108 else {
109 urlParameters.put(EnrollConstants.GROWL_MESSAGE, CourseOfferingConstants.COURSE_OFFERING_EDIT_SUCCESS_WITH_EXAMOFFERING_GENERATED);
110 }
111
112 urlParameters.put(EnrollConstants.GROWL_MESSAGE_PARAMS, dataObject.getCourseOfferingCode());
113
114
115 String returnLocationFromForm = form.getReturnLocation();
116 if ( StringUtils.contains(returnLocationFromForm,"viewId=courseOfferingManagementView")
117 || StringUtils.contains(returnLocationFromForm,"pageId=manageTheCourseOfferingPage")) {
118 if (!returnLocationFromForm.contains("methodToCall=")) {
119
120 form.getViewRequestParameters().put(CourseOfferingManagementSearchImpl.SearchParameters.IS_EXACT_MATCH_CO_CODE_SEARCH, Boolean.TRUE.toString());
121 }
122 else {
123 form.getViewRequestParameters().put(CourseOfferingManagementSearchImpl.SearchParameters.IS_EXACT_MATCH_CO_CODE_SEARCH, Boolean.FALSE.toString());
124 }
125 urlToRedirectTo = returnLocationFromForm.replaceFirst("methodToCall=[a-zA-Z0-9]+","methodToCall=show");
126 } else if (StringUtils.contains(returnLocationFromForm,"pageId=manageCourseOfferingsPage")
127 && !returnLocationFromForm.contains("methodToCall=")) {
128 urlToRedirectTo = returnLocationFromForm + "&methodToCall=show";
129 } else {
130 urlToRedirectTo = returnLocationFromForm;
131 }
132
133
134 urlToRedirectTo = urlToRedirectTo.replaceAll("growl.[^&]+&","");
135
136
137 String loadNewCO = form.getActionParameters().get( "coId" );
138 if( StringUtils.isNotBlank( loadNewCO ) ) {
139
140 urlParameters.put( KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.Maintenance.METHOD_TO_CALL_EDIT );
141 urlParameters.put( "courseOfferingInfo.id", loadNewCO );
142 urlParameters.put( KRADConstants.DATA_OBJECT_CLASS_ATTRIBUTE, CourseOfferingEditWrapper.class.getName() );
143 urlParameters.put( "returnLocation", urlToRedirectTo );
144
145 urlToRedirectTo = CourseOfferingConstants.CONTROLLER_PATH_COURSEOFFERING_EDIT_MAINTENANCE;
146 }
147
148 return performRedirect(form, urlToRedirectTo, urlParameters);
149 }
150
151 }