private ActionMessages processForm(
      User user, Server server, DynaActionForm f, HttpServletRequest request) {
    if (log.isDebugEnabled()) {
      log.debug("Processing form.");
    }

    // scheduleScriptRun takes a list of servers
    List servers = new ArrayList();
    servers.add(server);

    ActionMessages msgs = new ActionMessages();

    Boolean submitted = (Boolean) f.get("submitted");
    String runBefore = (String) f.get("run_script");
    String username = (String) f.get("username");
    String group = (String) f.get("group");
    Long timeout = (Long) f.get("timeout");
    String script = (String) f.get("script");
    String sessionSetLabel = (String) f.get("session_set_label");
    String mode = (String) f.get("mode");

    if (log.isDebugEnabled()) {
      log.debug("submitted [" + submitted + "]");
      log.debug("runBefore [" + runBefore + "]");
      log.debug("username [" + username + "]");
      log.debug("group [" + group + "]");
      log.debug("timeout [" + timeout + "]");
      log.debug("script [" + script + "]");
      log.debug("mode [" + mode + "]");
    }

    // The earliest time to perform the action.
    Date earliest = getStrutsDelegate().readDatePicker(f, "date", DatePicker.YEAR_RANGE_POSITIVE);

    if (BEFORE.equals(runBefore)) {
      ScriptActionDetails sad = ActionManager.createScript(username, group, timeout, script);
      ScriptRunAction sra = ActionManager.scheduleScriptRun(user, servers, "", sad, earliest);
      List<Map<String, Long>> packs = getPackages(user, request, sessionSetLabel);
      int numPackages = packs.size();
      PackageAction pa = schedulePackageAction(user, server, packs, mode, earliest);
      pa.setPrerequisite(sra);
      ActionManager.storeAction(pa);
      showMessages(msgs, pa, server, numPackages, mode);
      showRemoteCommandMsg(msgs, true, mode);
    } else {
      List<Map<String, Long>> packs = getPackages(user, request, sessionSetLabel);
      int numPackages = packs.size();
      PackageAction pa = schedulePackageAction(user, server, packs, mode, earliest);
      ScriptActionDetails sad = ActionManager.createScript(username, group, timeout, script);
      ScriptRunAction sra = ActionManager.scheduleScriptRun(user, servers, "", sad, earliest);
      sra.setPrerequisite(pa);
      ActionManager.storeAction(sra);
      showMessages(msgs, sra, server, numPackages, mode);
      showRemoteCommandMsg(msgs, false, mode);
    }
    SessionSetHelper.obliterate(request, sessionSetLabel);
    return msgs;
  }
  /**
   * Executes the appropriate PackageAction
   *
   * @param mapping ActionMapping
   * @param formIn ActionForm
   * @param request ServletRequest
   * @param response ServletResponse
   * @return The ActionForward to go to next.
   */
  public ActionForward executePackageAction(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext requestContext = new RequestContext(request);
    StrutsDelegate strutsDelegate = getStrutsDelegate();

    Long sid = requestContext.getRequiredParam("sid");
    User user = requestContext.getCurrentUser();
    // updateList(newactions, user.getId());

    List<Map<String, Long>> data = PackageListItem.toKeyMaps(getDataResult(request));
    int numPackages = data.size();

    // Archive the actions
    Server server = SystemManager.lookupByIdAndUser(sid, user);

    // The earliest time to perform the action.
    DynaActionForm dynaActionForm = (DynaActionForm) formIn;
    Date earliest =
        getStrutsDelegate().readDatePicker(dynaActionForm, "date", DatePicker.YEAR_RANGE_POSITIVE);

    // The action chain to append this action to, if any
    ActionChain actionChain = ActionChainHelper.readActionChain(dynaActionForm, user);

    PackageAction pa = schedulePackageAction(formIn, requestContext, data, earliest, actionChain);

    // Remove the actions from the users set
    SessionSetHelper.obliterate(request, getDecl(sid));

    ActionMessages msgs = new ActionMessages();

    if (actionChain == null) {
      /**
       * If there was only one action archived, display the "action" archived message, else display
       * the "actions" archived message.
       */
      if (numPackages == 1) {
        msgs.add(
            ActionMessages.GLOBAL_MESSAGE,
            new ActionMessage(
                getMessageKeyForOne(),
                LocalizationService.getInstance().formatNumber(numPackages),
                pa.getId().toString(),
                sid.toString(),
                StringUtil.htmlifyText(server.getName())));
      } else {
        msgs.add(
            ActionMessages.GLOBAL_MESSAGE,
            new ActionMessage(
                getMessageKeyForMany(),
                LocalizationService.getInstance().formatNumber(numPackages),
                pa.getId().toString(),
                sid.toString(),
                StringUtil.htmlifyText(server.getName())));
      }
    } else {
      msgs.add(
          ActionMessages.GLOBAL_MESSAGE,
          new ActionMessage(
              "message.addedtoactionchain",
              actionChain.getId(),
              StringUtil.htmlifyText(actionChain.getLabel())));
    }

    strutsDelegate.saveMessages(request, msgs);
    Map params = new HashMap();
    processParamMap(formIn, request, params);
    return strutsDelegate.forwardParams(mapping.findForward(RhnHelper.CONFIRM_FORWARD), params);
  }