예제 #1
0
  public void testChannel() throws Exception {
    Channel c = ChannelFactoryTest.createTestChannel(user);
    // add an errata
    Errata e = ErrataFactoryTest.createTestPublishedErrata(user.getId());
    c.addErrata(e);
    assertEquals(c.getErratas().size(), 1);
    ChannelFactory.save(c);

    log.debug("Looking up id [" + c.getId() + "]");
    Channel c2 = ChannelFactory.lookupById(c.getId());
    log.debug("Finished lookup");
    assertEquals(c2.getErratas().size(), 1);

    assertEquals(c.getLabel(), c2.getLabel());
    assertNotNull(c.getChannelArch());

    Channel c3 = ChannelFactoryTest.createTestChannel(user);

    c.setParentChannel(c3);
    assertEquals(c.getParentChannel().getId(), c3.getId());

    // Test isGloballySubscribable
    assertTrue(c.isGloballySubscribable(c.getOrg()));
    c.setGloballySubscribable(false, c.getOrg());
    assertFalse(c.isGloballySubscribable(c.getOrg()));
    c.setGloballySubscribable(true, c.getOrg());
    assertTrue(c.isGloballySubscribable(c.getOrg()));
  }
예제 #2
0
 public void testDeleteChannel() throws Exception {
   Channel c = ChannelFactoryTest.createTestChannel(user);
   Long id = c.getId();
   assertNotNull(c);
   ChannelFactory.save(c);
   assertNotNull(ChannelFactory.lookupById(id));
   ChannelFactory.remove(c);
   TestUtils.flushAndEvict(c);
   assertNull(ChannelFactory.lookupById(id));
 }
예제 #3
0
  /** {@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);
  }
예제 #4
0
  private Channel makePrivate(DynaActionForm form, ActionErrors errors, RequestContext ctx) {

    User user = ctx.getCurrentUser();
    Long cid = ctx.getParamAsLong("cid");
    Channel channel = ChannelFactory.lookupById(cid);
    unsubscribeOrgsFromChannel(user, channel, Channel.PRIVATE);
    return edit(form, errors, ctx);
  }
예제 #5
0
  private Channel lookupChannelByLabel(User user, String label) throws NoSuchChannelException {

    Channel channel = ChannelFactory.lookupByLabelAndUser(label, user);
    if (channel == null) {
      throw new NoSuchChannelException();
    }

    return channel;
  }
예제 #6
0
 public void testRemovePackage() throws Exception {
   Channel c = ChannelFactoryTest.createTestChannel(user);
   Package p = PackageTest.createTestPackage(user.getOrg());
   c.addPackage(p);
   ChannelFactory.save(c);
   c.removePackage(p, user);
   assertTrue(c.getPackageCount() == 0);
   assertTrue(c.getPackages().isEmpty());
 }
예제 #7
0
  private Long create(DynaActionForm form, ActionErrors errors, RequestContext ctx) {

    User loggedInUser = ctx.getCurrentUser();
    Long cid = null;

    // handle submission
    // why can't I just pass in a dictionary? sigh, there are
    // times where python would make this SOOOO much easier.
    CreateChannelCommand ccc = new CreateChannelCommand();
    ccc.setArchLabel((String) form.get("arch"));
    ccc.setChecksumLabel((String) form.get("checksum"));
    ccc.setLabel((String) form.get("label"));
    ccc.setName((String) form.get("name"));
    ccc.setSummary((String) form.get("summary"));
    ccc.setDescription(StringUtil.nullIfEmpty((String) form.get("description")));
    ccc.setParentLabel(null);
    ccc.setUser(loggedInUser);
    ccc.setGpgKeyId(StringUtil.nullIfEmpty((String) form.get("gpg_key_id")));
    ccc.setGpgKeyUrl(StringUtil.nullIfEmpty((String) form.get("gpg_key_url")));
    ccc.setGpgKeyFp(StringUtil.nullIfEmpty((String) form.get("gpg_key_fingerprint")));
    ccc.setMaintainerName(StringUtil.nullIfEmpty((String) form.get("maintainer_name")));
    ccc.setMaintainerEmail(StringUtil.nullIfEmpty((String) form.get("maintainer_email")));
    ccc.setMaintainerPhone(StringUtil.nullIfEmpty((String) form.get("maintainer_phone")));
    ccc.setSupportPolicy(StringUtil.nullIfEmpty((String) form.get("support_policy")));
    ccc.setAccess((String) form.get("org_sharing"));

    String parent = (String) form.get("parent");
    if (parent == null || parent.equals("")) {
      ccc.setParentId(null);
    } else {
      ccc.setParentId(Long.valueOf(parent));
    }

    try {
      Channel c = ccc.create();
      String sharing = (String) form.get("per_user_subscriptions");
      c.setGloballySubscribable(
          (sharing != null) && ("all".equals(sharing)), loggedInUser.getOrg());
      c = (Channel) ChannelFactory.reload(c);
      cid = c.getId();
    } catch (InvalidGPGFingerprintException borg) {
      errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("edit.channel.invalidgpgfp"));
    } catch (InvalidGPGKeyException dukat) {
      errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("edit.channel.invalidgpgkey"));
    } catch (InvalidGPGUrlException khan) {
      errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("edit.channel.invalidgpgurl"));
    } catch (InvalidChannelNameException ferengi) {
      handleChannelNameException(errors, ferengi);
    } catch (InvalidChannelLabelException q) {
      handleChannelLabelException(errors, q);
    } catch (IllegalArgumentException iae) {
      errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(iae.getMessage()));
    }

    return cid;
  }
예제 #8
0
 private void grant(DynaActionForm form, ActionErrors errors, RequestContext ctx) {
   Channel c = edit(form, errors, ctx);
   // if there was no exception during the above edit
   // add all of the orgs to the "rhnchanneltrust"
   if (c != null) {
     Org org = ctx.getCurrentUser().getOrg();
     Set<Org> trustedorgs = org.getTrustedOrgs();
     c.setTrustedOrgs(trustedorgs);
     ChannelFactory.save(c);
   }
 }
예제 #9
0
  /**
   * @param form form to check
   * @param errors errors to report
   * @param ctx context
   * @return Channel
   */
  private Channel deny(DynaActionForm form, ActionErrors errors, RequestContext ctx) {

    Channel c = edit(form, errors, ctx);
    User user = ctx.getCurrentUser();

    unsubscribeOrgsFromChannel(user, c, Channel.PROTECTED);

    c.getTrustedOrgs().clear();
    ChannelFactory.save(c);
    return c;
  }
예제 #10
0
 public void testEquals() throws Exception {
   Channel c1 = ChannelFactoryTest.createTestChannel(user);
   Channel c2 = ChannelFactoryTest.createTestChannel(user);
   assertFalse(c1.equals(c2));
   Channel c3 = ChannelFactory.lookupById(c1.getId());
   Set<Channel> testSet = new HashSet<Channel>();
   testSet.add(c1);
   testSet.add(c2);
   testSet.add(c3);
   assertTrue(testSet.size() == 2);
 }
예제 #11
0
 public void testContentSource() throws Exception {
   Channel c = ChannelFactoryTest.createTestChannel(user);
   ContentSource cs = new ContentSource();
   cs.setLabel("repo_label-" + c.getLabel());
   cs.setSourceUrl("fake url");
   List<ContentSourceType> cst = ChannelFactory.listContentSourceTypes();
   cs.setType(cst.get(0));
   cs.setOrg(user.getOrg());
   cs = (ContentSource) TestUtils.saveAndReload(cs);
   c.getSources().add(cs);
   c = (Channel) TestUtils.saveAndReload(c);
   assertNotEmpty(c.getSources());
 }
예제 #12
0
  public void testIsProxy() throws Exception {
    Channel c = ChannelFactoryTest.createTestChannel(user);
    ChannelFamily cfam =
        ChannelFamilyFactoryTest.createTestChannelFamily(
            user, false, ChannelFamilyFactory.PROXY_CHANNEL_FAMILY_LABEL);

    c.setChannelFamily(cfam);

    TestUtils.saveAndFlush(c);

    Channel c2 = ChannelFactory.lookupById(c.getId());
    assertTrue(c2.isProxy());
  }
  /**
   * Get the id of the Package installed for this KS. Here we'll verify that the kickstart package
   * exists in the host server's tools channel. The host server will need it to perform necessary
   * actions on either itself or the target system (if different).
   *
   * @return Long id of Package used for this KS.
   */
  public ValidatorError validateKickstartPackage() {
    if (cobblerOnly) {
      return null;
    }

    Server hostServer = getHostServer();
    Set<Long> serverChannelIds = new HashSet<Long>();
    Iterator<Channel> i = hostServer.getChannels().iterator();
    while (i.hasNext()) {
      Channel c = i.next();
      serverChannelIds.add(c.getId());
    }

    // check for package among channels the server is subscribed to.
    // If one is found, return
    Map<String, Long> pkgToInstall = findKickstartPackageToInstall(hostServer, serverChannelIds);
    if (pkgToInstall != null) {
      this.packagesToInstall.add(pkgToInstall);
      log.debug("    packagesToInstall: " + packagesToInstall);
      return null;
    }

    // otherwise search in channels that can be subscribed.
    // If one is found, subscribe channel and return
    Set<Long> subscribableChannelIds =
        SystemManager.subscribableChannelIds(
            hostServer.getId(), this.user.getId(), hostServer.getBaseChannel().getId());
    pkgToInstall = findKickstartPackageToInstall(hostServer, subscribableChannelIds);

    if (pkgToInstall != null) {
      this.packagesToInstall.add(pkgToInstall);
      log.debug("    packagesToInstall: " + packagesToInstall);
      Long cid = pkgToInstall.get("channel_id");
      log.debug("    Subscribing to: " + cid);
      Channel c = ChannelFactory.lookupById(cid);
      try {
        SystemManager.subscribeServerToChannel(this.user, server, c);
        log.debug("    Subscribed: " + cid);
      } catch (PermissionException pe) {
        return new ValidatorError("kickstart.schedule.cantsubscribe");
      } catch (Exception e) {
        return new ValidatorError(
            "kickstart.schedule.cantsubscribe.channel", c.getName(), server.getName());
      }
      return null;
    }

    return new ValidatorError(
        "kickstart.schedule.nopackage", this.getKsdata().getChannel().getName());
  }
예제 #14
0
  /**
   * @param user User that owns parent channel
   * @param channelIn base channel to unsubscribe from.
   */
  private void unsubscribeOrgsFromChannel(User user, Channel channelIn, String accessIn) {
    Org org = channelIn.getOrg();

    // find trusted orgs
    Set<Org> trustedOrgs = org.getTrustedOrgs();
    for (Org o : trustedOrgs) {
      // find systems subscribed in org Trust
      DataResult<Map<String, Object>> dr = SystemManager.sidsInOrgTrust(org.getId(), o.getId());

      for (Map<String, Object> item : dr) {
        Long sid = (Long) item.get("id");
        Server s = ServerFactory.lookupById(sid);
        if (s.isSubscribed(channelIn)) {
          // check if this is a base custom channel
          if (channelIn.getParentChannel() == null) {
            // unsubscribe children first if subscribed
            List<Channel> children = channelIn.getAccessibleChildrenFor(user);
            Iterator<Channel> i = children.iterator();
            while (i.hasNext()) {
              Channel child = i.next();
              if (s.isSubscribed(child)) {
                // unsubscribe server from child channel

                child.getTrustedOrgs().remove(o);
                child.setAccess(accessIn);
                ChannelFactory.save(child);
                s = SystemManager.unsubscribeServerFromChannel(s, child);
              }
            }
          }
          // unsubscribe server from channel
          ChannelFactory.save(channelIn);
          s = SystemManager.unsubscribeServerFromChannel(s, channelIn);
        }
      }
    }
  }
예제 #15
0
  private int enableAccess(User loggedInUser, String channelLabel, Integer orgId, boolean enable)
      throws FaultException {
    Channel channel = lookupChannelByLabel(loggedInUser, channelLabel);
    verifyChannelAdmin(loggedInUser, channel);

    if (!loggedInUser.getOrg().equals(channel.getOrg())) {
      // users are not allowed to alter properties for a channel that is in a
      // different org
      throw new NotPermittedByOrgException(
          loggedInUser.getOrg().getId().toString(),
          channel.getLabel(),
          channel.getOrg().getId().toString());
    }

    // protected mode only for modifying individual orgs
    if (!channel.getAccess().equals(Channel.PROTECTED)) {
      throw new InvalidChannelAccessException(channel.getAccess());
    }

    Org org = OrgFactory.lookupById(orgId.longValue());
    if (org == null) {
      throw new NoSuchOrgException(orgId.toString());
    }

    // need to validate that the org provided is in the list of orgs that may
    // be granted access
    List<OrgChannelDto> orgs = OrgManager.orgChannelTrusts(channel.getId(), loggedInUser.getOrg());
    boolean orgInTrust = false;

    for (OrgChannelDto orgDto : orgs) {
      if (orgDto.getId().equals(new Long(orgId))) {
        orgInTrust = true;
        break;
      }
    }

    if (orgInTrust) {
      if (enable) {
        channel.getTrustedOrgs().add(org);
      } else {
        channel.getTrustedOrgs().remove(org);
      }
      ChannelFactory.save(channel);
    } else {
      throw new OrgNotInTrustException(orgId);
    }

    return 1;
  }
  private List findChannelsByVersion(User user, String version) {

    if (version == null) {
      return null;
    }
    List<Channel> channels = ChannelFactory.listRedHatBaseChannels(user);
    List toReturn = new ArrayList();
    for (Channel chan : channels) {
      for (DistChannelMap map : chan.getDistChannelMaps()) {
        if (ChannelVersion.getChannelVersionForDistChannelMap(map).getVersion().equals(version)) {
          toReturn.add(chan);
          break;
        }
      }
    }
    return toReturn;
  }
예제 #17
0
  /** {@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");
  }
예제 #18
0
  private void prepDropdowns(RequestContext ctx) {
    User loggedInUser = ctx.getCurrentUser();
    // populate parent base channels
    List<Map<String, String>> baseChannels = new ArrayList<Map<String, String>>();
    List<Channel> bases = ChannelManager.findAllBaseChannelsForOrg(loggedInUser);

    LocalizationService ls = LocalizationService.getInstance();
    addOption(baseChannels, ls.getMessage("generic.jsp.none"), "");
    for (Channel c : bases) {
      addOption(baseChannels, c.getName(), c.getId().toString());
    }
    ctx.getRequest().setAttribute("parentChannels", baseChannels);

    Map<Long, String> parentChannelArches = new HashMap<Long, String>();
    for (Channel c : bases) {
      parentChannelArches.put(c.getId(), c.getChannelArch().getLabel());
    }
    ctx.getRequest().setAttribute("parentChannelArches", parentChannelArches);

    Map<Long, String> parentChannelChecksums = new HashMap<Long, String>();
    for (Channel c : bases) {
      parentChannelChecksums.put(c.getId(), c.getChecksumTypeLabel());
    }
    ctx.getRequest().setAttribute("parentChannelChecksums", parentChannelChecksums);

    // base channel arches
    List<Map<String, String>> channelArches = new ArrayList<Map<String, String>>();
    List<ChannelArch> arches = ChannelManager.getChannelArchitectures();
    for (ChannelArch arch : arches) {
      addOption(channelArches, arch.getName(), arch.getLabel());
    }
    ctx.getRequest().setAttribute("channelArches", channelArches);
    // set the list of yum supported checksums
    List<Map<String, String>> checksums = new ArrayList<Map<String, String>>();
    addOption(checksums, ls.getMessage("generic.jsp.none"), "");
    for (ChecksumType chType : ChannelFactory.listYumSupportedChecksums()) {
      addOption(checksums, chType.getLabel(), chType.getLabel());
    }
    ctx.getRequest().setAttribute("checksums", checksums);
  }
  public void testRepodata() throws Exception {

    OutputStream st = new ByteArrayOutputStream();
    SimpleContentHandler tmpHandler = getTemporaryHandler(st);

    SimpleAttributesImpl attr = new SimpleAttributesImpl();
    attr.addAttribute("type", "rpm");
    tmpHandler.startDocument();

    tmpHandler.startElement("package", attr);

    SimpleAttributesImpl secattr = new SimpleAttributesImpl();
    attr.addAttribute("bar", "&>><<");
    tmpHandler.startElement("foo", secattr);
    tmpHandler.addCharacters("&&&&");
    tmpHandler.endElement("foo");

    tmpHandler.endElement("package");
    tmpHandler.endDocument();

    // st.flush();
    String test = st.toString();
    System.out.println(test);

    Package p = PackageTest.createTestPackage();
    Channel c = ChannelFactoryTest.createTestChannel();
    c.addPackage(p);
    ChannelFactory.save(c);

    PackageManager.createRepoEntrys(c.getId());

    PackageManager.updateRepoPrimary(p.getId(), test);
    DataResult dr = PackageManager.getRepoData(p.getId());
    PackageDto dto = (PackageDto) dr.get(0);
    String prim = dto.getPrimaryXml();
    String other = dto.getOtherXml();
    assertEquals(prim, test);
  }
  /**
   * Looks up a list of applicable kickstart profiles. The list is generated based on matches
   * between the server's base channel arch and the profile's channel arch
   *
   * @return DataResult, else null if the server does not exist or does not have a base channel
   *     assigned
   */
  public DataResult<KickstartDto> getKickstartProfiles() {
    log.debug("getKickstartProfiles()");
    DataResult<KickstartDto> retval = new DataResult<KickstartDto>(Collections.EMPTY_LIST);

    // Profiles are associated with the host; the target system might not be created
    // yet.  Also, the host will be the one performing the kickstart, so the profile
    // is relative to that system.

    Server hostServer = getHostServer();
    if (hostServer != null) {
      log.debug("getKickstartProfiles(): hostServer isnt null");
      Channel baseChannel = hostServer.getBaseChannel();
      if (baseChannel != null) {
        log.debug("getKickstartProfiles(): hostServer.baseChannel isnt null");
        ChannelArch arch = baseChannel.getChannelArch();
        SelectMode mode = getMode();
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("org_id", this.user.getOrg().getId());
        params.put("prim_arch_id", arch.getId());
        if (arch.getName().equals("x86_64")) {
          log.debug("    Adding IA-32 to search list.");
          ChannelArch ia32arch = ChannelFactory.lookupArchByName("IA-32");
          params.put("sec_arch_id", ia32arch.getId());
        } else if (arch.getName().equals("IA-32")
            && (hostServer.getServerArch().getName().equals(ServerConstants.getArchI686().getName())
                || hostServer
                    .getServerArch()
                    .getName()
                    .equals(ServerConstants.getArchATHLON().getName()))) {
          log.debug("    Adding x86_64 to search list.");
          ChannelArch x86Arch = ChannelFactory.lookupArchByName("x86_64");
          params.put("sec_arch_id", x86Arch.getId());
        } else if (arch.getName().equals("PPC")) {
          log.debug("    Adding ppc64le to search list.");
          ChannelArch ppc64le = ChannelFactory.lookupArchByName("PPC64LE");
          params.put("sec_arch_id", ppc64le.getId());
        } else if (arch.getName().equals("PPC64LE")) {
          log.debug("    Adding ppc to search list.");
          ChannelArch ppc = ChannelFactory.lookupArchByName("PPC");
          params.put("sec_arch_id", ppc.getId());
        } else {
          params.put("sec_arch_id", arch.getId());
        }
        retval = mode.execute(params);
        if (log.isDebugEnabled()) {
          log.debug("got back from DB: " + retval);
        }
        KickstartLister.getInstance().setKickstartUrls(retval, user);
        KickstartLister.getInstance().pruneInvalid(user, retval);
        retval.setTotalSize(retval.size());
      }
    }

    List<CobblerProfileDto> dtos = KickstartLister.getInstance().listCobblerProfiles(user);
    if (log.isDebugEnabled()) {
      log.debug("got back from cobbler: " + dtos);
    }
    retval.setTotalSize(retval.getTotalSize() + dtos.size());
    retval.addAll(dtos);

    return retval;
  }
예제 #21
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);
  }
예제 #22
0
 /** {@inheritDoc} */
 public List<ContentSource> getResult(RequestContext context) {
   User user = context.getCurrentUser();
   return ChannelFactory.lookupContentSources(user.getOrg());
 }
  /** {@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);
  }
예제 #24
0
 /**
  * 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"));
 }
예제 #25
0
  /**
   * Creates the Channel based on the parameters that were set.
   *
   * @return the newly created Channel
   * @throws InvalidChannelLabelException thrown if label is in use or invalid.
   * @throws InvalidChannelNameException throw if name is in use or invalid.
   * @throws IllegalArgumentException thrown if label, name or user are null.
   * @throws InvalidParentChannelException thrown if parent label is not a valid base channel.
   */
  public Channel create()
      throws InvalidChannelLabelException, InvalidChannelNameException,
          InvalidParentChannelException {

    verifyRequiredParameters();
    verifyChannelName(name);
    verifyChannelLabel(label);
    verifyGpgInformation();

    if (ChannelFactory.doesChannelNameExist(name)) {
      throw new InvalidChannelNameException(
          name,
          InvalidChannelNameException.Reason.NAME_IN_USE,
          "edit.channel.invalidchannelname.nameinuse",
          name);
    }

    if (ChannelFactory.doesChannelLabelExist(label)) {
      throw new InvalidChannelLabelException(
          label,
          InvalidChannelLabelException.Reason.LABEL_IN_USE,
          "edit.channel.invalidchannellabel.labelinuse",
          label);
    }

    ChannelArch ca = ChannelFactory.findArchByLabel(archLabel);
    if (ca == null) {
      throw new IllegalArgumentException("Invalid architecture label");
    }

    ChecksumType ct = ChannelFactory.findChecksumTypeByLabel(checksum);

    Channel c = ChannelFactory.createChannel();
    c.setLabel(label);
    c.setName(name);
    c.setSummary(summary);
    c.setDescription(description);
    c.setOrg(user.getOrg());
    c.setBaseDir("/dev/null");
    c.setChannelArch(ca);
    c.setChecksumType(ct);
    c.setGPGKeyId(gpgKeyId);
    c.setGPGKeyUrl(gpgKeyUrl);
    c.setGPGKeyFp(gpgKeyFp);
    c.setAccess(access);
    c.setMaintainerName(maintainerName);
    c.setMaintainerEmail(maintainerEmail);
    c.setMaintainerPhone(maintainerPhone);
    c.setSupportPolicy(supportPolicy);

    // handles either parent id or label
    setParentChannel(c, user, parentLabel, parentId);

    c.addChannelFamily(user.getOrg().getPrivateChannelFamily());

    // need to save before calling stored proc below
    ChannelFactory.save(c);

    ChannelManager.queueChannelChange(c.getLabel(), "createchannel", "createchannel");
    ChannelFactory.refreshNewestPackageCache(c, WEB_CHANNEL_CREATED);

    return c;
  }
  /** {@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 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);
  }
 /** {@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);
 }