@Override
  public ActionForward start(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    ActionForward returnForward = super.execute(mapping, form, request, response);

    String docHandler = returnForward.getPath();
    if (PROPOSAL_DEVELOPMENT_DOCUMENT.equals(request.getParameter(DOCUMENT_TYPE_NAME))) {
      docHandler =
          docHandler.replace(KRADConstants.DOC_HANDLER_METHOD, Constants.PROPOSAL_ACTIONS_PAGE);
    } else if (PROTOCOL_DOCUMENT.equals(request.getParameter(DOCUMENT_TYPE_NAME))
        || IACUC_PROTOCOL_DOCUMENT.equals(request.getParameter(DOCUMENT_TYPE_NAME))) {
      docHandler =
          docHandler.replace(KRADConstants.DOC_HANDLER_METHOD, Constants.MAPPING_PROTOCOL_ACTIONS);
    } else if (AWARD_DOCUMENT.equals(request.getParameter(DOCUMENT_TYPE_NAME))) {
      docHandler =
          docHandler.replace(
              KRADConstants.DOC_HANDLER_METHOD, Constants.MAPPING_AWARD_ACTIONS_PAGE);
    }

    returnForward = new ActionForward(docHandler, returnForward.getRedirect());
    return returnForward;
  }
  public void processFormActionAndForward(
      final HttpServletRequest request,
      final HttpServletResponse response,
      final ActionMapping mapping)
      throws ServletException, IOException {
    ActionForm form = processActionForm(request, response, mapping);
    processPopulate(request, response, form, mapping);

    // Create or acquire the Action instance to process this request
    Action action = processActionCreate(request, response, mapping);

    if (action != null) {
      // Call the Action instance itself
      ActionForward forward = processActionPerform(request, response, action, form, mapping);

      if (forward != null) {
        if (forward.getRedirect()
            && forward.getName() != null
            && forward.getName().equals(KRADConstants.KRAD_INITIATED_DOCUMENT_VIEW_NAME)) {
          LOG.info("Attempt to open a document with a status of \"Initiated\" detected");
          return;
        }
        // ProcessDefinition the returned ActionForward instance
        processForwardConfig(request, response, forward);
      }
    }
  }
Beispiel #3
0
  public ActionForward rate(
      ActionMapping actionMapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Throwable {

    String itemNaturalKey = (String) request.getParameter("itemNaturalKey");
    String value = (String) request.getParameter("rate");
    ContentSessionBean contentSessionBean = getContentBean(request).getContentSessionBean();
    Site site = contentSessionBean.getSiteDomain().getSite();
    String siteId = site.getSiteId();
    if (value != null) {
      EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
      Item item = ItemDAO.loadNatural(siteId, itemNaturalKey);
      int itemRatingCount = item.getItemRatingCount().intValue();
      float itemRating = item.getItemRating().floatValue();

      int rate = Integer.parseInt(value);
      if (itemRatingCount != 0) {
        itemRating = ((itemRating * itemRatingCount) + rate) / (itemRatingCount + 1);
        itemRatingCount += 1;
      } else {
        itemRatingCount = 1;
        itemRating = rate;
      }
      item.setItemRating(new Float(itemRating));
      item.setItemRatingCount(new Integer(itemRatingCount));
      em.persist(item);
    }
    ActionForward forward = actionMapping.findForward("success");
    forward =
        new ActionForward(
            forward.getPath()
                + contentSessionBean.getSiteDomain().getSiteDomainPrefix()
                + "/"
                + contentSessionBean
                    .getSiteProfile()
                    .getSiteProfileClass()
                    .getSiteProfileClassName()
                + "/item/"
                + itemNaturalKey,
            forward.getRedirect());
    return forward;
  }
  /**
   * Makes HttpSession and GrouperSession available to subclasses Also handles pageSize parameter
   * and times how long is spent in an action
   */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    GrouperSession grouperSession =
        (GrouperSession)
            request.getSession().getAttribute("edu.intenet2.middleware.grouper.ui.GrouperSession");
    // if(grouperSession == null && !"/populateIndex.do".equals(request.getServletPath())) return
    // mapping.findForward("Index");

    ModuleConfig modConfig = (ModuleConfig) request.getAttribute("org.apache.struts.action.MODULE");
    String modulePrefix = modConfig.getPrefix();
    if (modulePrefix == null) modulePrefix = "";
    request.setAttribute("modulePrefix", modulePrefix);
    HttpSession session = request.getSession();
    String pageSize = request.getParameter("pageSize");
    if (pageSize != null && pageSize.length() > 0) {
      session.setAttribute("default.pagesize", pageSize);
    }

    DynaActionForm dummyForm = (DynaActionForm) form;
    if (dummyForm != null) {
      try {
        dummyForm.set("pageSize", "" + getPageSize(session));
      } catch (Exception e) {
        // Ok so form doesn't care about pageSize
        // let's just ignore it
      }
    }
    isWheelGroupMember(session);
    String wheelGroupAction = request.getParameter("wheelGroupAction");
    if (!isEmpty(wheelGroupAction)) doWheelGroupStuff(wheelGroupAction, session);
    UIThreadLocal.replace(
        "isActiveWheelGroupMember", new Boolean(isActiveWheelGroupMember(session)));

    if (grouperSession != null) {
      if (isWheelGroupMember(session)) {
        grouperSession.setConsiderIfWheelMember(isActiveWheelGroupMember(session));
      } else {
        // we'll set this back to the default
        grouperSession.setConsiderIfWheelMember(true);
      }
    }

    if (form != null) request.setAttribute("grouperForm", form);
    Object sessionMessage = session.getAttribute("sessionMessage");
    if (isEmpty(request.getAttribute("message")) && !isEmpty(sessionMessage)) {
      request.setAttribute("message", sessionMessage);
      session.removeAttribute("sessionMessage");
    }
    request.setAttribute("linkBrowseMode", getLinkBrowseMode(session));
    Date before = new Date();
    ActionForward forward = null;
    try {
      if (isEmpty(wheelGroupAction)) {

        forward =
            grouperTransactionExecute(mapping, form, request, response, session, grouperSession);

      } else
        forward =
            new ActionForward(
                GrouperUiFilter.retrieveSessionMediaResourceBundle().getString("admin.browse.path"),
                true);
    } catch (GrouperDAOException e) {
      Throwable cause = e.getCause();

      Throwable causeCause = cause == null ? null : cause.getCause();

      Throwable causeCauseCause = causeCause == null ? null : causeCause.getCause();

      HookVeto hookVeto = (cause instanceof HookVeto) ? (HookVeto) cause : null;

      hookVeto =
          ((hookVeto == null) && (causeCause instanceof HookVeto))
              ? (HookVeto) causeCause
              : hookVeto;

      hookVeto =
          ((hookVeto == null) && (causeCauseCause instanceof HookVeto))
              ? (HookVeto) causeCauseCause
              : hookVeto;

      if (hookVeto != null) {
        Message.addVetoMessageToScreen(request, hookVeto);
      } else if (!(cause instanceof UnrecoverableErrorException)) {
        LOG.error(NavExceptionHelper.toLog(cause));
        cause = new UnrecoverableErrorException(cause);
      }
      if (cause instanceof UnrecoverableErrorException) {
        NavExceptionHelper neh = getExceptionHelper(session);
        String msg = neh.getMessage((UnrecoverableErrorException) cause);
        request.setAttribute("seriousError", msg);
      }
      forward = mapping.findForward("ErrorPage");
    }
    Date after = new Date();
    long diff = after.getTime() - before.getTime();
    String url = request.getServletPath();
    Long ms = (Long) request.getAttribute("timingsMS");
    long mss = 0;
    if (ms != null) mss = ms.longValue();
    if (diff > 25) {
      request.setAttribute("timingsClass", this.getClass().getName());
      request.setAttribute("timingsMS", new Long(diff + mss));
    }
    if (forward != null && forward.getRedirect() && !isEmpty(request.getAttribute("message"))) {
      try {
        session.setAttribute("sessionMessage", request.getAttribute("message"));
      } catch (IllegalStateException e) {
      }
    }

    if (Boolean.TRUE.equals(request.getAttribute("loggedOut"))) {
      return forward;
    }
    try {
      GrouperHelper.fixSessionFields((Map) session.getAttribute("fieldList"));
    } catch (SchemaException e) {
      LOG.error(e);
    }
    String advSearch = request.getParameter("advancedSearch");
    try {
      session.getAttribute("");
    } catch (Exception e) {
      return forward;
    }
    if (!isEmpty(advSearch)) {
      setAdvancedSearchMode("true".equals(advSearch), session);
    }
    request.setAttribute("isAdvancedSearch", getAdvancedSearchMode(session));
    return forward;
  }
Beispiel #5
0
 /**
  * Return a new <code>ActionForward</code> based on the given one but with the specified parameter
  * name and value added to the new forward's path. NOTE: this method would be unnecessary if
  * Struts allowed us to "unfreeze" the <code>ForwardConfig</code> that is the superclass of the
  * forward.
  *
  * @param forward the ActionForward on which the new forward is based
  * @param param the name of the path parameter to add
  * @param value the value of the parameter to add
  * @exception ServletException if encoding the path parameter fails
  */
 public static ActionForward changeForwardPath(ActionForward forward, Map params)
     throws Exception {
   String newUrl = changeUrl(forward.getPath(), params);
   ActionForward newForward = new ActionForward(forward.getName(), newUrl, forward.getRedirect());
   return newForward;
 }
Beispiel #6
0
  public ActionForward executeAction(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response,
      SessionAPI session)
      throws Exception {

    // Comprobar si el usuario tiene asignadas las funciones adecuadas
    FunctionHelper.checkFunctions(
        request, session.getClientContext(), new int[] {ISecurityAPI.FUNC_INV_PROCEDURES_EDIT});

    int intTpObj = Integer.parseInt(request.getParameter("TpObj"));
    int intIdObj = Integer.parseInt(request.getParameter("IdObj"));

    // Prepara las API's a utilizar
    IInvesflowAPI invesFlowAPI = session.getAPI();
    ICatalogAPI catalogAPI = invesFlowAPI.getCatalogAPI();

    if (request.getParameter("idRule") != null) {
      catalogAPI.addPRuleEvent(
          intTpObj,
          intIdObj,
          Integer.parseInt(request.getParameter("codEvent")),
          Integer.parseInt(request.getParameter("idRule")));

      ActionForward forward = mapping.findForward("showevents");
      String path = forward.getPath() + "?TpObj=" + intTpObj + "&IdObj=" + intIdObj;
      return new ActionForward(forward.getName(), path, forward.getRedirect());
    }

    request.setAttribute("TpObj", String.valueOf(intTpObj));
    request.setAttribute("IdObj", String.valueOf(intIdObj));

    CacheFormatterFactory factory = CacheFormatterFactory.getInstance();
    String ispacbase = (String) servlet.getServletContext().getAttribute("ispacbase");

    if (request.getParameter("codEvent") != null) {
      request.setAttribute("codEvent", request.getParameter("codEvent"));
      IItemCollection rulecol = catalogAPI.getCTRules();
      List rulelist = CollectionBean.getBeanList(rulecol);

      request.setAttribute("RulesList", rulelist);

      BeanFormatter formatter =
          factory.getFormatter(getISPACPath("/formatters/events/ruleslistformatter.xml"));

      request.setAttribute("RulesListFormatter", formatter);
      request.setAttribute(
          "application", StaticContext.rewritePage(ispacbase, "common/events/ruleslist.jsp"));
    } else {
      List eventlist = DescriptionsPEvents.getDescEventsList(intTpObj, intIdObj);
      request.setAttribute("EventsList", eventlist);

      BeanFormatter formatter =
          factory.getFormatter(getISPACPath("/formatters/events/eventslistformatter.xml"));

      request.setAttribute("EventsListFormatter", formatter);
      request.setAttribute(
          "application", StaticContext.rewritePage(ispacbase, "common/events/eventslist.jsp"));
    }

    return mapping.findForward("success");
  }
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    // User making this request
    User user = UserUtils.getUser(request);
    if (user == null) {
      ActionErrors errors = new ActionErrors();
      errors.add("username", new ActionMessage("error.login.notloggedin"));
      saveErrors(request, errors);
      return mapping.findForward("authenticate");
    }

    // we need a projectID so that we can restrict access to researchers on a project
    int projectId = 0;
    try {
      projectId = Integer.parseInt(request.getParameter("projectId"));
    } catch (NumberFormatException e) {
      projectId = 0;
    }
    if (projectId == 0) {
      ActionErrors errors = new ActionErrors();
      errors.add(
          "payment", new ActionMessage("error.payment.invalidid", "Invalid projectID in request"));
      saveErrors(request, errors);
      return mapping.findForward("standardHome");
    }

    // user should be an admin OR a researcher on the project
    Project project = ProjectFactory.getProject(projectId);
    if (!project.checkAccess(user.getResearcher())) {
      ActionErrors errors = new ActionErrors();
      errors.add(
          "payment",
          new ActionMessage(
              "error.payment.invalidaccess",
              "User does not have access to view details of the payment method."));
      saveErrors(request, errors);
      ActionForward fwd = mapping.findForward("Failure");
      ActionForward newFwd =
          new ActionForward(fwd.getPath() + "?ID=" + projectId, fwd.getRedirect());
      return newFwd;
    }

    // we need a paymentMethodId
    int paymentMethodId = 0;
    try {
      paymentMethodId = Integer.parseInt(request.getParameter("paymentMethodId"));
    } catch (NumberFormatException e) {
      paymentMethodId = 0;
    }
    if (paymentMethodId == 0) {
      ActionErrors errors = new ActionErrors();
      errors.add(
          "payment",
          new ActionMessage("error.payment.invalidid", "Invalid paymentMethodID in request"));
      saveErrors(request, errors);
      ActionForward fwd = mapping.findForward("Failure");
      ActionForward newFwd =
          new ActionForward(fwd.getPath() + "?ID=" + projectId, fwd.getRedirect());
      return newFwd;
    }

    try {
      PaymentMethod paymentMethod =
          PaymentMethodDAO.getInstance().getPaymentMethod(paymentMethodId);
      request.setAttribute("paymentMethod", paymentMethod);
      request.setAttribute("projectId", projectId);
    } catch (Exception e) {
      ActionErrors errors = new ActionErrors();
      errors.add("payment", new ActionMessage("error.payment.load", "ERROR: " + e.getMessage()));
      saveErrors(request, errors);
      log.error("Error loading payment method for ID: " + paymentMethodId, e);
      ActionForward fwd = mapping.findForward("Failure");
      ActionForward newFwd =
          new ActionForward(fwd.getPath() + "?ID=" + projectId, fwd.getRedirect());
      return newFwd;
    }

    return mapping.findForward("Success");
  }