Skip to main content
Jul 11, 2025 5:48 AM UTC
Solved

Read jcr:created from dam asset json file

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.

SantoshSai
SantoshSaiAccepted solution
Community Advisor
Jul 11, 2025 2:21 PM UTC

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

5 replies

giuseppebaglio
Level 10
Jul 11, 2025 9:44 AM UTC

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."

 
Translate
Jul 11, 2025 11:03 AM UTC

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

 

Translate
giuseppebaglio
Level 10
Jul 14, 2025 8:44 AM UTC

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.

 

 
Translate
SantoshSai
Community Advisor
SantoshSaiCommunity AdvisorAccepted solution
Community Advisor
Jul 11, 2025 2:21 PM UTC

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()); } } }
Translate
Santosh Sai
kautuk_sahni
Level 9
Jul 16, 2025 10:38 AM UTC

@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!

Translate
Kautuk Sahni