Read jcr:created from dam asset json file | Community
Skip to main content
July 11, 2025
Solved

Read jcr:created from dam asset json file

  • July 11, 2025
  • 3 replies
  • 560 views

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.

Best answer by SantoshSai

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()); } } }

3 replies

giuseppebaglio
Level 10
July 11, 2025

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

 
July 11, 2025

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

 

giuseppebaglio
Level 10
July 14, 2025

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.

 

 
SantoshSai
Community Advisor
SantoshSaiCommunity AdvisorAccepted solution
Community Advisor
July 11, 2025

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
kautuk_sahni
Community Manager
Community Manager
July 16, 2025

@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