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;
  }
 private void cleanoutResource(Resource resource) {
   resource.setAncestry(null);
   resource.setAlertDefinitions(Collections.EMPTY_SET);
   resource.setLocation(null);
   resource.setDescription(null);
   resource.setAutoGroupBackingGroups(Collections.EMPTY_LIST);
   resource.setExplicitGroups(Collections.EMPTY_SET);
   resource.setCreateChildResourceRequests(Collections.EMPTY_LIST);
   resource.setDeleteResourceRequests(Collections.EMPTY_LIST);
   resource.setImplicitGroups(Collections.EMPTY_SET);
   resource.setInstalledPackageHistory(Collections.EMPTY_LIST);
   resource.setInstalledPackages(Collections.EMPTY_SET);
   resource.setPluginConfigurationUpdates(Collections.EMPTY_LIST);
   resource.setResourceConfigurationUpdates(Collections.EMPTY_LIST);
   if (resource.getPluginConfiguration() != null) {
     resource.getPluginConfiguration().cleanoutRawConfiguration();
   }
 }