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