View Javadoc

1   /*
2    * Copyright 2011 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.enrollment.class1.hold.controller;
17  
18  import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
19  import org.kuali.rice.krad.uif.UifParameters;
20  import org.kuali.rice.krad.util.GlobalVariables;
21  import org.kuali.rice.krad.web.controller.UifControllerBase;
22  import org.kuali.rice.krad.web.form.UifFormBase;
23  import org.kuali.student.enrollment.class1.hold.form.HoldIssueInfoCreateForm;
24  import org.kuali.student.enrollment.class2.courseoffering.form.DeleteTargetTermForm;
25  import org.kuali.student.enrollment.class2.courseoffering.service.CourseOfferingViewHelperService;
26  import org.kuali.student.enrollment.courseofferingset.dto.SocInfo;
27  import org.kuali.student.mock.utilities.TestHelper;
28  import org.kuali.student.r2.common.dto.ContextInfo;
29  import org.kuali.student.r2.common.dto.RichTextInfo;
30  import org.kuali.student.r2.common.util.constants.CourseOfferingSetServiceConstants;
31  import org.kuali.student.r2.core.constants.HoldServiceConstants;
32  import org.kuali.student.r2.common.util.constants.OrganizationServiceConstants;
33  import org.kuali.student.r2.core.hold.dto.HoldIssueInfo;
34  import org.kuali.student.r2.core.hold.service.HoldService;
35  import org.kuali.student.r2.core.organization.service.OrganizationService;
36  import org.kuali.student.r2.core.organization.dto.OrgInfo;
37  import org.springframework.stereotype.Controller;
38  import org.springframework.validation.BindingResult;
39  import org.springframework.web.bind.annotation.ModelAttribute;
40  import org.springframework.web.bind.annotation.RequestMapping;
41  import org.springframework.web.bind.annotation.RequestMethod;
42  import org.springframework.web.servlet.ModelAndView;
43  
44  import javax.servlet.http.HttpServletRequest;
45  import javax.servlet.http.HttpServletResponse;
46  import javax.xml.namespace.QName;
47  import java.util.Properties;
48  
49  /**
50   * This controller handles all the request from Academic calendar UI.
51   *
52   * @author Kuali Student Team
53   */
54  
55  @Controller
56  @RequestMapping(value = "/createHold")
57  public class HoldIssueInfoCreateController extends UifControllerBase {
58  
59      private transient HoldService holdService;
60      private transient OrganizationService organizationService;
61      private ContextInfo contextInfo;
62      private HoldIssueInfo holdIssueInfo;
63      private OrgInfo orgInfo;
64  
65      @Override
66      protected UifFormBase createInitialForm(HttpServletRequest request) {
67          return new HoldIssueInfoCreateForm();
68      }
69  
70      /**
71       * This GET method loads an academic calendar based on the parameters passed into the request.
72       *
73       * These are the supported request parameters
74       * 1. id - Academic Calendar Id to load in to UI
75       * 2. readOnlyView - If true, sets the view as read only
76       * 3. selectTab - can be 'info' or 'term'
77       *
78       */
79      @Override
80      @RequestMapping(method = RequestMethod.GET, params = "methodToCall=start")
81      public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
82                                HttpServletRequest request, HttpServletResponse response) {
83          HoldIssueInfoCreateForm holdForm = (HoldIssueInfoCreateForm) form;
84  
85          return super.start(form, result, request, response);
86      }
87  
88      @RequestMapping(params = "methodToCall=create")
89      public ModelAndView create(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
90                                 HttpServletRequest request, HttpServletResponse response) throws Exception {
91          HoldIssueInfoCreateForm createForm = (HoldIssueInfoCreateForm) form;
92          holdIssueInfo = new HoldIssueInfo();
93          holdIssueInfo.setName(createForm.getName());
94          holdIssueInfo.setTypeKey(createForm.getTypeKey());
95          holdIssueInfo.setStateKey("kuali.hold.issue.state.active");
96          holdIssueInfo.setOrganizationId(createForm.getOrganizationId());
97          RichTextInfo richTextInfo = new RichTextInfo();
98          richTextInfo.setPlain(createForm.getDescr());
99          holdIssueInfo.setDescr(richTextInfo);
100 
101         HoldIssueInfo createHoldIssueInfo;
102         try {
103             holdService = getHoldService();
104 
105                 createHoldIssueInfo = holdService.createHoldIssue(holdIssueInfo.getTypeKey(), holdIssueInfo, getContextInfo() );
106         } catch (Exception e) {
107 
108            return getUIFModelAndView(createForm);
109             //throw new RuntimeException("Create new failed. ", e);
110         }
111         createForm.setValidateDirty(false);
112         createForm.setId(createHoldIssueInfo.getId());
113         createForm.setStateKey(createHoldIssueInfo.getStateKey());
114         return close(createForm, result, request, response);
115     }
116 
117   @RequestMapping(params = "methodToCall=modify")
118  public ModelAndView modity(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
119                             HttpServletRequest request, HttpServletResponse response) throws Exception {
120       HoldIssueInfoCreateForm modifyForm = (HoldIssueInfoCreateForm) form;
121 
122       holdIssueInfo = new HoldIssueInfo();
123       holdIssueInfo.setId(modifyForm.getId());
124       holdIssueInfo.setName(modifyForm.getName());
125       holdIssueInfo.setTypeKey(modifyForm.getTypeKey());
126       holdIssueInfo.setStateKey(modifyForm.getStateKey());
127       holdIssueInfo.setOrganizationId(modifyForm.getOrganizationId());
128       RichTextInfo richTextInfo = new RichTextInfo();
129       richTextInfo.setPlain(modifyForm.getDescr());
130       holdIssueInfo.setDescr(richTextInfo);
131 
132       try {
133           holdService = getHoldService();
134           holdService.updateHoldIssue(holdIssueInfo.getId(), holdIssueInfo, getContextInfo() );
135       } catch (Exception e) {
136           e.printStackTrace();
137           throw new RuntimeException("Modify Hold failed. ", e);
138       }
139       form.setValidateDirty(false);
140       GlobalVariables.getMessageMap().putInfo("Hold Issue Info", "info.enroll.save.success");
141       return getUIFModelAndView(form);
142  }
143 
144     @RequestMapping(params = "methodToCall=view")
145     public ModelAndView view(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
146                               HttpServletRequest request, HttpServletResponse response) {
147         HoldIssueInfoCreateForm holdIssueForm = (HoldIssueInfoCreateForm) form;
148         String holdIssueId = request.getParameter("id");
149         String viewType = request.getParameter(UifParameters.VIEW_ID);
150         String orgName = request.getParameter("orgName");
151         if ((holdIssueId != null) && !holdIssueId.trim().isEmpty()) {
152             try {
153                 HoldIssueInfo holdIssueInfo = getHoldService().getHoldIssue(holdIssueId, getContextInfo());
154                 holdIssueForm.setName(holdIssueInfo.getName());
155                 holdIssueForm.setTypeKey(holdIssueInfo.getTypeKey());
156                 holdIssueForm.setDescr(holdIssueInfo.getDescr().getPlain());
157                 holdIssueForm.setOrganizationId(holdIssueInfo.getOrganizationId());
158                 holdIssueForm.setStateKey(holdIssueInfo.getStateKey());
159                 holdIssueForm.setOrgName(orgName);
160             } catch (Exception ex) {
161                 throw new RuntimeException("unable to get hold issue");
162             }
163         }
164 
165 /*        if(viewType.equals("holdView")) {
166             holdIssueForm.getView().setReadOnly(true);
167         }*/
168 
169         return super.start(holdIssueForm, result, request, response);
170     }
171 
172     private ContextInfo getContextInfo() {
173         if (null == contextInfo) {
174             //TODO - get real ContextInfo
175             contextInfo = TestHelper.getContext1();
176         }
177         return contextInfo;
178     }
179 
180     protected HoldService getHoldService(){
181         if(holdService == null) {
182             holdService = (HoldService) GlobalResourceLoader.getService(new QName(HoldServiceConstants.NAMESPACE, HoldServiceConstants.SERVICE_NAME_LOCAL_PART));
183         }
184         return holdService;
185     }
186     protected OrganizationService getOrganizationService(){
187         if(organizationService == null) {
188             organizationService = (OrganizationService) GlobalResourceLoader.getService(new QName(OrganizationServiceConstants.NAMESPACE, OrganizationServiceConstants.SERVICE_NAME_LOCAL_PART));
189         }
190         return organizationService;
191     }
192 }