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.uif.view.History;
22 import org.kuali.rice.krad.uif.view.HistoryEntry;
23 import org.kuali.rice.krad.uif.service.ViewService;
24 import org.kuali.rice.krad.uif.util.UifWebUtils;
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 = GlobalVariables.getUifFormManager().getCurrentForm();
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 GlobalVariables.getUifFormManager().removeForm(form);
85
86 UserSession userSession = (UserSession) request.getSession().getAttribute(KRADConstants.USER_SESSION_KEY);
87 IncidentReportForm incidentReportForm = new IncidentReportForm();
88
89
90
91 String postUrl = request.getRequestURL().toString();
92 postUrl = postUrl.substring(0, postUrl.lastIndexOf("/")) + "/incidentReport";
93 incidentReportForm.setFormPostUrl(postUrl);
94
95 incidentReportForm.setException(ex);
96 incidentReportForm.setIncidentDocId(incidentDocId);
97 incidentReportForm.setIncidentViewId(incidentViewId);
98 incidentReportForm.setController(handler.getClass().toString());
99 incidentReportForm.setUserId(userSession.getPrincipalId());
100 incidentReportForm.setUserName(userSession.getPrincipalName());
101 incidentReportForm.setUserEmail(userSession.getPerson().getEmailAddress());
102 incidentReportForm.setDevMode(!KRADUtils.isProductionEnvironment());
103 incidentReportForm.setViewId("Uif-IncidentReportView");
104
105
106 incidentReportForm.setView(getViewService().getViewById("Uif-IncidentReportView"));
107
108
109 History history = new History();
110 HistoryEntry entry = new HistoryEntry("", "", "Incident Report", "", "");
111 history.setCurrent(entry);
112 incidentReportForm.setFormHistory(history);
113
114
115 incidentReportForm.setRenderFullView(true);
116
117 ModelAndView modelAndView = UifWebUtils.getUIFModelAndView(incidentReportForm, "");
118 try {
119 UifWebUtils.postControllerHandle(request, response, handler, modelAndView);
120 } catch (Exception e) {
121 LOG.error("An error stopped the incident form from loading", e);
122 }
123
124 GlobalVariables.getUifFormManager().setCurrentForm(incidentReportForm);
125
126 return modelAndView;
127 }
128
129 protected ViewService getViewService() {
130 return KRADServiceLocatorWeb.getViewService();
131 }
132
133 }