1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.web.bind;
17
18 import org.apache.log4j.Logger;
19 import org.kuali.rice.krad.UserSession;
20 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
21 import org.kuali.rice.krad.service.SessionDocumentService;
22 import org.kuali.rice.krad.uif.view.History;
23 import org.kuali.rice.krad.uif.view.HistoryEntry;
24 import org.kuali.rice.krad.uif.service.ViewService;
25 import org.kuali.rice.krad.uif.util.UifWebUtils;
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 import java.util.Map;
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 String incidentDocId = request.getParameter(KRADConstants.DOCUMENT_DOCUMENT_NUMBER);
72 String incidentViewId = "";
73
74
75 LOG.error(ex.getMessage(), ex);
76
77 UifFormBase form = UifWebUtils.getFormFromRequest(request);
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 UserSession userSession = (UserSession) request.getSession().getAttribute(KRADConstants.USER_SESSION_KEY);
86 IncidentReportForm incidentReportForm = new IncidentReportForm();
87
88
89
90 String postUrl = request.getRequestURL().toString();
91 postUrl = postUrl.substring(0, postUrl.lastIndexOf("/")) + "/incidentReport";
92 incidentReportForm.setFormPostUrl(postUrl);
93 incidentReportForm.setException(ex);
94 incidentReportForm.setIncidentDocId(incidentDocId);
95 incidentReportForm.setIncidentViewId(incidentViewId);
96 incidentReportForm.setController(handler.getClass().toString());
97 incidentReportForm.setUserId(userSession.getPrincipalId());
98 incidentReportForm.setUserName(userSession.getPrincipalName());
99 incidentReportForm.setUserEmail(userSession.getPerson().getEmailAddress());
100 incidentReportForm.setDevMode(!KRADUtils.isProductionEnvironment());
101
102
103 incidentReportForm.setView(getViewService().getViewById("Incident-Report"));
104
105
106 History history = new History();
107 HistoryEntry entry = new HistoryEntry("", "", "Incident Report", "", "");
108 history.setCurrent(entry);
109 incidentReportForm.setFormHistory(history);
110
111
112 incidentReportForm.setRenderFullView(true);
113
114 ModelAndView modelAndView = UifWebUtils.getUIFModelAndView(incidentReportForm, "");
115 try {
116 UifWebUtils.postControllerHandle(request, response, handler, modelAndView);
117 } catch (Exception e) {
118 LOG.error("An error stopped the incident form from loading", e);
119 }
120
121 return modelAndView;
122 }
123
124 protected ViewService getViewService() {
125 return KRADServiceLocatorWeb.getViewService();
126 }
127
128 protected SessionDocumentService getSessionDocumentService() {
129 return KRADServiceLocatorWeb.getSessionDocumentService();
130 }
131
132 }