How to activate programmatically a page in cq5 workflow
Asked Answered
C

2

6

I am trying to activate some pages from code. I have made a workflow that will modify a page whenever some content is modified in some other pages that have a reference to this page. I was trying to do this by setting properties of activation like:

parentpage.setProperty("cq:lastModified", Calendar.getInstance());
parentpage.setProperty("cq:lastModifiedBy", session.getUserID());

Although this property is getting set each time. But activation is not happening in the publish instance. How do we activate programmatic ally in custom workflow itself?

Cultivar answered 23/9, 2013 at 9:34 Comment(0)
Z
9

Use Replicator OSGi service:

@Component
public class MyComponent {

    @Reference
    private Replicator replicator;

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

You don't need to set any properties.

Zobias answered 23/9, 2013 at 11:21 Comment(4)
Previously i tried using this code as well,but i am keep getting null pointer exception.could you help with that.@Tomek RekawekCultivar
I'd love to help you, but you have to write some more details. Maybe modify the question and past the class code and the NPE stack trace.Laddy
Where do you get the replicator itself from? new ReplicatorImpl() and just run with that?Indispensable
Replicator is an OSGi service, so assuming that MyComponent is also an OSGi component, you can inject the Replicator using @Reference SCR annotation.Laddy
V
0

If you do not have the component then you can inject the service as -

Replicator replicator = getSling().getService(Replicator.class);
Ventura answered 17/12, 2014 at 17:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.