Пример #1
0
 @SuppressWarnings("unchecked")
 public Map<String, Collection<SoftError>> getSoftErrors() {
   UserSession session = GlobalVariables.getUserSession();
   Object o = session.retrieveObject(KeyConstants.SOFT_ERRORS_KEY);
   Map<String, Collection<SoftError>> softErrors = (Map<String, Collection<SoftError>>) o;
   if (softErrors == null) {
     softErrors = initializeSoftErrorMap();
   }
   return softErrors;
 }
Пример #2
0
  /**
   * Checks for return from a lookup or question, and restores the action form stored under the
   * request parameter docFormKey.
   */
  @Override
  protected ActionForm processActionForm(
      HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) {

    String documentNumber = getDocumentNumber(request);
    if (documentNumber != null) {
      MDC.put(MDC_DOC_ID, documentNumber);
    }

    UserSession userSession =
        (UserSession) request.getSession().getAttribute(KRADConstants.USER_SESSION_KEY);

    String docFormKey = request.getParameter(KRADConstants.DOC_FORM_KEY);
    String methodToCall = request.getParameter(KRADConstants.DISPATCH_REQUEST_PARAMETER);
    String refreshCaller = request.getParameter(KRADConstants.REFRESH_CALLER);
    //		String searchListRequestKey = request.getParameter(KRADConstants.SEARCH_LIST_REQUEST_KEY);
    String documentWebScope = request.getParameter(KRADConstants.DOCUMENT_WEB_SCOPE);

    if (mapping.getPath().startsWith(KRADConstants.REFRESH_MAPPING_PREFIX)
        || KRADConstants.RETURN_METHOD_TO_CALL.equalsIgnoreCase(methodToCall)
        || KRADConstants.QUESTION_REFRESH.equalsIgnoreCase(refreshCaller)
        || KRADConstants.TEXT_AREA_REFRESH.equalsIgnoreCase(refreshCaller)
        || KRADConstants.SESSION_SCOPE.equalsIgnoreCase(documentWebScope)) {
      ActionForm form = null;
      // check for search result storage and clear
      GlobalVariables.getUserSession().removeObjectsByPrefix(KRADConstants.SEARCH_LIST_KEY_PREFIX);

      // We put different type of forms such as document form, lookup form
      // in session but we only store document form in
      // database.
      if (userSession.retrieveObject(docFormKey) != null) {
        LOG.debug("getDecomentForm KualiDocumentFormBase from session");
        form = (ActionForm) userSession.retrieveObject(docFormKey);
      } else if (StringUtils.isNotBlank(documentNumber)) {
        form =
            getSessionDocumentService()
                .getDocumentForm(documentNumber, docFormKey, userSession, request.getRemoteAddr());
      }
      request.setAttribute(mapping.getAttribute(), form);
      if (!KRADConstants.SESSION_SCOPE.equalsIgnoreCase(documentWebScope)) {
        userSession.removeObject(docFormKey);
      }
      // we should check whether this is a multipart request because we
      // could have had a combination of query parameters and a multipart
      // request
      String contentType = request.getContentType();
      String method = request.getMethod();
      if (("POST".equalsIgnoreCase(method)
          && contentType != null
          && contentType.startsWith("multipart/form-data"))) {
        // this method parses the multipart request and adds new
        // non-file parameters into the request
        WebUtils.getMultipartParameters(request, null, form, mapping);
      }
      // The form can be null if the document is not a session document
      if (form != null) {
        return form;
      }
    }

    // Rice has the ability to limit file upload sizes on a per-form basis,
    // so the max upload sizes may be accessed by calling methods on
    // PojoFormBase.
    // This requires that we are able know the file upload size limit (i.e.
    // retrieve a form instance) before we parse a mulitpart request.
    ActionForm form = super.processActionForm(request, response, mapping);

    // for sessiondocument with multipart request
    String contentType = request.getContentType();
    String method = request.getMethod();

    if ("GET".equalsIgnoreCase(method)
        && StringUtils.isNotBlank(methodToCall)
        && form instanceof PojoForm
        && ((PojoForm) form)
            .getMethodToCallsToBypassSessionRetrievalForGETRequests()
            .contains(methodToCall)) {
      return createNewActionForm(mapping, request);
    }

    // if we have a multipart request, parse it and return the stored form
    // from session if the doc form key is not blank. If it is blank, then
    // we just return the form
    // generated from the superclass processActionForm method. Either way,
    // we need to parse the mulitpart request now so that we may determine
    // what the value of the doc form key is.
    // This is generally against the contract of processActionForm, because
    // processPopulate should be responsible for parsing the mulitpart
    // request, but we need to parse it now
    // to determine the doc form key value.
    if (("POST".equalsIgnoreCase(method)
        && contentType != null
        && contentType.startsWith("multipart/form-data"))) {
      WebUtils.getMultipartParameters(request, null, form, mapping);
      docFormKey = request.getParameter(KRADConstants.DOC_FORM_KEY);
      documentWebScope = request.getParameter(KRADConstants.DOCUMENT_WEB_SCOPE);

      documentNumber = getDocumentNumber(request);

      if (KRADConstants.SESSION_SCOPE.equalsIgnoreCase(documentWebScope)
          || (form instanceof KualiDocumentFormBase
              && WebUtils.isDocumentSession(
                  ((KualiDocumentFormBase) form).getDocument(), (KualiDocumentFormBase) form))) {

        Object userSessionObject = userSession.retrieveObject(docFormKey);
        if (userSessionObject != null && userSessionObject instanceof ActionForm) {
          LOG.debug("getDocumentForm KualiDocumentFormBase from session");
          form = (ActionForm) userSessionObject;
        } else {
          ActionForm tempForm =
              getSessionDocumentService()
                  .getDocumentForm(
                      documentNumber, docFormKey, userSession, request.getRemoteAddr());
          if (tempForm != null) {
            form = tempForm;
          }
        }

        request.setAttribute(mapping.getAttribute(), form);
        if (form != null) {
          return form;
        }
      }
    }
    return form;
  }
  /**
   * Builds the incident report model and view from the request that threw the exception
   *
   * @param request - the request
   * @param response - the response
   * @param handler - the current handler when the exception occurred
   * @param ex - the exception
   * @return the incident report model and view
   * @see
   *     org.springframework.web.servlet.HandlerExceptionResolver#resolveException(javax.servlet.http.HttpServletRequest,
   *     javax.servlet.http.HttpServletResponse, java.lang.Object, java.lang.Exception)
   */
  @Override
  public ModelAndView resolveException(
      HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
    LOG.error("The following error was caught by the UifHandlerExceptionResolver : ", ex);

    // log exception
    LOG.error(ex.getMessage(), ex);

    String incidentDocId = request.getParameter(KRADConstants.DOCUMENT_DOCUMENT_NUMBER);
    String incidentViewId = "";

    UifFormBase form = (UifFormBase) request.getAttribute(UifConstants.REQUEST_FORM);
    if (form instanceof DocumentFormBase) {
      if (((DocumentFormBase) form).getDocument() != null) {
        incidentDocId = ((DocumentFormBase) form).getDocument().getDocumentNumber();
      }
      incidentViewId = ((DocumentFormBase) form).getViewId();
    }

    if (GlobalVariables.getUifFormManager() != null) {
      GlobalVariables.getUifFormManager().removeSessionForm(form);
    }

    UserSession userSession =
        (UserSession) request.getSession().getAttribute(KRADConstants.USER_SESSION_KEY);
    IncidentReportForm incidentReportForm = new IncidentReportForm();
    incidentReportForm.setSessionId(request.getSession().getId());

    // Set the post url map to the incident report controller and not
    // the one the exception occurred on
    String postUrl = request.getRequestURL().toString();
    postUrl = postUrl.substring(0, postUrl.lastIndexOf("/")) + "/incidentReport";
    incidentReportForm.setFormPostUrl(postUrl);

    incidentReportForm.setException(ex);
    incidentReportForm.setIncidentDocId(incidentDocId);
    incidentReportForm.setIncidentViewId(incidentViewId);
    incidentReportForm.setController(handler.getClass().toString());

    if (userSession != null) {
      incidentReportForm.setUserId(userSession.getPrincipalId());
      incidentReportForm.setUserName(userSession.getPrincipalName());
      incidentReportForm.setUserEmail(userSession.getPerson().getEmailAddress());
    }

    incidentReportForm.setDevMode(!KRADUtils.isProductionEnvironment());
    incidentReportForm.setViewId("Uif-IncidentReportView");

    if (form != null) {
      incidentReportForm.setAjaxRequest(form.isAjaxRequest());
    } else {
      String ajaxRequestParm = request.getParameter(UifParameters.AJAX_REQUEST);
      if (StringUtils.isNotBlank(ajaxRequestParm)) {
        incidentReportForm.setAjaxRequest(Boolean.parseBoolean(ajaxRequestParm));
      }
    }

    // Set the view object
    incidentReportForm.setView(getViewService().getViewById("Uif-IncidentReportView"));

    // Set the ajax return type
    incidentReportForm.setAjaxReturnType(UifConstants.AjaxReturnTypes.UPDATEVIEW.getKey());

    ModelAndView modelAndView = getModelAndViewService().getModelAndView(incidentReportForm, "");
    try {
      getModelAndViewService().prepareView(request, modelAndView);
    } catch (Exception e) {
      LOG.error("An error stopped the incident form from loading", e);
    }

    return modelAndView;
  }