Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.
SOLVED

Reverse replication in custom file upload component not works

Avatar

Level 1

I'm trying to write custom file upload component for CQ5.6, but I meet the problem with reverse replication. Node created in Publish instance, but not replicated to Author instance. After replicator call, next line appears in error.log:

com.day.cq.replication.impl.ReplicatorImpl Replication triggered, but no agent found or selected.

Replication agents are turned on. In other cases, userforms for example, replication works successfully, so I'm think the problem is somewhere in my code. There is the code I use in the servlet:

Node node = session.getNode(path); ValueFactory valueFactory = session.getValueFactory(); Binary contentValue = valueFactory.createBinary(is); Node parent = node.addNode(fileName, "nt:unstructured"); parent.setProperty(DELETED, false); parent.setProperty(DESCRIPTION, description); Node fileNode = parent.addNode(fileName, "nt:file"); fileNode.addMixin("mix:referenceable"); Node resNode = fileNode.addNode("jcr:content", "nt:resource"); resNode.setProperty(Property.JCR_DATA, contentValue); Calendar lastModified = Calendar.getInstance(); lastModified.setTimeInMillis(lastModified.getTimeInMillis()); resNode.setProperty(Property.JCR_LAST_MODIFIED, lastModified); parent.setProperty("cq:distribute", true); parent.setProperty("cq:lastModified", Calendar.getInstance()); parent.setProperty("cq:lastModifiedBy", session.getUserID()); session.save(); replicator.replicate(session, ReplicationActionType.ACTIVATE, parent.getPath()); session.logout();

What should I do to make reverse replication works for this nodes I create in servlet?

P.S. I've spent hours reading documentation, but not found any solution.

1 Accepted Solution

Avatar

Correct answer by
Level 10
3 Replies

Avatar

Level 2

Igor,

Please check CQ-Actions library: https://github.com/Cognifide/CQ-Actions. Reverse-replication is just a four liner there and you've got already an entry point for author-processing (like replication to other publishers). You can of course skip processing path leaving just reverse-replication helper.

@Reference ActionRegistryService actionRegistryService; ... Node node = actionRegistryService.createActionNode(session, relPath, "my-action"); node.setProperty(name, value); session.save();

 

@Service @Component public class MyAction implements Action { private final static LOGGER = LoggerFactory.getLogger(MyAction.class); @Override public void perform(Page page) throws Exception { LOGGER.info("performing action"); } public String getType() { return "my-action"; } }

Avatar

Correct answer by
Level 10