| 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 | 0 | public class UifHandlerExceptionResolver implements org.springframework.web.servlet.HandlerExceptionResolver { |
| 49 | 0 | 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 | 0 | LOG.error("The following error was caught by the UifHandlerExceptionResolver : ", ex); |
| 71 | 0 | String incidentDocId = request.getParameter(KRADConstants.DOCUMENT_DOCUMENT_NUMBER); |
| 72 | 0 | String incidentViewId = ""; |
| 73 | |
|
| 74 | |
|
| 75 | 0 | LOG.error(ex.getMessage(), ex); |
| 76 | |
|
| 77 | 0 | UifFormBase form = UifWebUtils.getFormFromRequest(request); |
| 78 | 0 | if (form instanceof DocumentFormBase) { |
| 79 | 0 | if (((DocumentFormBase) form).getDocument() != null) { |
| 80 | 0 | incidentDocId = ((DocumentFormBase) form).getDocument().getDocumentNumber(); |
| 81 | |
} |
| 82 | 0 | incidentViewId = ((DocumentFormBase) form).getViewId(); |
| 83 | |
} |
| 84 | |
|
| 85 | 0 | UserSession userSession = (UserSession) request.getSession().getAttribute(KRADConstants.USER_SESSION_KEY); |
| 86 | 0 | IncidentReportForm incidentReportForm = new IncidentReportForm(); |
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | 0 | String postUrl = request.getRequestURL().toString(); |
| 91 | 0 | postUrl = postUrl.substring(0, postUrl.lastIndexOf("/")) + "/incidentReport"; |
| 92 | 0 | incidentReportForm.setFormPostUrl(postUrl); |
| 93 | 0 | incidentReportForm.setException(ex); |
| 94 | 0 | incidentReportForm.setIncidentDocId(incidentDocId); |
| 95 | 0 | incidentReportForm.setIncidentViewId(incidentViewId); |
| 96 | 0 | incidentReportForm.setController(handler.getClass().toString()); |
| 97 | 0 | incidentReportForm.setUserId(userSession.getPrincipalId()); |
| 98 | 0 | incidentReportForm.setUserName(userSession.getPrincipalName()); |
| 99 | 0 | incidentReportForm.setUserEmail(userSession.getPerson().getEmailAddress()); |
| 100 | 0 | incidentReportForm.setDevMode(!KRADUtils.isProductionEnvironment()); |
| 101 | |
|
| 102 | |
|
| 103 | 0 | incidentReportForm.setView(getViewService().getViewById("Incident-Report")); |
| 104 | |
|
| 105 | |
|
| 106 | 0 | History history = new History(); |
| 107 | 0 | HistoryEntry entry = new HistoryEntry("", "", "Incident Report", "", ""); |
| 108 | 0 | history.setCurrent(entry); |
| 109 | 0 | incidentReportForm.setFormHistory(history); |
| 110 | |
|
| 111 | |
|
| 112 | 0 | incidentReportForm.setRenderFullView(true); |
| 113 | |
|
| 114 | 0 | ModelAndView modelAndView = UifWebUtils.getUIFModelAndView(incidentReportForm, ""); |
| 115 | |
try { |
| 116 | 0 | UifWebUtils.postControllerHandle(request, response, handler, modelAndView); |
| 117 | 0 | } catch (Exception e) { |
| 118 | 0 | LOG.error("An error stopped the incident form from loading", e); |
| 119 | 0 | } |
| 120 | |
|
| 121 | 0 | return modelAndView; |
| 122 | |
} |
| 123 | |
|
| 124 | |
protected ViewService getViewService() { |
| 125 | 0 | return KRADServiceLocatorWeb.getViewService(); |
| 126 | |
} |
| 127 | |
|
| 128 | |
protected SessionDocumentService getSessionDocumentService() { |
| 129 | 0 | return KRADServiceLocatorWeb.getSessionDocumentService(); |
| 130 | |
} |
| 131 | |
|
| 132 | |
} |