| 1 |  |   | 
  | 2 |  |   | 
  | 3 |  |   | 
  | 4 |  |   | 
  | 5 |  |   | 
  | 6 |  |   | 
  | 7 |  |   | 
  | 8 |  |   | 
  | 9 |  |   | 
  | 10 |  |   | 
  | 11 |  |  package org.kuali.rice.krad.web.spring; | 
  | 12 |  |   | 
  | 13 |  |  import javax.servlet.http.HttpServletRequest; | 
  | 14 |  |  import javax.servlet.http.HttpServletResponse; | 
  | 15 |  |   | 
  | 16 |  |  import org.apache.log4j.Logger; | 
  | 17 |  |  import org.kuali.rice.krad.UserSession; | 
  | 18 |  |  import org.kuali.rice.krad.service.KRADServiceLocatorWeb; | 
  | 19 |  |  import org.kuali.rice.krad.service.SessionDocumentService; | 
  | 20 |  |  import org.kuali.rice.krad.uif.history.History; | 
  | 21 |  |  import org.kuali.rice.krad.uif.history.HistoryEntry; | 
  | 22 |  |  import org.kuali.rice.krad.uif.service.ViewService; | 
  | 23 |  |  import org.kuali.rice.krad.uif.util.UifWebUtils; | 
  | 24 |  |  import org.kuali.rice.krad.util.KRADConstants; | 
  | 25 |  |  import org.kuali.rice.krad.util.WebUtils; | 
  | 26 |  |  import org.kuali.rice.krad.web.spring.form.DocumentFormBase; | 
  | 27 |  |  import org.kuali.rice.krad.web.spring.form.IncidentReportForm; | 
  | 28 |  |  import org.kuali.rice.krad.web.spring.form.UifFormBase; | 
  | 29 |  |  import org.springframework.web.servlet.ModelAndView; | 
  | 30 |  |   | 
  | 31 |  |   | 
  | 32 |  |   | 
  | 33 |  |   | 
  | 34 |  |   | 
  | 35 |  |   | 
  | 36 |  |   | 
  | 37 |  |   | 
  | 38 |  |   | 
  | 39 |  |   | 
  | 40 |  |   | 
  | 41 |  |   | 
  | 42 | 0 |  public class UifHandlerExceptionResolver implements org.springframework.web.servlet.HandlerExceptionResolver { | 
  | 43 |  |   | 
  | 44 | 0 |      private static final Logger LOG = Logger.getLogger(UifHandlerExceptionResolver.class); | 
  | 45 |  |   | 
  | 46 |  |       | 
  | 47 |  |   | 
  | 48 |  |   | 
  | 49 |  |   | 
  | 50 |  |   | 
  | 51 |  |   | 
  | 52 |  |   | 
  | 53 |  |   | 
  | 54 |  |   | 
  | 55 |  |   | 
  | 56 |  |   | 
  | 57 |  |   | 
  | 58 |  |   | 
  | 59 |  |   | 
  | 60 |  |   | 
  | 61 |  |   | 
  | 62 |  |   | 
  | 63 |  |      @Override | 
  | 64 |  |      public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, | 
  | 65 |  |              Exception ex) {     | 
  | 66 | 0 |          LOG.error("The following error was caught by the UifHandlerExceptionResolver : ", ex);         | 
  | 67 | 0 |          String incidentDocId = request.getParameter(KRADConstants.DOCUMENT_DOCUMENT_NUMBER); | 
  | 68 | 0 |          String incidentViewId = ""; | 
  | 69 |  |   | 
  | 70 |  |           | 
  | 71 | 0 |          LOG.error(ex.getMessage(), ex); | 
  | 72 |  |   | 
  | 73 | 0 |          UifFormBase form = UifWebUtils.getFormFromRequest(request); | 
  | 74 | 0 |          if (form instanceof DocumentFormBase) { | 
  | 75 | 0 |              incidentDocId = ((DocumentFormBase) form).getDocument().getDocumentNumber(); | 
  | 76 | 0 |              incidentViewId = ((DocumentFormBase) form).getViewId(); | 
  | 77 |  |          } | 
  | 78 |  |   | 
  | 79 | 0 |          UserSession userSession = (UserSession) request.getSession().getAttribute(KRADConstants.USER_SESSION_KEY); | 
  | 80 | 0 |          IncidentReportForm incidentReportForm = new IncidentReportForm(); | 
  | 81 |  |           | 
  | 82 |  |           | 
  | 83 | 0 |          String postUrl = request.getRequestURL().toString();         | 
  | 84 | 0 |          postUrl = postUrl.substring(0, postUrl.lastIndexOf("/")) + "/incidentReport"; | 
  | 85 | 0 |          incidentReportForm.setFormPostUrl(postUrl); | 
  | 86 | 0 |          incidentReportForm.setException(ex); | 
  | 87 | 0 |          incidentReportForm.setIncidentDocId(incidentDocId); | 
  | 88 | 0 |          incidentReportForm.setIncidentViewId(incidentViewId); | 
  | 89 | 0 |          incidentReportForm.setController(handler.getClass().toString()); | 
  | 90 | 0 |          incidentReportForm.setUserId(userSession.getPrincipalId()); | 
  | 91 | 0 |          incidentReportForm.setUserName(userSession.getPrincipalName()); | 
  | 92 | 0 |          incidentReportForm.setUserEmail(userSession.getPerson().getEmailAddress()); | 
  | 93 | 0 |          incidentReportForm.setDevMode(!WebUtils.isProductionEnvironment()); | 
  | 94 |  |   | 
  | 95 |  |           | 
  | 96 | 0 |          incidentReportForm.setView(getViewService().getView("Incident-Report", | 
  | 97 |  |                  incidentReportForm.getViewRequestParameters())); | 
  | 98 |  |   | 
  | 99 |  |           | 
  | 100 | 0 |          History history = new History(); | 
  | 101 | 0 |          HistoryEntry entry = new HistoryEntry("", "", "Incident Report", "", ""); | 
  | 102 | 0 |          history.setCurrent(entry); | 
  | 103 | 0 |          incidentReportForm.setFormHistory(history); | 
  | 104 |  |   | 
  | 105 |  |           | 
  | 106 | 0 |          incidentReportForm.setRenderFullView(true); | 
  | 107 |  |   | 
  | 108 | 0 |          ModelAndView modelAndView = UifWebUtils.getUIFModelAndView(incidentReportForm, "Incident-Report", ""); | 
  | 109 |  |          try { | 
  | 110 | 0 |              UifWebUtils.postControllerHandle(request, response, handler, modelAndView); | 
  | 111 | 0 |          } catch (Exception e) { | 
  | 112 | 0 |              LOG.error("An error stopped the incident form from loading", e); | 
  | 113 | 0 |          } | 
  | 114 |  |   | 
  | 115 | 0 |          return modelAndView; | 
  | 116 |  |      } | 
  | 117 |  |   | 
  | 118 |  |      protected ViewService getViewService() { | 
  | 119 | 0 |          return KRADServiceLocatorWeb.getViewService(); | 
  | 120 |  |      } | 
  | 121 |  |   | 
  | 122 |  |      protected SessionDocumentService getSessionDocumentService() { | 
  | 123 | 0 |          return KRADServiceLocatorWeb.getSessionDocumentService(); | 
  | 124 |  |      } | 
  | 125 |  |   | 
  | 126 |  |  } |