1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
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  
40  
41  
42  
43  @Controller
44  @RequestMapping(value = "/incidentReport")
45  public class IncidentReportController extends UifControllerBase {
46  
47      
48  
49  
50      @Override
51      protected IncidentReportForm createInitialForm() {
52          return new IncidentReportForm();
53      }
54  
55      
56  
57  
58      @RequestMapping(method = RequestMethod.POST, params = "methodToCall=submitReport")
59      public ModelAndView submitReport(UifFormBase uifForm, HttpServletRequest request) throws Exception {
60          
61          KualiExceptionIncidentService reporterService = KRADServiceLocatorWeb.getKualiExceptionIncidentService();
62          reporterService.emailReport(((IncidentReportForm) uifForm).createEmailSubject(),
63                  ((IncidentReportForm) uifForm).createEmailMessage());
64  
65          
66          return back(uifForm);
67      }
68  
69      
70  
71  
72  
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  }