0
votes

I have parent asset node inside the AEM CRXDE (/content/dam/parent). inside the parent node folder multiple child nodes are there .

Using Asset API how can i iterate the child nodes.?

After that i have to read/write properties.!

Code here:-

AssetManager assetManager=resolver.adaptTo(AssetManager.class);

Asset damAsset =assetManager.getAsset("/content/dam/parent");

Inside the parent node i have multiple child nodes. ex:-

  • /content/dam/parent/child1
  • /content/dam/parent/child2
  • /content/dam/parent/child3 I need to access and read/write properties of these nodes.!
2
Show us what you have done - can't do much without showing us what you're actually going on about.OcelotcR
@OcelotcR i have updated the Question!aem crook
What's the type of the /content/dam/parent node?iusting
/content/dam/parent node is sling folderaem crook
why access sling folder as asset ? can you not do resolver.getResource('/content/dam/parent') and do getChildren on it ?Sharath Madappa

2 Answers

0
votes

You can not get an Asset object from a non asset resource (a folder). The call to the getAsset method in your code will return a null, which is normal and as expected!

If you need to obtain the dam:Asset children, use the solution Sharath Madappa suggested in the comment to your question or even a SQL2 query like:

final Iterator<Resource> allAssetChildren = resolver.findResources( String.format("SELECT * FROM [dam:Asset] AS node WHERE ISDESCENDANTNODE(node,'%s')", "/content/dam/parent"), javax.jcr.query.Query.JCR_SQL2 );

Finally, you can adapt any of the obtained resources to an Asset object using the adaptTo framework.

0
votes

Generally dam:Asset will not have children of type dam:Asset. An exception being sub assets. Sub assets are generated in situations where the main asset is composite. Few examples

  • PDF, each page is extracted as a sub asset.
  • PSD, each layer is extracted as a sub asset.
  • Sub assets are extracted from AI story board.

In all such cases, the convention is to have these within a specific subfolder called subassets. When dealing with an Asset you can use getSubAssets method.

You cannot get a valid asset object by adapting folder node to Asset. To get assets in a folder use getChildren on the resource.

If you need to look within sub folders try node iteration/tree traversal for simpler use cases. You can use Sling Query with the right search strategy.

JCR queries are not the most performant choice and you should only use if tree traversal is not an option for the use case.