Replication

Avatar

Avatar
Validate 10
Level 2
rk39193348
Level 2

Like

1 like

Total Posts

92 posts

Correct reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 10
Level 2
rk39193348
Level 2

Like

1 like

Total Posts

92 posts

Correct reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 1
Affirm 1
View profile
rk39193348
Level 2

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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Springboard
Level 7
KiranVedantam1992
Level 7

Likes

195 likes

Total Posts

208 posts

Correct reply

60 solutions
Top badges earned
Springboard
Give Back 5
Ignite 1
Affirm 50
Validate 1
View profile

Avatar
Springboard
Level 7
KiranVedantam1992
Level 7

Likes

195 likes

Total Posts

208 posts

Correct reply

60 solutions
Top badges earned
Springboard
Give Back 5
Ignite 1
Affirm 50
Validate 1
View profile
KiranVedantam1992
Level 7

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

Answers (3)

Answers (3)

Avatar

Avatar
Establish
MVP
Anudeep_Garnepudi
MVP

Likes

275 likes

Total Posts

320 posts

Correct reply

87 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Establish
MVP
Anudeep_Garnepudi
MVP

Likes

275 likes

Total Posts

320 posts

Correct reply

87 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
Anudeep_Garnepudi
MVP

01-03-2021

@rk39193348 

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

Avatar

Avatar
Ignite 1
MVP
Ankur_Khare
MVP

Likes

159 likes

Total Posts

370 posts

Correct reply

58 solutions
Top badges earned
Ignite 1
Validate 10
Validate 1
Give Back 50
Give Back 5
View profile

Avatar
Ignite 1
MVP
Ankur_Khare
MVP

Likes

159 likes

Total Posts

370 posts

Correct reply

58 solutions
Top badges earned
Ignite 1
Validate 10
Validate 1
Give Back 50
Give Back 5
View profile
Ankur_Khare
MVP

26-02-2021

Could you pls add logs..

Avatar

Avatar
Establish
MVP
Ravi_Pampana
MVP

Likes

197 likes

Total Posts

243 posts

Correct reply

75 solutions
Top badges earned
Establish
Contributor
Shape 1
Ignite 5
Ignite 3
View profile

Avatar
Establish
MVP
Ravi_Pampana
MVP

Likes

197 likes

Total Posts

243 posts

Correct reply

75 solutions
Top badges earned
Establish
Contributor
Shape 1
Ignite 5
Ignite 3
View profile
Ravi_Pampana
MVP

26-02-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
Yes I am getting replicator as null. Can you please let me know what needs to be done?
Ravi_Pampana

Is your code have @reference added to the replicator 

 

@Reference

private Replicator replicator;

rk39193348
Can you please share sample code?
rk39193348
yes i have this line @reference private Replicator replicator;
Ravi_Pampana
rk39193348
I followed that article still i am getting null
rk39193348
I am getting replicator as null. Do you know what needs to be done?
Ravi_Pampana
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.
rk39193348
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); } } }
rk39193348
I checked the system/console class is active