private void showMessages(
      ActionMessages msgs, Action action, Server server, int pkgcnt, String mode) {
    String key = null;

    if (MODE_INSTALL.equals(mode)) {
      key = "message.packageinstall";
    } else if (MODE_REMOVAL.equals(mode)) {
      key = "message.packageremoval";
    } else { // must be upgrade
      key = "message.packageupgrade";
    }

    /**
     * If there was only one action archived, display the "action" archived message, else display
     * the "actions" archived message.
     */
    if (pkgcnt == 1) {
      msgs.add(
          ActionMessages.GLOBAL_MESSAGE,
          new ActionMessage(
              key,
              LocalizationService.getInstance().formatNumber(new Integer(pkgcnt)),
              action.getId().toString(),
              server.getId().toString(),
              server.getName()));
    } else {
      msgs.add(
          ActionMessages.GLOBAL_MESSAGE,
          new ActionMessage(
              key + "s",
              LocalizationService.getInstance().formatNumber(new Integer(pkgcnt)),
              action.getId().toString(),
              server.getId().toString(),
              server.getName()));
    }
  }
  /**
   * Setup the system for provisioning with cobbler.
   *
   * @param mapping ActionMapping for struts
   * @param form DynaActionForm representing the form
   * @param ctx RequestContext request context
   * @param response HttpServletResponse response object
   * @param step WizardStep what step are we on?
   * @return ActionForward struts action forward
   * @throws Exception if something goes amiss
   */
  public ActionForward runFourth(
      ActionMapping mapping,
      DynaActionForm form,
      RequestContext ctx,
      HttpServletResponse response,
      WizardStep step)
      throws Exception {

    log.debug("runFourth");
    if (!validateFirstSelections(form, ctx)) {
      return runFirst(mapping, form, ctx, response, step);
    }
    Long sid = (Long) form.get(RequestContext.SID);
    String cobblerId = form.getString(RequestContext.COBBLER_ID);

    log.debug("runFourth.cobblerId: " + cobblerId);

    User user = ctx.getCurrentUser();
    Server server = SystemManager.lookupByIdAndUser(sid, user);

    Map params = new HashMap();
    params.put(RequestContext.SID, sid);

    log.debug("Creating cobbler system record");
    org.cobbler.Profile profile =
        org.cobbler.Profile.lookupById(CobblerXMLRPCHelper.getConnection(user), cobblerId);

    KickstartData data =
        KickstartFactory.lookupKickstartDataByCobblerIdAndOrg(user.getOrg(), profile.getUid());

    if (showDiskWarning(data, form)) {
      form.set(NEXT_ACTION, "fourth");
      return mapping.findForward("fifth");
    }

    CobblerSystemCreateCommand cmd =
        new CobblerSystemCreateCommand(server, profile.getName(), data);
    cmd.store();
    log.debug("cobbler system record created.");
    String[] args = new String[2];
    args[0] = server.getName();
    args[1] = profile.getName();
    createMessage(ctx.getRequest(), "kickstart.schedule.cobblercreate", args);
    return getStrutsDelegate().forwardParams(mapping.findForward("cobbler-success"), params);
  }
  /**
   * Do the validation needed for this command. This ensures that the system hosting the kickstart
   * has the necessary resources to do so.
   *
   * @return Returns a ValidatorError, if any errors occur
   */
  public ValidatorError doValidation() {
    ValidatorError error = validateNetworkInterface();
    if (error != null) {
      return error;
    }
    if (isCobblerOnly()) {
      return null;
    }
    Server hostServer = getHostServer();

    // Check base channel.
    log.debug("** Checking basechannel.");
    if (hostServer.getBaseChannel() == null) {
      return new ValidatorError("kickstart.schedule.nobasechannel", hostServer.getName());
    }

    // Check that we have a valid ks package
    log.debug("** Checking validkspackage");
    error = validateKickstartPackage();
    if (error != null) {
      return error;
    }

    if (ksdata.isRhel()) {
      // Check that we have a valid up2date version
      log.debug("** Checking valid up2date");
      error = validateUp2dateVersion();
      if (error != null) {
        return error;
      }
    }

    // we already shall be subscribed to the tools channel
    // (since validateKickstartPackage), so no other actions needed
    return null;
  }
  // Check to make sure up2date is 2.9.0
  protected ValidatorError validateUp2dateVersion() {
    Server hostServer = getHostServer();
    List packages = PackageManager.systemPackageList(hostServer.getId(), null);
    if (packages != null) {
      log.debug("    packages.size() : " + packages.size());
    }
    // PackageListItem
    Iterator i = packages.iterator();
    String up2dateepoch = null;
    String up2dateversion = null;
    String up2daterelease = null;

    while (i.hasNext()) {
      PackageListItem pli = (PackageListItem) i.next();
      if (pli.getName().equals("yum-rhn-plugin")) {
        // found yum-rhn-plugin - returning
        return null;
      }
      if (pli.getName().equals("zypp-plugin-spacewalk")) {
        // found zypp-plugin-spacewalk - returning
        return null;
      }

      if (pli.getName().equals("up2date")) {
        log.debug("    found up2date ...");
        up2dateepoch = pli.getEpoch();
        up2dateversion = pli.getVersion();
        up2daterelease = pli.getRelease();

        log.debug("    e: " + up2dateepoch + " v: " + up2dateversion + " r : " + up2daterelease);
      }
    }

    if (up2dateepoch == null && up2dateversion == null && up2daterelease == null) {
      Object[] args = new Object[2];
      args[0] = hostServer.getId();
      args[1] = hostServer.getName();
      return new ValidatorError("kickstart.schedule.noup2date", args);
    }

    up2dateepoch = up2dateepoch == null ? "0" : up2dateepoch;
    up2dateversion = up2dateversion == null ? "0" : up2dateversion;
    up2daterelease = up2daterelease == null ? "0" : up2daterelease;

    int comp =
        PackageManager.verCmp(
            up2dateepoch, up2dateversion, up2daterelease, "0", UP2DATE_VERSION, "0");
    log.debug("    Got back comp from verCmp: " + comp);
    if (comp < 0) {
      Long packageId =
          PackageManager.getServerNeededUpdatePackageByName(hostServer.getId(), "up2date");
      if (packageId == null) {
        Object[] args = new Object[2];
        args[0] = UP2DATE_VERSION;
        args[1] = up2dateversion;
        return new ValidatorError("kickstart.schedule.noup2dateinchannel", args);
      }
      Package p = PackageFactory.lookupByIdAndUser(packageId, this.user);

      Map evrmap = new HashMap();
      evrmap.put("name_id", p.getPackageName().getId());
      evrmap.put("evr_id", p.getPackageEvr().getId());
      evrmap.put("arch_id", p.getPackageArch().getId());
      packagesToInstall.add(evrmap);
    } else {
      return null;
    }

    return null;
  }
  /**
   * 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);
  }