Expand my Community achievements bar.

How to reverse replicate dam asset using replication api ?

Avatar

Level 2

The scenario I am trying to implement is like this :

End user will submit a custom HTML form with some details and an image ,This will create a new page in publish instance (/content/project).

I need to reverse replicate this page to author , along with the user uploaded image (say a fileReference to dam asset).

But currently the dam asset is not reverse replicating when i use the api , only the page node is appearing in author.

            session = resourceResolver.adaptTo(Session.class);

            Node pageContainer = resource.adaptTo(Node.class);

           

            AssetReferenceSearch referenceSearch = new AssetReferenceSearch(pageContainer,DamConstants.MOUNTPOINT_ASSETS,resourceResolver);

            Map<String, Asset> assetMap = referenceSearch.search();

            AgentIdFilter filter = new AgentIdFilter("outbox");

            ReplicationOptions opts = new ReplicationOptions();

            opts.setFilter(filter);

            if(assetMap.size() > 0){

            for (Map.Entry<String, Asset> entry : assetMap.entrySet())

            {

            Node assetContainer = resourceResolver.getResource(entry.getValue().getPath()+"jcr:content").adaptTo(Node.class);

            assetContainer.setProperty("jcr:lastModified", Calendar.getInstance());

            assetContainer.setProperty("jcr:lastModifiedBy", session.getUserID());

            assetContainer.setProperty("cq:distribute", true);

               replicator.replicate(session , ReplicationActionType.INTERNAL_POLL, entry.getValue().getPath(), opts);

            }

            }

This is what my servlet is trying to do.

Image reference is appearing in the outbox , but in the author replication log it says "Error importing content" and no other logs.

Suggestions please!!

Thanks !!

1 Reply