Replication | Community
Skip to main content
rk39193348
New Participant
February 26, 2021
Solved

Replication

  • February 26, 2021
  • 4 replies
  • 4633 views

Hi 

I want to activate page through workflow in aem 6.5. I have created a java class and added following line:

"replicator.replicate(session, ReplicationActionType.ACTIVATE, payloadPath);"

still page is not activating. Any idea what needs to be done?

 

Regards

RK

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

Hi @rk39193348,

 

As per your code, you are using scr annotations which are outdated. Please use the R7 annotations. Try this updated code from my end:

 

import javax.jcr.Node;
import com.day.cq.replication.Replicator;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.day.cq.replication.ReplicationActionType;
import com.day.cq.workflow.WorkflowSession;
import com.day.cq.workflow.exec.WorkItem;
import com.day.cq.workflow.exec.WorkflowProcess;
import com.day.cq.workflow.metadata.MetaDataMap;
import javax.jcr.Session;
import com.day.cq.wcm.api.Page;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;

@Component(service = WorkflowProcess.class, property = { "process.label = Replicate Workflow" })
public class ReplicateWorkflow implements WorkflowProcess {
/** * Logger */
private static final Logger log = LoggerFactory.getLogger(ReplicateWorkflow.class);
private String payloadPath = "";
Node node = null;
Page newPage;
private Session session;
@Reference
protected Replicator replicator;
@Reference
private ResourceResolverFactory resourceResolverFactory;
ResourceResolver resolver;

/** * Overridden method which executes when the workflow is invoked */
@Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) {
try {
payloadPath = workItem.getWorkflowData().getPayload().toString();
log.info("payloadPath**" + payloadPath);
node = (Node) workflowSession.getSession().getItem(payloadPath);
session = node.getSession();
log.info("session**" + session);
replicator.replicate(session, ReplicationActionType.ACTIVATE, payloadPath);
replicator.replicate(session, ReplicationActionType.ACTIVATE, payloadPath);
} catch (Exception e) {
log.error("error***" + e.getMessage(), e);
}
}
}

 

Hope this helps!

 

Thanks,

Kiran Vedantam

4 replies

Anudeep_Garnepudi
New Participant
March 1, 2021

@rk39193348 

Are you able to publish the page manually? The code that you shared seems ok.

Kiran_Vedantam
Kiran_VedantamAccepted solution
New Participant
February 28, 2021

Hi @rk39193348,

 

As per your code, you are using scr annotations which are outdated. Please use the R7 annotations. Try this updated code from my end:

 

import javax.jcr.Node;
import com.day.cq.replication.Replicator;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.day.cq.replication.ReplicationActionType;
import com.day.cq.workflow.WorkflowSession;
import com.day.cq.workflow.exec.WorkItem;
import com.day.cq.workflow.exec.WorkflowProcess;
import com.day.cq.workflow.metadata.MetaDataMap;
import javax.jcr.Session;
import com.day.cq.wcm.api.Page;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;

@Component(service = WorkflowProcess.class, property = { "process.label = Replicate Workflow" })
public class ReplicateWorkflow implements WorkflowProcess {
/** * Logger */
private static final Logger log = LoggerFactory.getLogger(ReplicateWorkflow.class);
private String payloadPath = "";
Node node = null;
Page newPage;
private Session session;
@Reference
protected Replicator replicator;
@Reference
private ResourceResolverFactory resourceResolverFactory;
ResourceResolver resolver;

/** * Overridden method which executes when the workflow is invoked */
@Override
public void execute(WorkItem workItem, WorkflowSession workflowSession, MetaDataMap metaDataMap) {
try {
payloadPath = workItem.getWorkflowData().getPayload().toString();
log.info("payloadPath**" + payloadPath);
node = (Node) workflowSession.getSession().getItem(payloadPath);
session = node.getSession();
log.info("session**" + session);
replicator.replicate(session, ReplicationActionType.ACTIVATE, payloadPath);
replicator.replicate(session, ReplicationActionType.ACTIVATE, payloadPath);
} catch (Exception e) {
log.error("error***" + e.getMessage(), e);
}
}
}

 

Hope this helps!

 

Thanks,

Kiran Vedantam

rk39193348
New Participant
March 1, 2021
This is working. Thanks a lot
Ankur_Khare
New Participant
February 27, 2021

Could you pls add logs..

rk39193348
New Participant
February 27, 2021
I have added the logs.. please let me know what needs to be done.
Ravi_Pampana
New Participant
February 26, 2021

Hi,

 

See whether the user (session) is having replication access and check there are any exceptions in error.log like replicator is not null.

 

 

rk39193348
New Participant
February 26, 2021
Yes I am getting replicator as null. Can you please let me know what needs to be done?