View Javadoc
1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 1.0 (the
5    * "License"); you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl1.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations under
14   * the License.
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   *  This controller handles all the requests Curriculum Home View  'Create a Course' UI.
42   *
43   *   @author Kuali Student Team
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          // cannot pass in document type here because we do not now if this is a Create or a Modify
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          // cannot pass in document type here because we do not now if this is a Create or a Modify
74          if (!ProposalUtil.isUserCurriculumSpecialist()) {
75              // if user is not a CS user, then curriculum review must be used because only CS users can disable curriculum review
76              urlParameters.put(CurriculumManagementConstants.UrlParams.USE_CURRICULUM_REVIEW,Boolean.TRUE.toString());
77          } else {
78              // if user is a CS user, check the checkbox value
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       * After the Create course initial data is filled call the method to show the navigation panel and
89       * setup the maintenance object
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             //If CS user and selects no curriculum review
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      * This methods sets urlParameters with 'methodtocall' property depending on 'ProposalCourseStartOptions'
128      *
129      * @param urlParameters is properties which needs to be set with 'methodtocall' property.
130      * @param form
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 }