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);
 }
Exemplo n.º 2
0
  private Long findTopmostParentAction(Long startingAction) {
    SelectMode select =
        ModeFactory.getMode(
            TaskConstants.MODE_NAME, TaskConstants.TASK_QUERY_KSCLEANUP_FIND_PREREQ_ACTION);
    Map params = new HashMap();
    params.put("action_id", startingAction);
    if (log.isDebugEnabled()) {
      log.debug("StartingAction: " + startingAction);
    }

    Long retval = startingAction;
    Long preqid = startingAction;
    DataResult dr = select.execute(params);
    if (log.isDebugEnabled()) {
      log.debug("dr: " + dr);
    }

    while (dr.size() > 0 && preqid != null) {
      preqid = (Long) ((Map) dr.get(0)).get("prerequisite");
      if (preqid != null) {
        retval = preqid;
        params.put("action_id", retval);
        dr = select.execute(params);
      }
    }
    if (log.isDebugEnabled()) {
      log.debug("preqid: " + preqid);
      log.debug("Returning: " + retval);
    }

    return retval;
  }
Exemplo n.º 3
0
  /**
   * Returns PackageOverviews from a search.
   *
   * @param pids List of package ids returned from search server.
   * @param archLabels List of channel arch labels.
   * @param relevantUserId user id to filter by if relevant or architecture search server the user
   *     can see is subscribed to
   * @param filterChannelId channel id to filter by if channel search
   * @param searchType type of search to do, one of "relevant", "channel", "architecture", or "all"
   * @return PackageOverviews from a search.
   */
  public static List<PackageOverview> packageSearch(
      List<Long> pids,
      List<String> archLabels,
      Long relevantUserId,
      Long filterChannelId,
      String searchType) {
    Map<String, Object> params = new HashMap<String, Object>();
    SelectMode m = null;

    if (searchType.equals(PackageSearchAction.ARCHITECTURE)) {
      if (!(archLabels != null && archLabels.size() > 0)) {
        throw new MissingArchitectureException(
            "archLabels must not be null for architecture search!");
      }

      // This makes me very sad. PreparedSatement.setObject does not allow
      // you to pass in Lists or Arrays. We can't manually convert archLabels
      // to a string and use the regular infrastructure because it will
      // escape the quotes between architectures. The only thing we can do
      // is to get the SelectMode and manually insert the architecture types
      // before we continue. If we can get PreparedStatement to accept Lists
      // then all this hackishness can go away. NOTE: we know that we have to
      // guard against sql injection in this case. Notice that the archLabels
      // will all be enclosed in single quotes. Valid archLabels will only
      // contain alphanumeric, '-', and "_" characters. We will simply
      // check and enforce that constraint, and then even if someone injected
      // something we would either end up throwing an error or it would be
      // in a string, and therefore not dangerous.
      m = ModeFactory.getMode("Package_queries", "searchByIdAndArches");
      CachedStatement cs = m.getQuery();
      String query = cs.getOrigQuery();
      String archString = "'" + sanitizeArchLabel(archLabels.get(0)) + "'";
      for (int i = 1; i < archLabels.size(); i++) {
        archString += ", '" + sanitizeArchLabel(archLabels.get(i)) + "'";
      }
      query = query.replace(":channel_arch_labels", archString);
      cs.setQuery(query);
      m.setQuery(cs);
    } else if (searchType.equals(PackageSearchAction.RELEVANT)) {
      if (relevantUserId == null) {
        throw new IllegalArgumentException("relevantUserId must not be null for relevant search!");
      }
      params.put("uid", relevantUserId);
      m = ModeFactory.getMode("Package_queries", "relevantSearchById");
    } else if (searchType.equals(PackageSearchAction.CHANNEL)) {
      if (filterChannelId == null) {
        throw new IllegalArgumentException("filterChannelId must not be null for channel search!");
      }
      params.put("cid", filterChannelId);
      m = ModeFactory.getMode("Package_queries", "searchByIdInChannel");
    } else {
      m = ModeFactory.getMode("Package_queries", "searchById");
    }

    // SelectMode.execute will batch the size properly and CachedStatement.execute
    // will create a comma separated string representation of the list of pids
    DataResult result = m.execute(params, pids);
    result.elaborate();
    return result;
  }
Exemplo n.º 4
0
  /**
   * Primarily a convenience method to make testing easier
   *
   * @param ctx Quartz job runtime environment
   * @throws JobExecutionException Indicates somes sort of fatal error
   */
  public void execute(JobExecutionContext ctx) throws JobExecutionException {
    try {
      SelectMode select =
          ModeFactory.getMode(
              TaskConstants.MODE_NAME, TaskConstants.TASK_QUERY_KSCLEANUP_FIND_CANDIDATES);
      DataResult dr = select.execute(Collections.EMPTY_MAP);
      if (log.isDebugEnabled()) {
        log.debug("Found " + dr.size() + " entries to process");
      }
      // Bail early if no candidates
      if (dr.size() == 0) {
        return;
      }

      Long failedStateId = findFailedStateId();
      if (failedStateId == null) {
        log.warn("Failed kickstart state id not found");
        return;
      }
      for (Iterator iter = dr.iterator(); iter.hasNext(); ) {
        Map row = (Map) iter.next();
        processRow(failedStateId, row);
      }
    } catch (Exception e) {
      log.error(e.getMessage(), e);
      throw new JobExecutionException(e);
    }
  }
  public void testSystemPackageList() throws Exception {
    // need a system
    // need to add packages to that system
    // then need to query those values
    PageControl pc = new PageControl();
    pc.setIndexData(false);
    pc.setStart(1);

    user.addRole(RoleFactory.ORG_ADMIN);

    Server server = ServerFactoryTest.createTestServer(user, true);
    PackageManagerTest.addPackageToSystemAndChannel(
        "test-package-name" + TestUtils.randomString(),
        server,
        ChannelFactoryTest.createTestChannel(user));

    DataResult dr = PackageManager.systemPackageList(server.getId(), pc);
    assertNotNull(dr);
    assertEquals(1, dr.size());

    for (Iterator itr = dr.iterator(); itr.hasNext(); ) {
      Object o = itr.next();
      assertTrue(o instanceof PackageListItem);
    }
  }
  /** {@inheritDoc} */
  protected void render(User user, PageControl pc, HttpServletRequest request) {
    LocalizationService ls = LocalizationService.getInstance();
    DataResult<SystemOverview> isdr = SystemManager.inactiveListSortbyCheckinTime(user, pc);
    String inactiveSystemCSSTable = null;
    if (!isdr.isEmpty()) {
      for (Iterator<SystemOverview> i = isdr.iterator(); i.hasNext(); ) {
        SystemOverview so = i.next();
        StringBuilder buffer = new StringBuilder();
        Long lastCheckin = so.getLastCheckinDaysAgo();
        if (lastCheckin.compareTo(new Long(1)) < 0) {
          buffer.append(lastCheckin * 24);
          buffer.append(' ');

          buffer.append(ls.getMessage("filter-form.jspf.hours"));
        } else if (lastCheckin.compareTo(new Long(7)) < 0) {
          buffer.append(so.getLastCheckinDaysAgo().longValue());
          buffer.append(' ');
          buffer.append(ls.getMessage("filter-form.jspf.days"));
        } else if (lastCheckin.compareTo(new Long(7)) >= 0) {
          buffer.append(lastCheckin.longValue() / 7);
          buffer.append(' ');
          buffer.append(ls.getMessage("filter-form.jspf.weeks"));
        }

        so.setLastCheckinString(buffer.toString());
      }
      request.setAttribute(INACTIVE_SYSTEM_LIST, isdr);
    } else {
      inactiveSystemCSSTable =
          RendererHelper.makeEmptyTable(
              true, "inactivelist.jsp.header", "yourrhn.jsp.noinactivesystems");
      request.setAttribute(INACTIVE_SYSTEMS_EMPTY, inactiveSystemCSSTable);
    }
    RendererHelper.setTableStyle(request, INACTIVE_SYSTEMS_CLASS);
  }
  /** {@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());
  }
Exemplo n.º 8
0
 private Long findFailedStateId() {
   Long retval = null;
   SelectMode select =
       ModeFactory.getMode(
           TaskConstants.MODE_NAME, TaskConstants.TASK_QUERY_KSCLEANUP_FIND_FAILED_STATE_ID);
   DataResult dr = select.execute(Collections.EMPTY_MAP);
   if (dr.size() > 0) {
     retval = (Long) ((Map) dr.get(0)).get("id");
   }
   return retval;
 }
  // This test only works if you have Channels syched to your sat
  public void xxxxPackageNamesByCapability() throws Exception {

    /*user.addRole(RoleFactory.ORG_ADMIN);
    Channel c = ChannelFactoryTest.createTestChannel(user);
    Package pak = addPackageToChannel(user, TestUtils.randomString(), c);
    PackageCapability cap = PackageCapabilityTest.createTestCapability();*/
    DataResult dr =
        PackageManager.packageNamesByCapability(user.getOrg(), "rhn.kickstart.boot_image");
    assertNotNull(dr);
    assertTrue(dr.size() > 0);
  }
Exemplo n.º 10
0
 /**
  * If we do not know the host for a virtual system, insert a 'fake' system into the list before
  * the current one.
  *
  * @param result list of nodes to solve
  */
 public static void processList(DataResult result) {
   for (int i = 0; i < result.size(); i++) {
     VirtualSystemOverview current = (VirtualSystemOverview) result.get(i);
     if ((current.getUuid() != null) && (current.getHostSystemId() == null)) {
       VirtualSystemOverview fakeSystem = new VirtualSystemOverview();
       fakeSystem.setServerName(FAKENODE_LABEL);
       fakeSystem.setHostSystemId(new Long(0));
       result.add(i, fakeSystem);
       i++;
     }
   }
 }
    /** {@inheritDoc} */
    public List getResult(RequestContext ctx) {
      Long sid = ctx.getParamAsLong(RequestContext.SID);
      User user = ctx.getCurrentUser();

      KickstartScheduleCommand cmd = getKickstartScheduleCommand(sid, user);
      DataResult profiles = cmd.getKickstartProfiles();
      if (profiles.size() == 0) {
        addMessage(ctx.getRequest(), "kickstart.schedule.noprofiles");
        ctx.getRequest().setAttribute(HAS_PROFILES, Boolean.FALSE.toString());
      } else {
        ctx.getRequest().setAttribute(HAS_PROFILES, Boolean.TRUE.toString());
      }
      return profiles;
    }
Exemplo n.º 12
0
  public void testDeleteKey() throws Exception {

    // default setup already includes a custom key; therefore, let's
    // grab the initial size
    DataResult initialKeys = SystemManager.listDataKeys(admin);

    handler.createKey(admin, "testlabel", "test description");
    DataResult result = SystemManager.listDataKeys(admin);
    assertEquals(initialKeys.size() + 1, result.size());

    boolean foundKey = false;
    for (Iterator itr = result.iterator(); itr.hasNext(); ) {
      CustomDataKeyOverview key = (CustomDataKeyOverview) itr.next();
      if (key.getLabel().equals("testlabel") && key.getDescription().equals("test description")) {
        foundKey = true;
        break;
      }
    }
    assertTrue(foundKey);

    handler.deleteKey(admin, "testlabel");
    result = SystemManager.listDataKeys(admin);
    assertEquals(initialKeys.size(), result.size());

    foundKey = false;
    for (Iterator itr = result.iterator(); itr.hasNext(); ) {
      CustomDataKeyOverview key = (CustomDataKeyOverview) itr.next();
      if (key.getLabel().equals("testlabel") && key.getDescription().equals("test description")) {
        foundKey = true;
        break;
      }
    }
    assertFalse(foundKey);
  }
Exemplo n.º 13
0
  /**
   * Returns true if the Package with the given name and evr ids exists in the Channel whose id is
   * cid.
   *
   * @param cid Channel id to look in
   * @param nameId Package name id
   * @param evrId Package evr id
   * @return true if the Package with the given name and evr ids exists in the Channel whose id is
   *     cid.
   */
  public static boolean isPackageInChannel(Long cid, Long nameId, Long evrId) {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("cid", cid);
    params.put("name_id", nameId);
    params.put("evr_id", evrId);
    SelectMode m = ModeFactory.getMode("Channel_queries", "is_package_in_channel");
    DataResult dr = m.execute(params);
    if (dr.isEmpty()) {
      return false;
    }

    BooleanWrapper bw = (BooleanWrapper) dr.get(0);
    return bw.booleanValue();
  }
Exemplo n.º 14
0
  public void testPackageNamesByCapabilityAndChannel() throws Exception {
    Channel channel1 = ChannelFactoryTest.createTestChannel(user);
    addKickstartPackageToChannel(ConfigDefaults.get().getKickstartPackageName(), channel1);

    // Add a regular non-kickstart package as well:
    PackageManagerTest.addPackageToChannel("Another package", channel1);

    DataResult dr =
        PackageManager.packageNamesByCapabilityAndChannel(
            user.getOrg(), BaseTreeEditOperation.KICKSTART_CAPABILITY, channel1);
    assertNotNull(dr);
    assertEquals(1, dr.size());
    PackageListItem item = (PackageListItem) dr.get(0);
    assertEquals(ConfigDefaults.get().getKickstartPackageName(), item.getName());
  }
Exemplo n.º 15
0
 /**
  * Sort overview DTOs
  *
  * @param dr data result to sort
  * @return sorted data result
  */
 public static DataResult sortOverviews(DataResult dr) {
   Object[] overviews = dr.toArray();
   if (overviews != null && overviews.length > 0) {
     Arrays.sort(overviews, new SystemOverviewComparator());
     return new DataResult(Arrays.asList(overviews));
   }
   return dr;
 }
Exemplo n.º 16
0
  public void testUpgradable() throws Exception {
    Map info =
        ErrataCacheManagerTest.createServerNeededPackageCache(user, ErrataFactory.ERRATA_TYPE_BUG);
    Server s = (Server) info.get("server");
    Package p = (Package) info.get("package");
    p = (Package) TestUtils.saveAndReload(p);

    DataResult<UpgradablePackageListItem> dr = PackageManager.upgradable(s.getId(), null);
    assertFalse(dr.isEmpty());
    boolean containsSamePackage = false;
    for (UpgradablePackageListItem item : dr) {
      if (p.getPackageName().getName().equals(item.getName())) {
        containsSamePackage = true;
      }
      assertTrue(item.getIdCombo().split("\\|").length == 3);
    }
    assertTrue(containsSamePackage);
  }
Exemplo n.º 17
0
 /**
  * Gets the list user ids(Long) taking in DataResult and the key Do we need to make this public?
  *
  * @param dataresult the dataresult object containing the results of a query
  * @param key the key for fetching the value
  * @return Returns the userIds
  */
 private List getListFromResult(DataResult dataresult, String key) {
   List userIds = new ArrayList();
   Iterator iter = dataresult.iterator();
   while (iter.hasNext()) {
     // convert these to Longs
     Long bd = (Long) ((HashMap) iter.next()).get(key);
     userIds.add(bd);
   }
   return userIds;
 }
Exemplo n.º 18
0
  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);
  }
Exemplo n.º 19
0
  public void testUpgradablePackagesFromServerSet() throws Exception {
    // Setup
    User admin = UserTestUtils.findNewUser("ssmUpgradeUser1", "ssmUpgradeOrg1");
    Org org = admin.getOrg();

    //   Create the server and add to the SSM
    Server server = ServerTestUtils.createTestSystem(admin);
    ServerTestUtils.addServersToSsm(admin, server.getId());

    //   Create upgraded package EVR so package will show up from the query
    PackageEvr upgradedPackageEvr = PackageEvrFactory.createPackageEvr("1", "1.0.0", "2");
    upgradedPackageEvr = (PackageEvr) TestUtils.saveAndReload(upgradedPackageEvr);

    ServerTestUtils.populateServerErrataPackages(
        org, server, upgradedPackageEvr, ErrataFactory.ERRATA_TYPE_SECURITY);
    ServerTestUtils.populateServerErrataPackages(
        org, server, upgradedPackageEvr, ErrataFactory.ERRATA_TYPE_BUG);

    // Test
    DataResult result = PackageManager.upgradablePackagesFromServerSet(admin);

    assertTrue(result != null);
    assertEquals(2, result.size());
  }
Exemplo n.º 20
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);
  }
  /**
   * 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;
  }
  /** {@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);
  }