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
Solved! Go to Solution.
Views
Replies
Total Likes
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
Hi,
See whether the user (session) is having replication access and check there are any exceptions in error.log like replicator is not null.
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Views
Replies
Total Likes
Could you pls add logs..
Views
Replies
Total Likes
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
Views
Replies
Total Likes
Are you able to publish the page manually? The code that you shared seems ok.
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies