Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Replication

Avatar

Level 4

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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

View solution in original post

16 Replies

Avatar

Community Advisor

Hi,

 

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

 

 

Avatar

Level 4
Yes I am getting replicator as null. Can you please let me know what needs to be done?

Avatar

Community Advisor

Is your code have @reference added to the replicator 

 

@Reference

private Replicator replicator;

Avatar

Level 4
I followed that article still i am getting null

Avatar

Level 4
I am getting replicator as null. Do you know what needs to be done?

Avatar

Community Advisor
Can you check, that the service is properly registered within OSGI? Go to https://<host>:<port>/system/console/components and look for your class. If it is active and still getting replicator as null, share your complete file for checking further.

Avatar

Level 4
package com.aem.community.core.workflow; import javax.jcr.Node; import com.day.cq.replication.Replicator; import org.osgi.service.component.annotations.Component; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.day.cq.replication.ReplicationActionType; import com.day.cq.workflow.WorkflowException; 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 javax.jcr.Node; import com.adobe.cq.sightly.WCMUsePojo; import org.apache.felix.scr.annotations.Reference; import org.apache.sling.api.resource.ResourceResolver; import org.apache.sling.api.resource.ResourceResolverFactory; import com.day.cq.replication.ReplicationOptions; import org.osgi.service.component.ComponentContext; @component(service = WorkflowProcess.class, property = { "process.label = dummy" }) 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); } } }

Avatar

Level 4
I have added the logs.. please let me know what needs to be done.

Avatar

Correct answer by
Community Advisor

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

Avatar

Community Advisor

@rk39193348 

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