Coverage Report - org.kuali.rice.krad.web.bind.UifHandlerExceptionResolver
 
Classes in this File Line Coverage Branch Coverage Complexity
UifHandlerExceptionResolver
0%
0/37
0%
0/4
1.667
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation Licensed under the Educational Community
 3  
  * License, Version 1.0 (the "License"); you may not use this file except in
 4  
  * compliance with the License. You may obtain a copy of the License at
 5  
  * http://www.opensource.org/licenses/ecl1.php Unless required by applicable law
 6  
  * or agreed to in writing, software distributed under the License is
 7  
  * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 8  
  * KIND, either express or implied. See the License for the specific language
 9  
  * governing permissions and limitations under the License.
 10  
  */
 11  
 package org.kuali.rice.krad.web.bind;
 12  
 
 13  
 import org.apache.log4j.Logger;
 14  
 import org.kuali.rice.krad.UserSession;
 15  
 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
 16  
 import org.kuali.rice.krad.service.SessionDocumentService;
 17  
 import org.kuali.rice.krad.uif.history.History;
 18  
 import org.kuali.rice.krad.uif.history.HistoryEntry;
 19  
 import org.kuali.rice.krad.uif.service.ViewService;
 20  
 import org.kuali.rice.krad.uif.util.UifWebUtils;
 21  
 import org.kuali.rice.krad.util.KRADConstants;
 22  
 import org.kuali.rice.krad.util.KRADUtils;
 23  
 import org.kuali.rice.krad.web.form.DocumentFormBase;
 24  
 import org.kuali.rice.krad.web.form.IncidentReportForm;
 25  
 import org.kuali.rice.krad.web.form.UifFormBase;
 26  
 import org.springframework.web.servlet.ModelAndView;
 27  
 
 28  
 import javax.servlet.http.HttpServletRequest;
 29  
 import javax.servlet.http.HttpServletResponse;
 30  
 
 31  
 /**
 32  
  * Spring Exception intercepter
 33  
  *
 34  
  * <p>
 35  
  * Gets the data needed for the incident report from the request and builds the
 36  
  * model and view for the incident report. This resolver intercepts any unhandled 
 37  
  * exception.
 38  
  * </p>
 39  
  * 
 40  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 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  
      * Builds the incident report model and view from the
 48  
      * request that threw the exception.
 49  
      * 
 50  
      * @param request
 51  
      *            the request
 52  
      * @param response
 53  
      *            the response
 54  
      * @param handler
 55  
      *            the current handler when the exception occurred
 56  
      * @param ex
 57  
      *            the exception
 58  
      * @return the incident report model and view
 59  
      * @see org.springframework.web.servlet.HandlerExceptionResolver#resolveException(javax.servlet.http.HttpServletRequest,
 60  
      *      javax.servlet.http.HttpServletResponse, java.lang.Object,
 61  
      *      java.lang.Exception)
 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  
         // log exception
 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  
         // Set the post url map to the incident report controller and not 
 82  
         // the one the exception occurred on
 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(!KRADUtils.isProductionEnvironment());
 94  
 
 95  
         // Set the view object
 96  0
         incidentReportForm.setView(getViewService().getView("Incident-Report",
 97  
                 incidentReportForm.getViewRequestParameters()));
 98  
 
 99  
         // Add a new History entry to avoid errors in the postHandle
 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  
         // Set render full view to force full render
 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  
 }