I need to fetch the Expiry assets from DAM ?
I have tried below snippets code. but it is not working.
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServerException, IOException {
try {
ResourceResolver resourceResolver = resolverFactory.getServiceResourceResolver(null);
session = resourceResolver.adaptTo(Session.class);
// create query description as hash map (simplest way, same as form post)
Map<String, String> map = new HashMap<String, String>();
//set QueryBuilder search criteria
map.put("type", "dam:Asset");
map.put("path", "/content/dam/images/rt1");
map.put("property.value", "image/png");
builder = resourceResolver.adaptTo(QueryBuilder.class);
//INvoke the Search query
Query query = builder.createQuery(PredicateGroup.create(map), session);
SearchResult sr = query.getResult();
//write out to the AEM Log file
log.info("Search Results: " + sr.getTotalMatches());
//Create a MAP to store results
Map<String, InputStream> dataMap = new HashMap<String, InputStream>();
// iterating over the results
for (Hit hit : sr.getHits()) {
//Convert the HIT to an asset - each asset will be placed into a ZIP for downloading
String path = hit.getPath();
Resource rs = resourceResolver.getResource(path);
Asset asset = rs.adaptTo(Asset.class);
//We have the File Name and the inputstream
InputStream data = asset.getOriginal().getStream();
String name = asset.getName();
}
}
My code is not working properly.
There are a couple of ways to search for the expired Assets in AEM.
Check the "Expired" checkbox under "Status" filter
The above filters should show you all the expired assets
Expiration date will be stored in the metadata node as "prism:expirationDate"
You can use the below set of properties in your query to get the results.