View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * 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/ecl2.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,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.web.controller;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.kuali.rice.core.api.config.property.ConfigContext;
20  import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
21  import org.kuali.rice.krad.service.KualiExceptionIncidentService;
22  import org.kuali.rice.krad.uif.UifConstants;
23  import org.kuali.rice.krad.uif.UifParameters;
24  import org.kuali.rice.krad.util.KRADConstants;
25  import org.kuali.rice.krad.web.form.IncidentReportForm;
26  import org.kuali.rice.krad.web.form.UifFormBase;
27  import org.springframework.stereotype.Controller;
28  import org.springframework.validation.BindingResult;
29  import org.springframework.web.bind.annotation.ModelAttribute;
30  import org.springframework.web.bind.annotation.RequestMapping;
31  import org.springframework.web.bind.annotation.RequestMethod;
32  import org.springframework.web.servlet.ModelAndView;
33  
34  import javax.servlet.http.HttpServletRequest;
35  import javax.servlet.http.HttpServletResponse;
36  import java.util.Properties;
37  
38  /**
39   * Handler for incident reports
40   *
41   * @author Kuali Rice Team (rice.collab@kuali.org)
42   */
43  @Controller
44  @RequestMapping(value = "/incidentReport")
45  public class IncidentReportController extends UifControllerBase {
46  
47      /**
48       * @see org.kuali.rice.krad.web.controller.UifControllerBase#createInitialForm(javax.servlet.http.HttpServletRequest)
49       */
50      @Override
51      protected IncidentReportForm createInitialForm(HttpServletRequest request) {
52          return new IncidentReportForm();
53      }
54  
55      /**
56       * Emails the report and closes the incident report screen
57       */
58      @RequestMapping(method = RequestMethod.POST, params = "methodToCall=submitReport")
59      public ModelAndView submitReport(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
60              HttpServletRequest request, HttpServletResponse response) throws Exception {
61          // get the exception incident service and use it to mail the report
62          KualiExceptionIncidentService reporterService = KRADServiceLocatorWeb.getKualiExceptionIncidentService();
63          reporterService.emailReport(((IncidentReportForm) uifForm).createEmailSubject(),
64                  ((IncidentReportForm) uifForm).createEmailMessage());
65  
66          // return the close redirect
67          return back(uifForm, result, request, response);
68      }
69  
70      /**
71       * Returns back to the application url on a cancel
72       *
73       * @see UifControllerBase#cancel
74       */
75      @RequestMapping(params = "methodToCall=cancel")
76      public ModelAndView cancel(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
77              HttpServletRequest request, HttpServletResponse response) {
78          Properties props = new Properties();
79          props.put(UifParameters.METHOD_TO_CALL, UifConstants.MethodToCallNames.REFRESH);
80  
81          if (StringUtils.isNotBlank(form.getReturnFormKey())) {
82              props.put(UifParameters.FORM_KEY, form.getReturnFormKey());
83          }
84  
85          String returnUrl = ConfigContext.getCurrentContextConfig().getProperty(KRADConstants.APPLICATION_URL_KEY);
86  
87          return performRedirect(form, returnUrl, props);
88      }
89  
90  }