Пример #1
0
  private void setupForm(HttpServletRequest request, DynaActionForm form) {
    RequestContext ctx = new RequestContext(request);
    prepDropdowns(ctx);
    Long cid = ctx.getParamAsLong("cid");

    if (cid != null) {
      Channel c = ChannelManager.lookupByIdAndUser(cid, ctx.getCurrentUser());
      if (!UserManager.verifyChannelAdmin(ctx.getCurrentUser(), c)) {
        throw new PermissionException(RoleFactory.CHANNEL_ADMIN);
      }

      form.set("name", c.getName());
      form.set("summary", c.getSummary());
      form.set("description", c.getDescription());
      form.set("org_sharing", c.getAccess());
      form.set("gpg_key_url", c.getGPGKeyUrl());
      form.set("gpg_key_id", c.getGPGKeyId());
      form.set("gpg_key_fingerprint", c.getGPGKeyFp());
      form.set("maintainer_name", c.getMaintainerName());
      form.set("maintainer_phone", c.getMaintainerPhone());
      form.set("maintainer_email", c.getMaintainerEmail());
      form.set("support_policy", c.getSupportPolicy());
      if (c.getChecksumTypeLabel() == null) {
        form.set("checksum", null);
      } else {
        form.set("checksum", c.getChecksumTypeLabel());
      }
      if (c.isGloballySubscribable(ctx.getCurrentUser().getOrg())) {
        form.set("per_user_subscriptions", "all");
      } else {
        form.set("per_user_subscriptions", "selected");
      }

      if (c.getParentChannel() != null) {
        request.setAttribute("parent_name", c.getParentChannel().getName());
        request.setAttribute("parent_id", c.getParentChannel().getId());
      } else {
        request.setAttribute(
            "parent_name", LocalizationService.getInstance().getMessage("generic.jsp.none"));
      }

      if (c.getSources().isEmpty()) {
        request.setAttribute("last_sync", "");
      } else {
        String lastSync =
            LocalizationService.getInstance().getMessage("channel.edit.repo.neversynced");
        if (c.getLastSynced() != null) {
          lastSync = LocalizationService.getInstance().formatCustomDate(c.getLastSynced());
        }
        request.setAttribute("last_sync", lastSync);
        if (!ChannelManager.getLatestSyncLogFiles(c).isEmpty()) {
          request.setAttribute(
              "log_url", DownloadManager.getChannelSyncLogDownloadPath(c, ctx.getCurrentUser()));
        }
      }

      request.setAttribute("channel_label", c.getLabel());
      request.setAttribute("channel_name", c.getName());
      request.setAttribute("channel_arch", c.getChannelArch().getName());
      request.setAttribute("channel_arch_label", c.getChannelArch().getLabel());

    } else {
      // default settings
      String channelName =
          LocalizationService.getInstance().getMessage("frontend.actions.channels.manager.create");
      request.setAttribute("channel_name", channelName);
      form.set("org_sharing", "private");
      form.set("per_user_subscriptions", "all");
      form.set("checksum", "sha1");
    }
  }
  /** {@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} */
  @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);
  }