How to get Expiry Assets from DAM in AEM 6.3?

1.3k Views Asked by At

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.

1

There are 1 best solutions below

0
Sudheer Donaboina On

There are a couple of ways to search for the expired Assets in AEM.

Option 1: If it is only for view purpose you can use the AEM search from the AEM console

  • Enter the DAM folder path you would like to check the expired assets (Or Leave it empty to search the whole repository)
  • Select the FileType as "Images" (Or leave it empty to search all the assets)
  • Check the "Expired" checkbox under "Status" filter

    The above filters should show you all the expired assets

Option 2: Query to retrieve 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.

path=/content/dam/<site>
type=dam:Asset
property=@jcr:content/metadata/prism:expirationDate
property.operation=exists