Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Programatically replicate a page

Avatar

Level 4

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

1 Accepted Solution

Avatar

Correct answer by
Level 10

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

View solution in original post

0 Replies

Avatar

Correct answer by
Level 10

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

Avatar

Level 4

Thanks,

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

Avatar

Employee

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

Avatar

Level 9

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

Avatar

Administrator

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

Avatar

Level 4

Thanks all for your valuable responses.

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

Avatar

Level 4

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..

Avatar

Level 10

Add this, it will work

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

Avatar

Administrator

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

Avatar

Level 1

Hi can you tell how I can replicate an asset from one path to different path with using

getReplicator().replicate(workflowSession.getSession(), ReplicationActionType.ACTIVATE,

payload, opts);