Programatically replicate the asset including all the sub asets | Community
Skip to main content
Selva123
Level 2
Mar 30, 2016 3:29 AM UTC

Programatically replicate the asset including all the sub asets

Hi,

I am using the Replicator API to replicate the asset like below.

replicator.replicate(session, ReplicationActionType.ACTIVATE, asset.getPath());

but somehow subassets are not replicated. Please confirm is there we can replicate all the subassets when the asset has been activated.

I am using the below code and achieving it now. Is there any better way the API or AEM provides. please help.

        Resource resource = resolver.resolve(assetPath);

                   if(resource != null){
                       Asset parentAsset = resource.adaptTo(Asset.class);
                       if(parentAsset != null){
                           Collection<Asset> subAssetCollection = parentAsset.getSubAssets();
                           for(Asset subAsset : subAssetCollection){
                               replicator.replicate(session, ReplicationActionType.ACTIVATE, subAsset.getPath());
                           }
                       }
                   }

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

3 replies

smacdonald2008
Level 10
Apr 1, 2016 5:53 PM UTC

This is a good use case to add to our community articles. 

Translate
kautuk_sahni
Employee
Mar 30, 2016 4:33 AM UTC

[No solution, but good to refer this]

Hi

Please read this post :

Link:- http://stackoverflow.com/questions/18955982/how-to-activate-programmatically-a-page-in-cq5-workflow

//Use Replicator OSGi service:

@Component public class MyComponent { @Reference private Replicator replicator; private void activatePage(Session session) { //... replicator.replicate(session, ReplicationActionType.ACTIVATE, pathToPage); //... } }
Translate
Kautuk Sahni
edubey
Level 10
Mar 30, 2016 4:25 AM UTC

It looks fine to me, 

You are using right asset API and replicator as well.

Other community member will share if there is better way

Translate