Hi All,
I'm new to AEM please let me know if anyone has idea on below scenario.
I'm working on dam assets - I would like to delete assets from one particular folder after some specific time So Im using scheduler for this requirement, but wanted to know how to get all assets from a folder So that once i get list of assets from folder will try to read the jcr:data of all assets like modified date and based on that will delete the asset once it completes some time in dam.
please suggest if approach is not correct
path will be something like this :- /content/dam/folder
Thanks in advance
Solved! Go to Solution.
Views
Replies
Total Likes
You can use the Assets HTTP API as follows:
https://helpx.adobe.com/ca/experience-manager/6-4/assets/using/mac-api-assets.html
Use Query Builder API to search for all the assets under a folder.
Hello @arunpatidar ..I was trying to use the QueryBuilder to get all the assets using this (type=dam:Asset path=/content/dam p.limit=-1 ) But this seems to be timing out .. I am trying to get all the assets which have renditions ..And i want to iterate over it
Please check https://helpx.adobe.com/experience-manager/6-3/sites/developing/using/troubleshooting-slow-queries.h...
There could be multiple reason like , queries may be not using index or there are more than 100000 nodes.
Please try for subfolder and put condition to include rendition node in the search query.
Views
Replies
Total Likes
Hello @sams16001423
You can utilise the JCR API. The JCR API allows you to query nodes in the JCR with the "JCR_SQL2 search queries". I have provided an example for you below where we are querying for all JCR node-type [dam:AssetContent] under the path "/content/dam/my-project". If results are returned, then we will print each jcr:lastModified (the dam:AssetContent node composes of the jcr:lastModified values). Making a query like this is awesome because you don't need to worry about nested folders.
JCR API - JCR_SQL2 Example Search in the Backend:
private void doExampleSearch(ResourceResolver resolver) throws RepositoryException {
Session session = resolver.adaptTo(Session.class);
QueryManager queryManager = session.getWorkspace().getQueryManager();
String selectQuery = "SELECT * FROM [dam:AssetContent] WHERE ISDESCENDANTNODE ([/content/dam/my-project])";
Query query = queryManager.createQuery(selectQuery, Query.JCR_SQL2);
QueryResult queryResults = query.execute();
if (queryResults != null) {
NodeIterator resultNodes = queryResults.getNodes();
while (resultNodes.hasNext()) {
Node node = resultNodes.nextNode();
System.out.println(node.getProperty("jcr:lastModified").getString();
}
}
}
Before the implementation code, you should familiarize yourself with JCR_SQL2 queries. You can test your queries directly from http://localhost:4502/crx/de/index.jsp; tools (drop-down menu item) > query. A tutorial for JCR_SQL2 query language for beginners can be found here: https://sourcedcode.com/aem-jcr-sql2-tutorial-and-examples-and-cheatsheet.
I hope this helps.
You can use the Assets HTTP API as follows:
https://helpx.adobe.com/ca/experience-manager/6-4/assets/using/mac-api-assets.html
aaaaa
Views
Replies
Total Likes