I have created the object of the Replictor using Reference annotation in my Java servlet:
import com.day.cq.replication.Replicator;
import com.day.cq.replication.Replicator;
@Reference
Replicator replicator;
@Reference
private transient ResourceResolverFactory resourceResolverFactory;
Now get the resourceResolver from the service user and get the Session out of it.
Map<String, Object> serviceUserAuth= Collections.singletonMap(ResourceResolverFactory.SUBSERVICE,
"serviceUser");
ResourceResolver resourceResolver = resolverFactory.getServiceResourceResolver(serviceUserAuth);
Session session = resourceResolver.adaptTo(Session.class);
Once you get the session you can use the below code snippet to replicate the node that you have in your code:
replicator.replicate(session,ReplicationActionType.ACTIVATE,node.getPath());
Map<String, Object> serviceUserAuth= Collections.singletonMap(ResourceResolverFactory.SUBSERVICE,
"serviceUser");
ResourceResolver resourceResolver = resolverFactory.getServiceResourceResolver(serviceUserAuth);
Session session = resourceResolver.adaptTo(Session.class);
Once you get the session you can use the below code snippet to replicate the node that you have in your code:
replicator.replicate(session,ReplicationActionType.ACTIVATE,node.getPath());
No comments:
Post a Comment
If you have any doubts or questions, please let us know.