Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

how to get all assets from a folder under content dam folder in aem

Avatar

Avatar
Validate 1
Level 1
sams16001423
Level 1

Likes

0 likes

Total Posts

8 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
sams16001423
Level 1

Likes

0 likes

Total Posts

8 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Affirm 1
View profile
sams16001423
Level 1

21-02-2020

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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Give Back 5
Employee
sunjot16
Employee

Likes

104 likes

Total Posts

164 posts

Correct Reply

50 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back 25
Give Back 10
Give Back
View profile

Avatar
Give Back 5
Employee
sunjot16
Employee

Likes

104 likes

Total Posts

164 posts

Correct Reply

50 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back 25
Give Back 10
Give Back
View profile
sunjot16
Employee

24-02-2020

Answers (2)

Answers (2)

Avatar

Avatar
Establish
MVP
BrianKasingli
MVP

Likes

613 likes

Total Posts

590 posts

Correct Reply

231 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Establish
MVP
BrianKasingli
MVP

Likes

613 likes

Total Posts

590 posts

Correct Reply

231 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
BrianKasingli
MVP

22-02-2020

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.

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,356 likes

Total Posts

3,227 posts

Correct Reply

917 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,356 likes

Total Posts

3,227 posts

Correct Reply

917 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

21-02-2020

Use Query Builder API to search for all the assets under a folder.