Replication

Avatar

Avatar

rk39193348

Avatar

rk39193348

rk39193348

26-02-2021

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

View Entire Topic

Avatar

Avatar

KiranVedantam1992

Avatar

KiranVedantam1992

KiranVedantam1992

27-02-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