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