private DataResult getData(
      HttpServletRequest request,
      Channel selectedChan,
      Channel currentChan,
      List<SelectableChannel> selChannelList,
      boolean packageAssoc,
      User user) {

    if (selectedChan != null) {
      RhnSet set = RhnSetDecl.CHANNELS_FOR_ERRATA.get(user);
      set.clear();
      set.addElement(selectedChan.getId());
      RhnSetManager.store(set);
      return ChannelManager.findErrataFromRhnSetForTarget(currentChan, packageAssoc, user);
    } else if (selChannelList != null) {
      RhnSet set = RhnSetDecl.CHANNELS_FOR_ERRATA.get(user);
      set.clear();
      for (SelectableChannel chan : selChannelList) {
        set.addElement(chan.getId());
      }
      RhnSetManager.store(set);
      return ChannelManager.findErrataFromRhnSetForTarget(currentChan, packageAssoc, user);

    } else {
      return ChannelManager.findErrataForTarget(currentChan, packageAssoc);
    }
  }
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

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

    User user = requestContext.getCurrentUser();

    Errata errata = requestContext.lookupErratum();
    DataResult dr = ErrataManager.systemsAffected(user, errata.getId(), null);

    RhnSet set = RhnSetDecl.SYSTEMS_AFFECTED.get(user);
    RhnListSetHelper helper = new RhnListSetHelper(request);

    // if its not submitted
    // ==> this is the first visit to this page
    // clear the 'dirty set'
    if (!requestContext.isSubmitted()) {
      set.clear();
      RhnSetManager.store(set);
    }

    if (request.getParameter(DISPATCH) != null) {
      helper.updateSet(set, LIST_NAME);
      if (!set.isEmpty()) {
        // Send to AffectedSystemsAction to handle submit
        return strutsDelegate.forwardParams(
            mapping.findForward("confirm"), request.getParameterMap());
      }
      RhnHelper.handleEmptySelection(request);
    }

    if (ListTagHelper.getListAction(LIST_NAME, request) != null) {
      helper.execute(set, LIST_NAME, dr);
    }

    // if I have a previous set selections populate data using it
    if (!set.isEmpty()) {
      helper.syncSelections(set, dr);
      ListTagHelper.setSelectedAmount(LIST_NAME, set.size(), request);
    }

    TagHelper.bindElaboratorTo("systemAffectedList", dr.getElaborator(), request);
    ListTagHelper.bindSetDeclTo(LIST_NAME, RhnSetDecl.SYSTEMS_AFFECTED, request);

    request.setAttribute(RequestContext.PAGE_LIST, dr);
    request.setAttribute("set", set);
    request.setAttribute("errata", errata);
    request.setAttribute(
        ListTagHelper.PARENT_URL,
        request.getRequestURI() + "?" + RequestContext.ERRATA_ID + "=" + errata.getId());

    return strutsDelegate.forwardParams(
        mapping.findForward(RhnHelper.DEFAULT_FORWARD), request.getParameterMap());
  }
  /**
   * Forward to the confirm page
   *
   * @param mapping ActionMapping
   * @param formIn ActionForm
   * @param request ServletRequest
   * @param response ServletResponse
   * @return The ActionForward to go to next.
   */
  public ActionForward forwardToConfirm(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {
    RhnSet set = updateSet(request);
    String forwardName = "delete";

    StrutsDelegate strutsDelegate = getStrutsDelegate();

    if (set.size() == 0) {
      strutsDelegate.saveMessage("filelists.jsp.selectafilelist", request);
      forwardName = RhnHelper.DEFAULT_FORWARD;
    }
    Map params = makeParamMap(formIn, request);
    RhnSetManager.store(set);
    return strutsDelegate.forwardParams(mapping.findForward(forwardName), params);
  }
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext requestContext = new RequestContext(request);
    User user = requestContext.getCurrentUser();
    Long cid = Long.parseLong(request.getParameter(CID));
    Channel currentChan = ChannelFactory.lookupByIdAndUser(cid, user);
    Channel selectedChannel = null;

    PublishErrataHelper.checkPermissions(user, cid);

    request.setAttribute(CID, cid);
    request.setAttribute("user", user);
    request.setAttribute("channel_name", currentChan.getName());
    request.setAttribute(ListTagHelper.PARENT_URL, request.getRequestURI());

    List<SelectableChannelVersion> versionList =
        SelectableChannelVersion.getCurrentChannelVersionList();
    List<SelectableChannel> channelList = null;
    request.setAttribute(VERSION_LIST, versionList);

    String selectedVersionStr = null;
    String selectedChannelStr = null;
    Boolean checked = true;

    // Set initail strings
    selectedChannelStr = request.getParameter(SELECTED_CHANNEL_OLD);
    selectedVersionStr = request.getParameter(SELECTED_VERSION_OLD);
    if (selectedVersionStr == null) {
      selectedVersionStr = versionList.get(0).getVersion();
    }

    // If the channel submit button was clicked
    if (requestContext.wasDispatched(CHANNEL_SUBMIT)) {
      selectedChannelStr = request.getParameter(SELECTED_CHANNEL);
      // selectedChannelStr might be null
    }
    // if the version submit button was clicked
    else if (requestContext.wasDispatched(VERSION_SUBMIT)) {
      selectedVersionStr = request.getParameter(SELECTED_VERSION);
      // selectedChannelStr might be null
      selectedChannelStr = null;
    }

    if (!requestContext.isSubmitted()) {
      // If this is a clone, go ahead and pre-select the original Channel
      Channel original = ChannelFactory.lookupOriginalChannel(currentChan);

      while (original != null) {

        selectedChannel = original;
        selectedChannelStr = selectedChannel.getId().toString();
        String tmp = findVersionFromChannel(selectedChannel);
        if (tmp == null) {
          // if we haven't found channel version, let's try to check its parent
          if (!selectedChannel.isBaseChannel()) {
            tmp = findVersionFromChannel(selectedChannel.getParentChannel());
          }
        }
        if (tmp != null) {
          selectedVersionStr = tmp;
          break;
        }
        original = ChannelFactory.lookupOriginalChannel(original);
      }
    }

    if (selectedVersionStr != null) {
      // set selected version based off version selected
      for (SelectableChannelVersion chanVer : versionList) {
        if (chanVer.getVersion().equals(selectedVersionStr)) {
          chanVer.setSelected(true);
          request.setAttribute(SELECTED_VERSION_NAME, chanVer.getName());
          break;
        }
      }

      List<Channel> channelSet = findChannelsByVersion(user, selectedVersionStr);
      channelList = new ArrayList();
      if (channelSet != null) {
        sortChannelsAndChildify(channelSet, channelList, user, selectedChannelStr);
        request.setAttribute(CHANNEL_LIST, channelList);
      }
    }

    if (requestContext.isSubmitted() && request.getParameter(CHECKED) == null) {
      checked = false;
    }

    request.setAttribute(CHECKED, checked);
    request.setAttribute(SELECTED_CHANNEL, selectedChannelStr);
    request.setAttribute(SELECTED_VERSION, selectedVersionStr);

    if (requestContext.wasDispatched(SUBMITTED)) {
      Map params = new HashMap();
      params.put(CID, request.getParameter(CID));
      params.put(SELECTED_CHANNEL, selectedChannelStr);
      params.put(CHECKED, request.getParameter(CHECKED));
      return getStrutsDelegate().forwardParams(mapping.findForward("submit"), params);
    }

    // If we clicked on the channel selection, clear the set
    if (requestContext.wasDispatched(CHANNEL_SUBMIT)
        || requestContext.wasDispatched(VERSION_SUBMIT)
        || !requestContext.isSubmitted()) {
      RhnSet eset = getSetDecl(currentChan).get(user);
      eset.clear();
      RhnSetManager.store(eset);
    }

    if (selectedChannelStr != null) {
      selectedChannel = ChannelFactory.lookupByIdAndUser(Long.parseLong(selectedChannelStr), user);
    }

    RhnListSetHelper helper = new RhnListSetHelper(request);
    RhnSet set = getSetDecl(currentChan).get(user);

    DataResult dr = getData(request, selectedChannel, currentChan, channelList, checked, user);

    request.setAttribute(RequestContext.PAGE_LIST, dr);

    if (ListTagHelper.getListAction("errata", request) != null) {
      helper.execute(set, "errata", dr);
    }
    if (!set.isEmpty()) {
      helper.syncSelections(set, dr);
      ListTagHelper.setSelectedAmount("errata", set.size(), request);
    }

    TagHelper.bindElaboratorTo("errata", dr.getElaborator(), request);
    ListTagHelper.bindSetDeclTo("errata", getSetDecl(currentChan), request);

    return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
  }
Exemplo n.º 5
0
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext context = new RequestContext(request);
    User user = context.getCurrentUser();
    Long cid = Long.parseLong(request.getParameter(CID));
    Channel channel = ChannelFactory.lookupByIdAndUser(cid, user);

    PublishErrataHelper.checkPermissions(user, cid);

    request.setAttribute(CID, cid);
    request.setAttribute("user", user);
    request.setAttribute("channel_name", channel.getName());
    request.setAttribute(ListTagHelper.PARENT_URL, request.getRequestURI());
    request.setAttribute("emptyKey", EMPTY_KEY);

    List<SelectableChannel> channelList = null;

    RhnSet set = getDecl(channel).get(user);
    // if its not submitted
    // ==> this is the first visit to this page
    // clear the 'dirty set'
    if (!context.isSubmitted()) {
      set.clear();
      RhnSetManager.store(set);
    }

    Channel original = ChannelFactory.lookupOriginalChannel(channel);

    RhnListSetHelper helper = new RhnListSetHelper(request);
    if (request.getParameter(DISPATCH) != null) {
      // if its one of the Dispatch actions handle it..
      helper.updateSet(set, LIST_NAME);
      if (!set.isEmpty()) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put(CID, request.getParameter(CID));
        params.put(ConfirmErrataAction.SELECTED_CHANNEL, original.getId());
        return getStrutsDelegate().forwardParams(mapping.findForward("submit"), params);
      } else {
        RhnHelper.handleEmptySelection(request);
      }
    }

    // get the errata list
    DataResult<ErrataOverview> dataSet =
        ErrataFactory.relevantToOneChannelButNotAnother(original.getId(), channel.getId());

    if (ListTagHelper.getListAction(LIST_NAME, request) != null) {
      helper.execute(set, LIST_NAME, dataSet);
    }

    if (!set.isEmpty()) {
      helper.syncSelections(set, dataSet);
      ListTagHelper.setSelectedAmount(LIST_NAME, set.size(), request);
    }

    request.setAttribute(RequestContext.PAGE_LIST, dataSet);
    ListTagHelper.bindSetDeclTo(LIST_NAME, getDecl(channel), request);
    TagHelper.bindElaboratorTo(LIST_NAME, dataSet.getElaborator(), request);

    return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
  }