1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.student.cm.course.controller;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.kew.api.KewApiConstants;
20 import org.kuali.rice.krad.uif.UifConstants;
21 import org.kuali.rice.krad.util.KRADConstants;
22 import org.kuali.rice.krad.web.controller.UifControllerBase;
23 import org.kuali.rice.krad.web.form.UifFormBase;
24 import org.kuali.student.cm.common.util.CMUtils;
25 import org.kuali.student.cm.common.util.CurriculumManagementConstants;
26 import org.kuali.student.cm.course.form.StartProposalForm;
27 import org.kuali.student.cm.course.form.wrapper.CourseInfoWrapper;
28 import org.kuali.student.cm.proposal.util.ProposalUtil;
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
46
47 @Controller
48 @RequestMapping(value = CurriculumManagementConstants.ControllerRequestMappings.START_PROPOSAL)
49 public class StartProposalController extends UifControllerBase {
50
51 @Override
52 protected UifFormBase createInitialForm(HttpServletRequest httpServletRequest) {
53 StartProposalForm courseForm= new StartProposalForm();
54 courseForm.setUseReviewProcess(false);
55
56 courseForm.setCurriculumSpecialistUser(ProposalUtil.isUserCurriculumSpecialist());
57 String versionIndId = httpServletRequest.getParameter(CurriculumManagementConstants.UrlParams.VERSION_IND_ID);
58 courseForm.setVersionIndId(versionIndId);
59 String courseId = httpServletRequest.getParameter(CurriculumManagementConstants.UrlParams.CLU_ID);
60 String isModifyNewVersion = httpServletRequest.getParameter(CurriculumManagementConstants.UrlParams.IS_MODIFY_NEW_VERSION);
61 courseForm.setModifiableCourse(new Boolean(isModifyNewVersion));
62 courseForm.setCourseId(courseId);
63 String subjectArea = httpServletRequest.getParameter(CurriculumManagementConstants.UrlParams.COURSE_SUBJECT_AREA);
64 String courseNumber = httpServletRequest.getParameter(CurriculumManagementConstants.UrlParams.COURSE_NUMBER_SUFFIX);
65 String courseTitle = httpServletRequest.getParameter(CurriculumManagementConstants.UrlParams.COURSE_TITLE);
66 courseForm.setModifyHeaderText("Modify " + subjectArea + courseNumber + " " + courseTitle);
67 return courseForm;
68 }
69
70
71 protected void setUrlParameters(Properties urlParameters,UifFormBase form){
72
73
74 if (!ProposalUtil.isUserCurriculumSpecialist()) {
75
76 urlParameters.put(CurriculumManagementConstants.UrlParams.USE_CURRICULUM_REVIEW,Boolean.TRUE.toString());
77 } else {
78
79 urlParameters.put(CurriculumManagementConstants.UrlParams.USE_CURRICULUM_REVIEW,Boolean.toString(((StartProposalForm) form).isUseReviewProcess()));
80 }
81 urlParameters.put(UifConstants.UrlParams.PAGE_ID, CurriculumManagementConstants.CoursePageIds.CREATE_COURSE_PAGE);
82 urlParameters.put(KRADConstants.PARAMETER_COMMAND, KewApiConstants.INITIATE_COMMAND);
83 urlParameters.put(KRADConstants.DATA_OBJECT_CLASS_ATTRIBUTE, CourseInfoWrapper.class.getName());
84 urlParameters.put(KRADConstants.RETURN_LOCATION_PARAMETER, CMUtils.getCMHomeUrl() );
85 }
86
87
88
89
90
91 @RequestMapping(params = "methodToCall=continueCreateCourse")
92 public ModelAndView continueCreateCourse(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
93 HttpServletRequest request, HttpServletResponse response) throws Exception {
94
95 Properties urlParameters = new Properties();
96 setUrlParameters(urlParameters,form);
97
98 String startProposalCourseAction = ((StartProposalForm)form).getStartProposalCourseAction();
99 if( StringUtils.equalsIgnoreCase(startProposalCourseAction,CurriculumManagementConstants.ModifyCourseStartOptions.MODIFY_WITH_A_NEW_VERSION)) {
100
101 urlParameters.put(CurriculumManagementConstants.UrlParams.VERSION_IND_ID,((StartProposalForm)form).getVersionIndId());
102 urlParameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, startProposalCourseAction);
103 urlParameters.put(CourseController.UrlParams.MODIFY_ACTION, startProposalCourseAction);
104
105 boolean isCSUser = ProposalUtil.isUserCurriculumSpecialist();
106
107 if (!isCSUser || (isCSUser && ((StartProposalForm)form).isUseReviewProcess())) {
108 urlParameters.put(UifConstants.UrlParams.PAGE_ID, CurriculumManagementConstants.CoursePageIds.REVIEW_COURSE_PROPOSAL_PAGE);
109 } else {
110 urlParameters.put(UifConstants.UrlParams.PAGE_ID, CurriculumManagementConstants.CoursePageIds.CREATE_COURSE_PAGE);
111 }
112 }
113 else if(StringUtils.equalsIgnoreCase(startProposalCourseAction,CurriculumManagementConstants.ModifyCourseStartOptions.MODIFY_THIS_VERSION)){
114 urlParameters.put(CurriculumManagementConstants.UrlParams.CLU_ID , ((StartProposalForm)form).getCourseId()) ;
115 urlParameters.put(UifConstants.UrlParams.PAGE_ID, CurriculumManagementConstants.CoursePageIds.CREATE_COURSE_PAGE);
116 urlParameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, startProposalCourseAction);
117 }
118
119 else{
120 setMethodToCall(urlParameters, (StartProposalForm)form);
121 }
122 String uri = request.getRequestURL().toString().replace(CurriculumManagementConstants.ControllerRequestMappings.START_PROPOSAL,CurriculumManagementConstants.ControllerRequestMappings.COURSE_MAINTENANCE);
123 return performRedirect(form, uri, urlParameters);
124 }
125
126
127
128
129
130
131
132 protected void setMethodToCall(Properties urlParameters, StartProposalForm form ){
133
134 String startProposalCourseAction = form.getStartProposalCourseAction();
135
136 if(StringUtils.equalsIgnoreCase(startProposalCourseAction,CurriculumManagementConstants.ProposalCourseStartOptions.BLANK_PROPOSAL)) {
137 urlParameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.DOC_HANDLER_METHOD);
138 return;
139 }
140
141 urlParameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, KRADConstants.Maintenance.METHOD_TO_CALL_COPY);
142
143 if(StringUtils.equalsIgnoreCase(startProposalCourseAction,CurriculumManagementConstants.ProposalCourseStartOptions.COPY_APPROVED_COURSE)) {
144 urlParameters.put(CourseController.UrlParams.COPY_CLU_ID, form.getCourseId());
145 } else if(StringUtils.equalsIgnoreCase(startProposalCourseAction,CurriculumManagementConstants.ProposalCourseStartOptions.COPY_PROPOSED_COURSE)) {
146 urlParameters.put(CourseController.UrlParams.COPY_PROPOSAL_ID, form.getProposalId());
147 } else {
148 throw new RuntimeException("This should not happen.");
149 }
150 }
151
152 }