[AEM6.5] Read multiple Properties from a Node and perform action | Community
Skip to main content
tushaar_srivastava
Level 6
December 21, 2022
Solved

[AEM6.5] Read multiple Properties from a Node and perform action

  • December 21, 2022
  • 2 replies
  • 1160 views

Hi All,
I have a basic requirement where I have a Image and havings it's custom rendition under /content/dam/test/Test.jpg/jcr:content/metadata/customRendition

 

Now I have to readthe values of properties from /content/dam/test/Test.jpg/jcr:content/metadata/customRendition which holds the path of assets [in given case it is prop1, prop2, prop3...] and unpublish those path.

For unpublishing we can use replicator.replicate(__,ReplicationActionType.DEACTIVATE).

But How o read the values of properties, and in our case property name is prop1, prop2, prop3 and so on...

Similarly we have to read all the values from all properties and it is not fixed.

 

// Get the current node Node currentNode = resourceResolver.getResource("/content/dam/test/Test.jpg/jcr:content/metadata/customRendition").adaptTo(Node.class); // Get the properties PropertyIterator properties = currentNode.getProperties(); // Iterate over properties while (properties.hasNext()) { Property property = properties.nextProperty(); String propertyName = property.getName(); // Check if the property is prop1, prop2, prop3 if (propertyName.equals("prop1") || propertyName.equals("prop2") || propertyName.equals("prop3")) { // Get the asset paths String assetPath = property.getValue().getString(); // Get the asset node Node assetNode = resourceResolver.getResource(assetPath).adaptTo(Node.class);

we can use Property Iterator but since we don't have fixed set of properties in that case how to check for properties.equal condition?

 

 

Thanks

 

@kautuk_sahni  @arunpatidar  @briankasingli  @theo_pendle  

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by arunpatidar

 

Resource resource = resourceResolver.getResource("/content/dam/test/Test.jpg/jcr:content/metadata/customRendition"); ValueMap properties = resource.getValueMap(); for(Entry<String, Object> e : properties.entrySet()) { String key = e.getKey(); Object value = e.getValue(); //use the key and value here }

 

2 replies

walterch
December 21, 2022

I would suggest to use the query api like this:

 

https://gist.github.com/munim/e03a3f418dbc29cc912c1fc5c4eaeb87

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
December 21, 2022

 

Resource resource = resourceResolver.getResource("/content/dam/test/Test.jpg/jcr:content/metadata/customRendition"); ValueMap properties = resource.getValueMap(); for(Entry<String, Object> e : properties.entrySet()) { String key = e.getKey(); Object value = e.getValue(); //use the key and value here }

 

Arun Patidar