Skip to content

Instantly share code, notes, and snippets.

@ksurendra
Last active September 11, 2023 10:09
Show Gist options
  • Save ksurendra/f34af635d1ef30b5378656a97bafce4a to your computer and use it in GitHub Desktop.
Save ksurendra/f34af635d1ef30b5378656a97bafce4a to your computer and use it in GitHub Desktop.
Get all properties of an Asset from AEM
Resource resource;
ValueMap mainProperties;
ValueMap assetMetadataProperties;
Resource metadataResource;
ValueMap jcrProperties;
Resource jcrdataResource;
ValueMap allProperties;
for (Hit hit : result.getHits()) {
//LOGGER.info("nHit path="+hit.getPath()+", title="+hit.getTitle()); resource = hit.getResource();
if(null!=resource){ mainProperties = resource.getValueMap();
// Add JCR Properties
jcrdataResource = resource.getChild("jcr:content");
jcrProperties = ResourceUtil.getValueMap(jcrdataResource);
// Add Metadata properties
metadataResource = resource.getChild("jcr:content/metadata");
assetMetadataProperties = ResourceUtil.getValueMap(metadataResource);
// Adding all together
allProperties = new ValueMapDecorator(new HashMap());
allProperties.putAll(hit.getProperties());
allProperties.putAll(mainProperties); // Includes jcr:created createdDate etc.
allProperties.put("jcr:path",hit.getPath()); //Add Path
allProperties.putAll(jcrProperties);
allProperties.putAll(assetMetadataProperties);
//LOGGER.debug("All Asset Properties="+new Gson().toJson(allProperties));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment