public void testPossiblePackagesForPushingIntoChannel() throws Exception {
   Errata e = ErrataFactoryTest.createTestPublishedErrata(user.getOrg().getId());
   Channel c = ChannelTestUtils.createTestChannel(user);
   DataResult dr =
       PackageManager.possiblePackagesForPushingIntoChannel(c.getId(), e.getId(), null);
   assertTrue(dr.size() > 0);
 }
  /**
   * Adds references info from the errata
   *
   * @param erratum erratum to be added
   * @throws SAXException
   */
  private void addErratumReferences(Errata erratum) throws SAXException {
    handler.startElement("references");

    Iterator iter = erratum.getBugs().iterator();
    while (iter.hasNext()) {
      Bug bug = (Bug) iter.next();

      SimpleAttributesImpl attr = new SimpleAttributesImpl();
      attr.addAttribute(
          "href", "http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=" + bug.getId());
      attr.addAttribute("id", Long.toString(bug.getId()));
      attr.addAttribute("type", "bugzilla");
      handler.startElement("reference", attr);
      handler.addCharacters(bug.getSummary());
      handler.endElement("reference");
    }

    iter = erratum.getCves().iterator();
    while (iter.hasNext()) {
      Cve cve = (Cve) iter.next();

      SimpleAttributesImpl attr = new SimpleAttributesImpl();
      attr.addAttribute("href", "http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=" + cve);
      attr.addAttribute("id", sanitize(0, cve.getName()));
      attr.addAttribute("type", "cve");
      handler.startElement("reference", attr);
      handler.endElement("reference");
    }

    handler.endElement("references");
  }
  /** {@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());
  }
  /**
   * Add erratum to repodata for given channel
   *
   * @param erratum erratum to be added
   * @param channel channel info
   * @throws SAXException
   */
  private void addErratum(Errata erratum, Channel channel) throws SAXException {
    SimpleAttributesImpl attr = new SimpleAttributesImpl();
    attr.addAttribute("from", "*****@*****.**");
    attr.addAttribute("status", "final");
    attr.addAttribute("type", mapAdvisoryType(erratum.getAdvisoryType()));
    attr.addAttribute("version", Long.toString(erratum.getAdvisoryRel()));
    handler.startElement("update", attr);

    handler.addElementWithCharacters("id", sanitize(0, erratum.getAdvisoryName()));
    handler.addElementWithCharacters("title", sanitize(0, erratum.getSynopsis()));

    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    attr.clear();
    attr.addAttribute("date", df.format(erratum.getIssueDate()));
    handler.startElement("issued", attr);
    handler.endElement("issued");

    attr.clear();
    attr.addAttribute("date", df.format(erratum.getUpdateDate()));
    handler.startElement("updated", attr);
    handler.endElement("updated");

    handler.addElementWithCharacters("description", sanitize(0, erratum.getDescription()));

    addErratumReferences(erratum);
    addErratumPkgList(erratum, channel);

    handler.endElement("update");
  }
  /**
   * Adds packages associated to the errata
   *
   * @param erratum erratum to be added
   * @param channel channel info
   * @throws SAXException
   */
  private void addErratumPkgList(Errata erratum, Channel channel) throws SAXException {
    handler.startElement("pkglist");

    SimpleAttributesImpl attr = new SimpleAttributesImpl();
    attr.addAttribute("short", channel.getLabel());
    handler.startElement("collection", attr);

    handler.addElementWithCharacters("name", channel.getName());

    Iterator iter = erratum.getPackages().iterator();

    while (iter.hasNext()) {
      Package pkg = (Package) iter.next();
      if (channel.getPackages().contains(pkg)) {
        long pkgId = pkg.getId();
        String epoch = pkg.getPackageEvr().getEpoch();
        if (epoch == null || epoch.length() == 0) {
          epoch = "0";
        }
        attr.clear();
        attr.addAttribute("name", sanitize(pkgId, pkg.getPackageName().getName()));
        attr.addAttribute("version", sanitize(pkgId, pkg.getPackageEvr().getVersion()));
        attr.addAttribute("release", sanitize(pkgId, pkg.getPackageEvr().getRelease()));
        attr.addAttribute("epoch", sanitize(pkgId, epoch));
        attr.addAttribute("arch", sanitize(pkgId, pkg.getPackageArch().getLabel()));
        attr.addAttribute("src", sanitize(pkgId, pkg.getSourceRpm().getName()));
        handler.startElement("package", attr);

        handler.addElementWithCharacters("filename", sanitize(pkgId, pkg.getFilename()));

        attr.clear();
        attr.addAttribute("type", sanitize(pkgId, pkg.getChecksum().getChecksumType().getLabel()));
        handler.startElement("sum", attr);
        handler.addCharacters(sanitize(pkgId, pkg.getChecksum().getChecksum()));
        handler.endElement("sum");

        handler.endElement("package");
      }
    }

    handler.endElement("collection");

    handler.endElement("pkglist");
  }