Expand my Community achievements bar.

SOLVED

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

Avatar

Level 6

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

tushaar_srivastava_0-1671602550430.png

 

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  

 

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

 

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

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

 

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