View Javadoc
1   /**
2    * Copyright 2005-2015 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       * {@inheritDoc}
49       */
50      @Override
51      protected IncidentReportForm createInitialForm() {
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(UifFormBase uifForm, HttpServletRequest request) throws Exception {
60          // get the exception incident service and use it to mail the report
61          KualiExceptionIncidentService reporterService = KRADServiceLocatorWeb.getKualiExceptionIncidentService();
62          reporterService.emailReport(((IncidentReportForm) uifForm).createEmailSubject(),
63                  ((IncidentReportForm) uifForm).createEmailMessage());
64  
65          // return the close redirect
66          return back(uifForm);
67      }
68  
69      /**
70       * Returns back to the application url on a cancel
71       *
72       * @see UifControllerBase#cancel
73       */
74      @RequestMapping(params = "methodToCall=cancel")
75      public ModelAndView cancel(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
76              HttpServletRequest request, HttpServletResponse response) {
77          Properties props = new Properties();
78          props.put(UifParameters.METHOD_TO_CALL, UifConstants.MethodToCallNames.REFRESH);
79  
80          if (StringUtils.isNotBlank(form.getReturnFormKey())) {
81              props.put(UifParameters.FORM_KEY, form.getReturnFormKey());
82          }
83  
84          String returnUrl = ConfigContext.getCurrentContextConfig().getProperty(KRADConstants.APPLICATION_URL_KEY);
85  
86          return performRedirect(form, returnUrl, props);
87      }
88  
89  }