Skip to main content
rk39193348
Level 4
November 28, 2015
Solved

Programatically replicate a page

  • November 28, 2015
  • 11 replies
  • 6600 views

Hi All ,

I have a requirement where i want to programatically activate the pages. I need a program which will parse through the pages and check for "replicated" property. If the property is available the pages should get activated after 30 mins automatically. Can you please please tell me how this can be achieved ??

Awaiting your positive response

Regards

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 smacdonald2008

This would need a custom implementation. I would look at using workflows as part of this solution. 

Write code  that iterates through pages using JCR API or QueryBuilder API. The when you find a page that meets you criteria, invoke a workflow (that activates the page) using an API. You can invoke workflows programmatically. See: 

http://scottsdigitalcommunity.blogspot.ca/2013/09/creating-workflows-for-adobe-experience.html

You may need to write a custom workflow step as well to perform time operations (if you want to wait 30 mins for example)\. However AEM is very flexable in letting you write custom workflow steps. TO learn how to write a custom workflow step that implements , WorkflowProcess see: 

https://helpx.adobe.com/experience-manager/using/creating-custom-aem-workflow-steps.html

11 replies

smacdonald2008
smacdonald2008Accepted solution
Level 10
November 28, 2015

This would need a custom implementation. I would look at using workflows as part of this solution. 

Write code  that iterates through pages using JCR API or QueryBuilder API. The when you find a page that meets you criteria, invoke a workflow (that activates the page) using an API. You can invoke workflows programmatically. See: 

http://scottsdigitalcommunity.blogspot.ca/2013/09/creating-workflows-for-adobe-experience.html

You may need to write a custom workflow step as well to perform time operations (if you want to wait 30 mins for example)\. However AEM is very flexable in letting you write custom workflow steps. TO learn how to write a custom workflow step that implements , WorkflowProcess see: 

https://helpx.adobe.com/experience-manager/using/creating-custom-aem-workflow-steps.html

rk39193348
Level 4
November 29, 2015

Thanks,

Can't this be achieved through schedulers? , can you please elaborate on the procedure ..

Adobe Employee
November 29, 2015

The Scheduler is a service that uses a cron expression to schedule other services/jobs. Here is an example [2].

You could run code that runs on a schedule to check for the replicated property, but depending on how many pages you have and how often the job is run, this could place a load on the system. 

Regards,

Opkar

[0]https://sling.apache.org/documentation/bundles/scheduler-service-commons-scheduler.html 

[1] https://helpx.adobe.com/experience-manager/using/aem-first-components1.html

Jitendra_S_Toma
Level 10
November 30, 2015

R.K,

What would be the frequency to look for page property?. And If property found, you want to schedule a page activation event after 30 mins?. 

--

jitendra

kautuk_sahni
Adobe Employee
Adobe Employee
November 30, 2015

Hi 

Apart form above mentioned, please find few reference link to help you achieve the needful.

Link:- https://helpx.adobe.com/experience-manager/kb/CQ5ReplicateToSpecificAgents.html

//How to activate to a specific replication agent.

Link:- http://www.sotheanim.com/21-how-to-programmatically-activate-cq-page

//How to programmatically activate CQ Page

Link:- http://stackoverflow.com/questions/18955982/how-to-activate-programmatically-a-page-in-cq5-workflow

//

Use Replicator OSGi service:

@Component
public class MyComponent {

    @Reference
    private Replicator replicator;

    private void activatePage(Session session) {
    //...
        replicator.replicate(session, ReplicationActionType.ACTIVATE, pathToPage);
    //...
    }
}

The above stated option is based on Scott's reply another way to do is as mentioned by Opkar Gill,

I hope this would help you.

 

Thanks and Regards

Kautuk Sahni

Kautuk Sahni
rk39193348
Level 4
November 30, 2015

Thanks all for your valuable responses.

Basically if replicatedBy property is set , page should get activated after a specific time.

rk39193348
Level 4
November 30, 2015

I have one more query , for "import com.day.cq.replication.Replicator;" which dependency should be added to pom.xml ?? As i am getting package not found error. I have included many dependencies it is not at all taking..

smacdonald2008
Level 10
November 30, 2015

Use AEM dependency finder to locate POM dependencies you need to reference. 

http://blog.behrang.org/blog/2014/03/11/aem-dependency-finder/

edubey
Level 10
November 30, 2015

Add this, it will work

<dependency>
                <groupId>com.day.cq</groupId>
                <artifactId>cq-replication</artifactId>
                <version>5.4.2</version>
                <scope>provided</scope>
 </dependency>

kautuk_sahni
Adobe Employee
Adobe Employee
December 1, 2015

Hi 

Please refer to this link:- https://maven-repository.com/artifact/com.day.cq/cq-replication

Click to the specific version that you would want, you would get the dependency code there.

Link:- https://maven-repository.com/artifact/com.day.cq/cq-replication/5.4.2

<dependency><groupId>com.day.cq</groupId><artifactId>cq-replication</artifactId><version>5.4.2</version></dependency>

I hope this would help you.

Thanks and Regards

Kautuk Sahni

Kautuk Sahni