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);
  }
  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);
  }
  /**
   * 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);
    }
  }
Esempio n. 5
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;
 }