Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards.
SOLVED

Read jcr:created from dam asset json file

Avatar

Level 1

This is part of my jcr content json

{
"jcr:primaryType": "dam:Asset",
"jcr:createdBy": "admin",
"jcr:created": "Thu Oct 03 2024 20:15:12 GMT+0530",
"jcr:uuid": "bb43bafd-099d-425b-a0af-a748489a7e98",
"jcr:content": {
"jcr:primaryType": "dam:AssetContent",
"jcr:lastModifiedBy": "admin",
"dam:assetState": "processed",
"jcr:lastModified": "Thu Oct 31 2024 16:23:48 GMT+0530"
}
}

This is how I wrote the query to fetch the assets

QueryBuilder queryBuilder = resourceResolver.adaptTo(QueryBuilder.class);
Map<String, String> queryMap = new HashMap<>();

queryMap.put(SearchConstants.PATH, path);
queryMap.put(SearchConstants.TYPE, DamConstants.NT_DAM_ASSET);
queryMap.put(SearchConstants.PROPERTY, SearchConstants.DAM_SCENE7_FILE_STATUS);
queryMap.put(SearchConstants.PROPERTY_VALUE, Scene7Constants.PV_S7_PUBLISH_COMPLETE);

SearchUtils.addExcludePaths(queryMap, lennoxDocumentLibraryService);

queryMap.put(SearchConstants.P_LIMIT, SearchConstants.MINUS_ONE);
queryMap.put(SearchConstants.P_HITS, SearchConstants.FULL);
Query query = queryBuilder.createQuery(PredicateGroup.create(queryMap), resourceResolver.adaptTo(Session.class));
return query.getResult();

post query search, i tried to iterate the results and read jcr:created property through assetResource.getValueMap(); it always shows "jcr:uuid": "bb43bafd-099d-425b-a0af-a748489a7e98", and  "jcr:primaryType": "dam:Asset". i could not read jcr:created 

for (Hit hit : searchResult.getHits()) {
Resource assetResource = resourceResolver.getResource(hit.getPath());
assetResource.getValueMap();
}

I need to read this jcr:created and add it to my search result response. Could somebody help me on this.

 

Thanks in Advance.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @ManikumarSu,

Could you gie a try to this?

for (Hit hit : searchResult.getHits()) {
    Resource assetResource = resourceResolver.getResource(hit.getPath());
    if (assetResource != null) {
        ValueMap assetProperties = assetResource.getValueMap();
        Calendar jcrCreated = assetProperties.get("jcr:created", Calendar.class);
        
        if (jcrCreated != null) {
            // Format or add this to your response as needed
            log.debug("Asset Created Date: {}", jcrCreated.getTime());
        }
    }
}

Santosh Sai

AEM BlogsLinkedIn


View solution in original post

5 Replies

Avatar

Level 10

hi @ManikumarSu,

This code should accomplish what you need: 

for (Hit hit : searchResult.getHits()) {
    Resource assetResource = resourceResolver.getResource(hit.getPath());
    if (assetResource != null) {
        Resource contentResource = assetResource.getChild("jcr:content");
        if (contentResource != null) {
            ValueMap contentProperties = contentResource.getValueMap();
            String jcrCreated = contentProperties.get("jcr:created", String.class);
            // Add jcrCreated to your response as needed
        }
    }
}

Be cautious not to leave an open resource resolver leakage for queries. Please refer to the section titled "Closing the Resolver for Queries."

 

Avatar

Level 1

Hi Thanks for your reply.   This is not working , I could get the following results only which are available inside jcr:content node.  But I am looking for the jcr:created property which is available above and at the root node

ManikumarSu_0-1752231772325.png

 

Avatar

Level 10

You can try with

Node node = assetResource.adaptTo(Node.class);
String jcrCreated = node.getProperty("jcr:created").getString();

Edit: I've just realized that retrieving the "jcr:content" node may be incorrect.

 

 

Avatar

Correct answer by
Community Advisor

Hi @ManikumarSu,

Could you gie a try to this?

for (Hit hit : searchResult.getHits()) {
    Resource assetResource = resourceResolver.getResource(hit.getPath());
    if (assetResource != null) {
        ValueMap assetProperties = assetResource.getValueMap();
        Calendar jcrCreated = assetProperties.get("jcr:created", Calendar.class);
        
        if (jcrCreated != null) {
            // Format or add this to your response as needed
            log.debug("Asset Created Date: {}", jcrCreated.getTime());
        }
    }
}

Santosh Sai

AEM BlogsLinkedIn


Avatar

Administrator

@ManikumarSu Just checking in — were you able to resolve your issue?
We’d love to hear how things worked out. If the suggestions above helped, marking a response as correct can guide others with similar questions. And if you found another solution, feel free to share it — your insights could really benefit the community. Thanks again for being part of the conversation!



Kautuk Sahni