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.apache.log4j.Logger;
20 import org.kuali.rice.krad.UserSession;
21 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
22 import org.kuali.rice.krad.uif.UifConstants;
23 import org.kuali.rice.krad.uif.UifParameters;
24 import org.kuali.rice.krad.uif.service.ViewService;
25 import org.kuali.rice.krad.util.GlobalVariables;
26 import org.kuali.rice.krad.util.KRADConstants;
27 import org.kuali.rice.krad.util.KRADUtils;
28 import org.kuali.rice.krad.web.form.DocumentFormBase;
29 import org.kuali.rice.krad.web.form.IncidentReportForm;
30 import org.kuali.rice.krad.web.form.UifFormBase;
31 import org.springframework.web.servlet.ModelAndView;
32
33 import javax.servlet.http.HttpServletRequest;
34 import javax.servlet.http.HttpServletResponse;
35
36
37
38
39
40
41
42
43
44
45
46
47 public class UifHandlerExceptionResolver implements org.springframework.web.servlet.HandlerExceptionResolver {
48 private static final Logger LOG = Logger.getLogger(UifHandlerExceptionResolver.class);
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 @Override
67 public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
68 Exception ex) {
69 LOG.error("The following error was caught by the UifHandlerExceptionResolver : ", ex);
70
71
72 LOG.error(ex.getMessage(), ex);
73
74 String incidentDocId = request.getParameter(KRADConstants.DOCUMENT_DOCUMENT_NUMBER);
75 String incidentViewId = "";
76
77 UifFormBase form = (UifFormBase)request.getAttribute(UifConstants.REQUEST_FORM);
78 if (form instanceof DocumentFormBase) {
79 if (((DocumentFormBase) form).getDocument() != null) {
80 incidentDocId = ((DocumentFormBase) form).getDocument().getDocumentNumber();
81 }
82 incidentViewId = ((DocumentFormBase) form).getViewId();
83 }
84
85 GlobalVariables.getUifFormManager().removeSessionForm(form);
86
87 UserSession userSession = (UserSession) request.getSession().getAttribute(KRADConstants.USER_SESSION_KEY);
88 IncidentReportForm incidentReportForm = new IncidentReportForm();
89
90
91
92 String postUrl = request.getRequestURL().toString();
93 postUrl = postUrl.substring(0, postUrl.lastIndexOf("/")) + "/incidentReport";
94 incidentReportForm.setFormPostUrl(postUrl);
95
96 incidentReportForm.setException(ex);
97 incidentReportForm.setIncidentDocId(incidentDocId);
98 incidentReportForm.setIncidentViewId(incidentViewId);
99 incidentReportForm.setController(handler.getClass().toString());
100
101 if (userSession != null) {
102 incidentReportForm.setUserId(userSession.getPrincipalId());
103 incidentReportForm.setUserName(userSession.getPrincipalName());
104 incidentReportForm.setUserEmail(userSession.getPerson().getEmailAddress());
105 }
106
107 incidentReportForm.setDevMode(!KRADUtils.isProductionEnvironment());
108 incidentReportForm.setViewId("Uif-IncidentReportView");
109
110 if (form != null) {
111 incidentReportForm.setAjaxRequest(form.isAjaxRequest());
112 } else {
113 String ajaxRequestParm = request.getParameter(UifParameters.AJAX_REQUEST);
114 if (StringUtils.isNotBlank(ajaxRequestParm)) {
115 incidentReportForm.setAjaxRequest(Boolean.parseBoolean(ajaxRequestParm));
116 }
117 }
118
119
120 incidentReportForm.setView(getViewService().getViewById("Uif-IncidentReportView"));
121
122
123 incidentReportForm.setAjaxReturnType(UifConstants.AjaxReturnTypes.UPDATEVIEW.getKey());
124
125 ModelAndView modelAndView = UifControllerHelper.getUIFModelAndView(incidentReportForm, "");
126 try {
127 UifControllerHelper.postControllerHandle(request, response, handler, modelAndView);
128 } catch (Exception e) {
129 LOG.error("An error stopped the incident form from loading", e);
130 }
131
132 return modelAndView;
133 }
134
135 protected ViewService getViewService() {
136 return KRADServiceLocatorWeb.getViewService();
137 }
138
139 }