private static Resource convertToPojoResource(Resource resource, boolean includeDescendants) {
    Resource pojoResource = new Resource(resource.getId());
    pojoResource.setUuid(resource.getUuid());
    pojoResource.setResourceKey(resource.getResourceKey());
    pojoResource.setResourceType(resource.getResourceType());
    pojoResource.setMtime(resource.getMtime());
    pojoResource.setInventoryStatus(resource.getInventoryStatus());
    Configuration pcCopy = resource.getPluginConfiguration();
    if (pcCopy != null) {
      pcCopy = pcCopy.deepCopy();
    }
    pojoResource.setPluginConfiguration(pcCopy);
    pojoResource.setName(resource.getName());
    pojoResource.setDescription(resource.getDescription());
    pojoResource.setLocation(resource.getLocation());
    pojoResource.setVersion(resource.getVersion());

    if (resource.getParentResource() != null) {
      pojoResource.setParentResource(convertToPojoResource(resource.getParentResource(), false));
    }
    if (includeDescendants) {
      for (Resource childResource : resource.getChildResources()) {
        if (isVisibleInInventory(childResource)) {
          pojoResource.addChildResource(convertToPojoResource(childResource, true));
        }
      }
    }
    return pojoResource;
  }
예제 #2
0
  private Resource createNewResource() throws Exception {
    getTransactionManager().begin();
    Resource resource;

    try {
      try {
        ResourceType resourceType =
            new ResourceType(
                "plat" + System.currentTimeMillis(), "test", ResourceCategory.PLATFORM, null);
        DriftDefinitionTemplate template = new DriftDefinitionTemplate();
        template.setName("test-template");
        DriftDefinition templateDef = new DriftDefinition(new Configuration());
        templateDef.setName("test-template-def");
        template.setTemplateDefinition(templateDef);
        template.setUserDefined(true);
        resourceType.addDriftDefinitionTemplate(template);
        em.persist(resourceType);

        Agent agent = new Agent("testagent", "testaddress", 1, "", "testtoken");
        em.persist(agent);
        em.flush();

        DriftDefinition test1Def = new DriftDefinition(new Configuration());
        test1Def.setName("test-1");

        DriftDefinition test2Def = new DriftDefinition(new Configuration());
        test2Def.setName("test-2");

        resource = new Resource("reskey" + System.currentTimeMillis(), "resname", resourceType);
        resource.setUuid("" + new Random().nextInt());
        resource.setAgent(agent);
        resource.setInventoryStatus(InventoryStatus.COMMITTED);
        resource.addDriftDefinition(test1Def);
        resource.addDriftDefinition(test2Def);
        em.persist(resource);

      } catch (Exception e) {
        System.out.println("CANNOT PREPARE TEST: " + e);
        getTransactionManager().rollback();
        throw e;
      }

      em.flush();
      getTransactionManager().commit();
    } finally {
    }

    return resource;
  }