private PackageAction syncToVictim(
      RequestContext requestContext, Long sid, Set pkgIdCombos, String option) {

    PackageAction pa = null;
    Date time = new Date(requestContext.getParamAsLong("time"));

    if (isProfileSync(requestContext)) {
      Long prid = requestContext.getRequiredParam("prid");

      pa =
          ProfileManager.syncToProfile(
              requestContext.getCurrentUser(), sid, prid, pkgIdCombos, option, time);

      if (pa == null) {
        createMessage(requestContext.getRequest(), "message.nopackagestosync");
        return null;
      }

      List args = new ArrayList();
      args.add(sid.toString());
      args.add(pa.getId().toString());
      args.add(requestContext.lookupAndBindServer().getName());
      args.add(
          ProfileManager.lookupByIdAndOrg(prid, requestContext.getCurrentUser().getOrg())
              .getName());

      createMessage(requestContext.getRequest(), "message.syncpackages", args);
    } else if (isSystemSync(requestContext)) {
      Long sid1 = requestContext.getRequiredParam("sid_1");
      pa =
          ProfileManager.syncToSystem(
              requestContext.getCurrentUser(), sid, sid1, pkgIdCombos, option, time);

      if (pa == null) {
        createMessage(requestContext.getRequest(), "message.nopackagestosync");
        return null;
      }

      List args = new ArrayList();
      args.add(sid.toString());
      args.add(pa.getId().toString());
      args.add(requestContext.lookupAndBindServer().getName());
      args.add(SystemManager.lookupByIdAndUser(sid1, requestContext.getCurrentUser()).getName());

      createMessage(requestContext.getRequest(), "message.syncpackages", args);
    }

    addHardwareMessage(pa, requestContext);

    return pa;
  }
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext rc = new RequestContext(request);
    User user = rc.getLoggedInUser();

    Channel chan = ChannelManager.lookupByIdAndUser(rc.getRequiredParam(RequestContext.CID), user);

    try {
      ChannelManager.verifyChannelAdmin(user, chan.getId());
    } catch (InvalidChannelRoleException e) {
      addMessage(request, e.getMessage());
      return mapping.findForward("default");
    }

    ListRhnSetHelper helper =
        new ListRhnSetHelper(this, request, RhnSetDecl.ERRATA_TO_SYNC.createCustom(chan.getId()));

    helper.execute();
    if (helper.isDispatched()) {
      Map params = new HashMap();
      params.put(RequestContext.CID, chan.getId());
      return getStrutsDelegate().forwardParams(mapping.findForward("submit"), params);
    }

    request.setAttribute("channel_name", chan.getName());
    request.setAttribute(RequestContext.CID, chan.getId());
    return mapping.findForward("default");
  }
  /** {@inheritDoc} */
  public List getResult(RequestContext context) {
    User user = context.getLoggedInUser();
    Channel chan =
        ChannelManager.lookupByIdAndUser(context.getRequiredParam(RequestContext.CID), user);

    return ChannelManager.listErrataNeedingResync(chan, user);
  }
 /** {@inheritDoc} */
 protected void processParamMap(ActionForm formIn, HttpServletRequest request, Map params) {
   RequestContext requestContext = new RequestContext(request);
   Long sid = requestContext.getRequiredParam("sid");
   params.put("sid", sid);
   getStrutsDelegate()
       .rememberDatePicker(
           params, (DynaActionForm) formIn, "date", DatePicker.YEAR_RANGE_POSITIVE);
 }
  /** {@inheritDoc} */
  protected DataResult getDataResult(User user, ActionForm formIn, HttpServletRequest request) {
    RequestContext requestContext = new RequestContext(request);
    Long sid = requestContext.getRequiredParam("sid");
    Set<String> pkgIdCombos = SessionSetHelper.lookupAndBind(request, getDecl(requestContext, sid));

    if (isProfileSync(requestContext)) {
      Long prid = requestContext.getRequiredParam("prid");

      return ProfileManager.getMissingProfilePackages(
          requestContext.getCurrentUser(), sid, prid, pkgIdCombos, null);
    } else if (isSystemSync(requestContext)) {
      Long sid1 = requestContext.getRequiredParam("sid_1");

      return ProfileManager.getMissingSystemPackages(
          requestContext.getCurrentUser(), sid, sid1, pkgIdCombos, null);
    }

    return null;
  }
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext context = new RequestContext(request);
    User user = context.getCurrentUser();

    long cid = context.getRequiredParam("cid");
    Channel chan = ChannelFactory.lookupByIdAndUser(cid, user);
    request.setAttribute("channel_name", chan.getName());
    request.setAttribute("cid", chan.getId());

    Map<String, Object> params = new HashMap<String, Object>();
    params.put(RequestContext.CID, chan.getId().toString());

    ListSessionSetHelper helper = new ListSessionSetHelper(this, request, params);

    if (!context.isSubmitted()) {
      List<ContentSource> result = getResult(context);
      Set<String> preSelect = new HashSet<String>();
      for (int i = 0; i < result.size(); i++) {
        ContentSource src = result.get(i);
        if (src.getChannels().contains(chan)) {
          preSelect.add(src.getId().toString());
        }
      }
      helper.preSelect(preSelect);
    }

    helper.ignoreEmptySelection();
    helper.execute();

    if (helper.isDispatched()) {
      Set<ContentSource> foo = chan.getSources();
      foo.clear();
      Set<String> set = helper.getSet();
      for (String id : set) {
        Long sgid = Long.valueOf(id);
        ContentSource tmp = ChannelFactory.lookupContentSource(sgid, user.getOrg());
        foo.add(tmp);
      }

      ChannelFactory.save(chan);

      StrutsDelegate strutsDelegate = getStrutsDelegate();
      strutsDelegate.saveMessage(
          "channel.edit.repo.updated", new String[] {chan.getName()}, request);

      return strutsDelegate.forwardParams(mapping.findForward("success"), params);
    }

    return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
  }
  private List<PackageListItem> getDataResult(HttpServletRequest request) {
    RequestContext requestContext = new RequestContext(request);

    Long sid = requestContext.getRequiredParam("sid");

    Set<String> data = SessionSetHelper.lookupAndBind(request, getDecl(sid));
    List<PackageListItem> items = new LinkedList<PackageListItem>();
    for (String key : data) {
      items.add(PackageListItem.parse(key));
    }
    return items;
  }
  /** {@inheritDoc} */
  @Override
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext requestContext = new RequestContext(request);
    Server server = requestContext.lookupAndBindServer();
    Long aid = requestContext.getRequiredParam("aid");

    request.setAttribute("aid", aid);
    request.setAttribute("referrerLink", "History.do");
    request.setAttribute("linkLabel", "system.event.return");
    request.setAttribute("headerLabel", "system.event.header");

    Action action;
    ServerAction serverAction;
    try {
      action = ActionManager.lookupAction(requestContext.getCurrentUser(), aid);
      serverAction = ActionFactory.getServerActionForServerAndAction(server, action);
    } catch (LookupException e) {
      ServerHistoryEvent event = ActionFactory.lookupHistoryEventById(aid);
      request.setAttribute("actiontype", event.getSummary());
      request.setAttribute("earliestaction", event.getCreated());
      request.setAttribute("actionnotes", event.getDetails());
      request.setAttribute("failed", false);
      return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
    }
    ActionFormatter af = action.getFormatter();
    request.setAttribute("actionname", af.getName());
    request.setAttribute("actiontype", af.getActionType());
    request.setAttribute("scheduler", af.getScheduler());
    request.setAttribute("earliestaction", af.getEarliestDate());
    request.setAttribute("actionnotes", af.getDetails(server, requestContext.getCurrentUser()));
    request.setAttribute("failed", serverAction.getStatus().equals(ActionFactory.STATUS_FAILED));
    if (!serverAction.getStatus().equals(ActionFactory.STATUS_COMPLETED)
        && !serverAction.getStatus().equals(ActionFactory.STATUS_FAILED)) {
      request.setAttribute("referrerLink", "Pending.do");
      request.setAttribute("linkLabel", "system.event.pendingReturn");
      request.setAttribute("headerLabel", "system.event.pendingHeader");
    }
    if (isSubmitted((DynaActionForm) formIn)) {
      createSuccessMessage(request, "system.event.rescheduled", action.getName());
      ActionFactory.rescheduleSingleServerAction(action, 5L, server.getId());
      return mapping.findForward("continue");
    }

    return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
  }
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {
    RequestContext context = new RequestContext(request);
    User user = context.getCurrentUser();
    Long sid = context.getRequiredParam("sid");
    Server server = SystemManager.lookupByIdAndUser(sid, user);
    Long xid = context.getRequiredParam("xid");
    XccdfTestResult testResult = ScapFactory.lookupTestResultByIdAndSid(xid, server.getId());
    request.setAttribute("testResult", testResult);
    request.setAttribute("system", server);

    ListHelper helper = new ListHelper(this, request);
    helper.execute();

    request.setAttribute(
        ListTagHelper.PARENT_URL, request.getRequestURI() + "?sid=" + sid + "&xid=" + xid);
    SdcHelper.ssmCheck(request, sid, user);

    return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
  }
  /**
   * Callback for the Subscribe to channels button, it attempts to subscribe to the channels
   * containing the Packages.
   *
   * @param mapping ActionMapping
   * @param formIn ActionForm
   * @param request HttpServletRequest
   * @param response HttpServletResponse
   * @return ActionForward
   */
  public ActionForward subscribeToChannels(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {
    RequestContext requestContext = new RequestContext(request);
    Long sid = requestContext.getRequiredParam("sid");
    Set<String> pkgIdCombos = SessionSetHelper.lookupAndBind(request, getDecl(requestContext, sid));
    Map params = new HashMap();
    params.put("sid", sid);

    syncToVictim(requestContext, sid, pkgIdCombos, ProfileManager.OPTION_SUBSCRIBE);
    return getStrutsDelegate().forwardParams(mapping.findForward("showprofile"), params);
  }
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext requestContext = new RequestContext(request);
    User user = requestContext.getCurrentUser();
    Long sid = requestContext.getRequiredParam("sid");
    RhnSet set = getSetDecl(sid).get(user);

    ListRhnSetHelper help = new ListRhnSetHelper(this, request, getSetDecl(sid));
    help.setListName(LIST_NAME);
    String parentURL = request.getRequestURI() + "?sid=" + sid;
    help.setParentUrl(parentURL);

    help.execute();

    if (help.isDispatched()) {
      if (requestContext.wasDispatched("errata.jsp.apply")) {
        return applyErrata(mapping, formIn, request, response);
      }
    }

    String showButton = "true";
    // Show the "Apply Errata" button only when unapplied errata exist:
    if (!SystemManager.hasUnscheduledErrata(user, sid)) {
      showButton = "false";
    }

    Map params = new HashMap();
    Set keys = request.getParameterMap().keySet();
    for (Iterator i = keys.iterator(); i.hasNext(); ) {
      String key = (String) i.next();
      params.put(key, request.getParameter(key));
    }

    Server server = SystemManager.lookupByIdAndUser(sid, user);
    SdcHelper.ssmCheck(request, server.getId(), user);
    request.setAttribute("showApplyErrata", showButton);
    request.setAttribute("set", set);
    request.setAttribute("system", server);
    request.setAttribute("combo", getComboList(request));
    request.setAttribute(SELECTOR, request.getParameter(SELECTOR));

    return getStrutsDelegate()
        .forwardParams(mapping.findForward(RhnHelper.DEFAULT_FORWARD), params);
  }
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response) {

    StrutsDelegate strutsDelegate = getStrutsDelegate();

    ActionForward forward = null;
    DynaActionForm f = (DynaActionForm) form;
    RequestContext requestContext = new RequestContext(request);
    Long sid = requestContext.getRequiredParam("sid");
    User user = requestContext.getLoggedInUser();
    Server server = SystemManager.lookupByIdAndUser(sid, user);
    request.setAttribute("system", server);

    DynaActionForm dynaForm = (DynaActionForm) form;
    DatePicker picker =
        getStrutsDelegate()
            .prepopulateDatePicker(request, dynaForm, "date", DatePicker.YEAR_RANGE_POSITIVE);

    request.setAttribute("date", picker);

    if (!isSubmitted(f)) {
      setup(request, f);
      forward =
          strutsDelegate.forwardParams(mapping.findForward("default"), request.getParameterMap());
    } else {
      ActionMessages msgs = processForm(user, server, f, request);
      strutsDelegate.saveMessages(request, msgs);

      String mode = (String) f.get("mode");
      forward =
          strutsDelegate.forwardParams(
              mapping.findForward(getForward(mode)), request.getParameterMap());
    }

    return forward;
  }
  /** {@inheritDoc} */
  public List getResult(RequestContext context) {
    User user = context.getCurrentUser();
    Long sid = context.getRequiredParam("sid");
    String type = context.getParam(SELECTOR, false);
    String synopsis = "";
    Boolean currency = false;

    LocalizationService ls = LocalizationService.getInstance();

    String eType = new String();

    if (ls.getMessage(SECUR_CRIT).equals(type)) {
      eType = ErrataFactory.ERRATA_TYPE_SECURITY;
      synopsis = "C";
      currency = true;
    } else if (ls.getMessage(SECUR_IMP).equals(type)) {
      eType = ErrataFactory.ERRATA_TYPE_SECURITY;
      synopsis = "I";
      currency = true;
    } else if (ls.getMessage(SECUR_MOD).equals(type)) {
      eType = ErrataFactory.ERRATA_TYPE_SECURITY;
      synopsis = "M";
      currency = true;
    } else if (ls.getMessage(SECUR_LOW).equals(type)) {
      eType = ErrataFactory.ERRATA_TYPE_SECURITY;
      synopsis = "L";
      currency = true;
    }

    if (currency) {
      return SystemManager.relevantCurrencyErrata(user, sid, eType, synopsis);
    }

    List<String> typeList = getTypes(type);
    return SystemManager.relevantErrata(user, sid, typeList);
  }
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    ActionErrors errors = new ActionErrors();
    DynaActionForm form = (DynaActionForm) formIn;
    Map<String, Object> params = makeParamMap(request);
    RequestContext ctx = new RequestContext(request);

    // keep the cid
    if (ctx.hasParam("cid")) {
      params.put("cid", ctx.getParam("cid", true));
    }

    if (!isSubmitted(form)) {
      setupForm(request, form);
      return getStrutsDelegate()
          .forwardParams(mapping.findForward(RhnHelper.DEFAULT_FORWARD), request.getParameterMap());
    }

    if (ctx.hasParam("create_button")) {
      Long cid = create(form, errors, ctx);
      params.put("cid", cid);
      if (errors.isEmpty()) {
        createSuccessMessage(request, "message.channelcreated", form.getString("name"));
      }
    } else if (ctx.hasParam("edit_button")) {
      String sharing = (String) form.get("org_sharing");

      if (hasSharingChanged(form, ctx)
          && ("private".equals(sharing) || "protected".equals(sharing))) {
        // forward to confirm page
        request.setAttribute("org", ctx.getCurrentUser().getOrg());
        formToAttributes(request, form);
        Map urlParams = new HashMap();
        urlParams.put(RequestContext.CID, ctx.getRequiredParam(RequestContext.CID));
        ListHelper helper = new ListHelper(this, request, urlParams);
        helper.setDataSetName(getDataSetName());
        helper.setListName(getListName());
        // ignore the return
        helper.execute();
        request.setAttribute("channel_name", form.getString("name"));
        return getStrutsDelegate().forwardParams(mapping.findForward(sharing), params);
      }

      edit(form, errors, ctx);
      if (errors.isEmpty()) {
        createSuccessMessage(request, "message.channelupdated", form.getString("name"));
      }

      // did they enable per user subscriptions?
      String sub = (String) form.get("per_user_subscriptions");
      if (!sub.equals("all")) {
        addMessage(request, "message.channelsubscribers");
      }
    }
    // handler for private confirmation page
    else if (ctx.hasParam(RequestContext.DISPATCH)) {
      makePrivate(form, errors, ctx);
      if (errors.isEmpty()) {
        createSuccessMessage(request, "message.channelupdated", form.getString("name"));
      }
    } else if (ctx.hasParam("deny")) {
      deny(form, errors, ctx);
      if (errors.isEmpty()) {
        createSuccessMessage(request, "message.channelupdated", form.getString("name"));
      }
    } else if (ctx.hasParam("grant")) {
      grant(form, errors, ctx);
      if (errors.isEmpty()) {
        createSuccessMessage(request, "message.channelupdated", form.getString("name"));
      }
    }
    if (!errors.isEmpty()) {
      request.setAttribute("channel_label", form.get("label"));
      request.setAttribute("channel_name", form.getString("name"));
      request.setAttribute("channel_arch", form.get("arch_name"));
      request.setAttribute("channel_arch_label", form.get("arch"));
      request.setAttribute("checksum", form.get("checksum"));
      addErrors(request, errors);
      prepDropdowns(new RequestContext(request));
      return getStrutsDelegate()
          .forwardParams(mapping.findForward(RhnHelper.DEFAULT_FORWARD), params);
    }

    return getStrutsDelegate().forwardParams(mapping.findForward("success"), params);
  }
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext requestContext = new RequestContext(request);
    User user = requestContext.getLoggedInUser();

    // If this is an easy one and we have the pid
    if (request.getParameter("pid") != null) {
      long pid = requestContext.getRequiredParam("pid");
      Package pkg = PackageFactory.lookupByIdAndUser(pid, user);

      // show permission error if pid is invalid like we did before
      if (pkg == null) {
        throw new PermissionException("Invalid pid");
      }

      if (pkg instanceof Patch) {
        request.setAttribute("type", "patch");
        request.setAttribute(PACKAGE_NAME, pkg.getPackageName().getName());
        request.setAttribute(
            "readme_url", DownloadManager.getPatchReadmeDownloadPath((Patch) pkg, user));
      } else if (pkg instanceof PatchSet) {
        request.setAttribute("type", "patchset");
        request.setAttribute(PACKAGE_NAME, pkg.getNameEvra());
        request.setAttribute(
            "readme_url", DownloadManager.getPatchSetReadmeDownloadPath((PatchSet) pkg, user));
      } else {
        request.setAttribute("type", "rpm");
        request.setAttribute(PACKAGE_NAME, pkg.getFilename());
        if (!pkg.getPackageKeys().isEmpty()) {
          request.setAttribute(PACKAGE_KEY, pkg.getPackageKeys().iterator().next().getKey());
        }
        boolean isDebug = pkg.getPackageName().getName().contains("debuginfo");

        request.setAttribute("isDebuginfo", isDebug);
        if (!isDebug) {
          Package debugPkg = PackageManager.findDebugInfo(user, pkg);
          String ftpUrl = PackageManager.generateFtpDebugPath(pkg);
          if (debugPkg != null) {
            request.setAttribute(
                "debugUrl", DownloadManager.getPackageDownloadPath(debugPkg, user));
          } else if (ftpUrl != null) {
            request.setAttribute("debugUrl", ftpUrl);
            request.setAttribute("debugFtp", true);
          }
        }
      }

      if (DownloadManager.isFileAvailable(pkg.getPath())) {
        request.setAttribute("url", DownloadManager.getPackageDownloadPath(pkg, user));
      }

      List<PackageSource> src = PackageFactory.lookupPackageSources(pkg);

      if (!src.isEmpty() && DownloadManager.isFileAvailable(src.get(0).getPath())) {
        request.setAttribute(
            "srpm_url", DownloadManager.getPackageSourceDownloadPath(pkg, src.get(0), user));
        request.setAttribute("srpm_path", src.get(0).getFile());
      }

      request.setAttribute("pack", pkg);
      // description can be null.
      if (pkg.getDescription() != null) {
        request.setAttribute("description", pkg.getDescription().replace("\n", "<BR>\n"));
      } else {
        request.setAttribute("description", pkg.getDescription());
      }
      request.setAttribute("packArches", PackageFactory.findPackagesWithDifferentArch(pkg));
      request.setAttribute("pid", pid);

      return mapping.findForward("default");
    } else { // we have to guess
      PackageListItem item = PackageListItem.parse(request.getParameter("id_combo"));
      Package pkg;
      long nameId = item.getIdOne();
      long evrId = item.getIdTwo();
      long archId = 0;
      if (item.getIdThree() != null) {
        archId = item.getIdThree();
      }

      Long cid = requestContext.getParamAsLong("cid");
      Long sid = requestContext.getParamAsLong("sid");
      if (cid != null) {
        pkg = PackageManager.guestimatePackageByChannel(cid, nameId, evrId, user.getOrg());

      } else if (sid != null) {
        pkg = PackageManager.guestimatePackageBySystem(sid, nameId, evrId, archId, user.getOrg());

      } else {
        throw new BadParameterException("pid, cid, or sid");
      }

      // show permission error if pid is invalid like we did before
      if (pkg == null) {
        throw new NoSuchPackageException();
      }

      Map params = new HashMap();
      params.put("pid", pkg.getId());
      return getStrutsDelegate().forwardParams(mapping.findForward("package"), params);
    }
  }
  /**
   * 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);
  }
  /** {@inheritDoc} */
  @Override
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext context = new RequestContext(request);
    User user = context.getCurrentUser();

    long cid = context.getRequiredParam("cid");
    Channel chan = ChannelFactory.lookupByIdAndUser(cid, user);
    request.setAttribute("channel_name", chan.getName());
    request.setAttribute("cid", chan.getId());

    Map params = new HashMap();
    params.put(RequestContext.CID, chan.getId().toString());

    ListHelper helper = new ListHelper(this, request, params);
    helper.execute();

    TaskomaticApi taskomatic = new TaskomaticApi();
    String oldCronExpr;
    try {
      oldCronExpr = taskomatic.getRepoSyncSchedule(chan, user);
    } catch (TaskomaticApiException except) {
      params.put("inactive", true);
      request.setAttribute("inactive", true);
      createErrorMessage(request, "repos.jsp.message.taskomaticdown", null);
      return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
    }

    RecurringEventPicker picker =
        RecurringEventPicker.prepopulatePicker(request, "date", oldCronExpr);

    if (context.isSubmitted()) {
      StrutsDelegate strutsDelegate = getStrutsDelegate();

      // check user permissions first
      if (!UserManager.verifyChannelAdmin(user, chan)) {
        createErrorMessage(request, "frontend.actions.channels.manager.add.permsfailure", null);
        return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
      }

      if (chan.getSources().isEmpty()) {
        createErrorMessage(request, "repos.jsp.channel.norepos", null);
        return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
      }

      try {
        if (context.wasDispatched("repos.jsp.button-sync")) {
          // schedule one time repo sync
          taskomatic.scheduleSingleRepoSync(chan, user);
          createSuccessMessage(request, "message.syncscheduled", chan.getName());

        } else if (context.wasDispatched("schedule.button")) {
          if ((picker.isDisabled() || StringUtils.isEmpty(picker.getCronEntry()))
              && oldCronExpr != null) {
            taskomatic.unscheduleRepoSync(chan, user);
            createSuccessMessage(request, "message.syncschedule.disabled", chan.getName());
          } else if (!StringUtils.isEmpty(picker.getCronEntry())) {
            Date date = taskomatic.scheduleRepoSync(chan, user, picker.getCronEntry());
            createSuccessMessage(request, "message.syncscheduled", chan.getName());
          }
        }
      } catch (TaskomaticApiException e) {
        if (e.getMessage().contains("InvalidParamException")) {
          createErrorMessage(request, "repos.jsp.message.invalidcron", picker.getCronEntry());
        } else {
          createErrorMessage(request, "repos.jsp.message.schedulefailed", null);
        }
        return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
      }

      Map forwardParams = new HashMap();
      forwardParams.put("cid", chan.getId());
      return getStrutsDelegate().forwardParams(mapping.findForward("success"), forwardParams);
    }

    return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
  }
 /** {@inheritDoc} */
 protected BaseKickstartCommand getCommand(RequestContext ctx) {
   return new KickstartLocaleCommand(
       ctx.getRequiredParam(RequestContext.KICKSTART_ID), ctx.getCurrentUser());
 }
  /** {@inheritDoc} */
  @Override
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext requestContext = new RequestContext(request);
    User user = requestContext.getCurrentUser();

    long cid = requestContext.getRequiredParam(RequestContext.CID);
    Channel chan = ChannelFactory.lookupByIdAndUser(cid, user);
    String syncType = request.getParameter(SYNC_TYPE);

    if (!UserManager.verifyChannelAdmin(user, chan)) {
      throw new PermissionException(RoleFactory.CHANNEL_ADMIN);
    }
    if (chan.getOrg() == null) {
      throw new PermissionCheckFailureException();
    }

    String selectedChan = request.getParameter(SELECTED_CHANNEL);
    request.setAttribute(RequestContext.CID, chan.getId());
    request.setAttribute(CHANNEL_NAME, chan.getName());

    if (requestContext.wasDispatched("channel.jsp.package.mergebutton")) {
      Map<String, Object> params = new HashMap<String, Object>();
      params.put(RequestContext.CID, cid);
      params.put(OTHER_ID, selectedChan);
      params.put(SYNC_TYPE, syncType);
      return getStrutsDelegate()
          .forwardParams(mapping.findForward(RhnHelper.CONFIRM_FORWARD), params);
    }

    // selected channel id
    long scid = 0;
    String sname = "";

    // If a channel isn't selected, select one smartly
    if (selectedChan == null) {
      if (chan.isCloned()) {
        scid = chan.getOriginal().getId();
      }
    } else if (!NO_PACKAGES.equals(selectedChan)) {
      scid = Long.parseLong(selectedChan);
    }

    // Add Red Hat Base Channels, and custom base channels to the list, and if one
    //      is selected, select it
    List<SelectableChannel> chanList = findChannels(user, scid);
    DataResult result = null;

    if (scid != 0) {
      sname = ChannelFactory.lookupByIdAndUser(scid, user).getName();

      result = PackageManager.comparePackagesBetweenChannels(cid, scid);

      TagHelper.bindElaboratorTo(listName, result.getElaborator(), request);
    }

    request.setAttribute(CHANNEL_LIST, chanList);
    request.setAttribute(OTHER_CHANNEL, sname);
    request.setAttribute(SYNC_TYPE, syncType);
    request.setAttribute(ListTagHelper.PARENT_URL, request.getRequestURI());
    request.setAttribute(RequestContext.PAGE_LIST, result);

    return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
  }
 /** {@inheritDoc} */
 public List getResult(RequestContext context) {
   Long xid = context.getRequiredParam("xid");
   return ScapManager.ruleResultsPerScan(xid);
 }
 /** {@inheritDoc} */
 public List<ContentSource> getResult(RequestContext context) {
   User user = context.getCurrentUser();
   long cid = context.getRequiredParam("cid");
   Channel chan = ChannelFactory.lookupByIdAndUser(cid, user);
   return ChannelFactory.lookupContentSources(user.getOrg(), chan);
 }