/** {@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);
  }
  /** {@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));
    PublishErrataHelper.checkPermissions(user, cid);

    Channel currentChan = ChannelFactory.lookupByIdAndUser(cid, requestContext.getCurrentUser());
    request.setAttribute("channel_name", currentChan.getName());

    request.setAttribute("cid", cid);
    return mapping.findForward("default");
  }
  /** {@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 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);
  }
 /**
  * Return true if the form value of org_sharing is different than the Channel for the given id.
  *
  * @param form contains the user entered values.
  * @param ctx current Request context.
  * @return true if the form value of org_sharing is different than the Channel for the given id.
  */
 private boolean hasSharingChanged(DynaActionForm form, RequestContext ctx) {
   Long cid = ctx.getParamAsLong("cid");
   Channel c = ChannelFactory.lookupByIdAndUser(cid, ctx.getCurrentUser());
   return !c.getAccess().equals(form.get("org_sharing"));
 }
Example #6
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);
  }
  /** {@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} */
 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);
 }