Reputation: 43
I’m very new to Groovy. Using Groovy I am trying to determine a page’s activation status and also activate/deactivate a page. This is the core elements of my code and it’s throwing an exception.
import com.day.cq.replication.Replicator;
import javax.jcr.Session;
Session session = slingRequest.getResourceResolver().adaptTo(Session.class);
path='/content/geometrixx/en/';
def getStats = getReplicationStatus(session, path);
def rp = replicate(session, "ACTIVATE", path);
Here's the exception it throws:
groovy.lang.MissingMethodException: No signature of method: Script1.getReplicationStatus() is applicable for argument types: ($Proxy10, java.lang.String) values: [session-admin-977089, /content/geometrixx/en/]
at Script1.run(Script1.groovy:9)
I tried a few things but they don't seem to be working. replicate returns void but that didn't seem to change anything. Declaring if of Replicator doesn't seem to work. It's almost like it can't find the import.
Help would be appreciated.
Upvotes: 1
Views: 4147
Reputation: 186
Groovy Console provides some extension methods. One of them are:
activate(String path) - Activate the node at the given path.
activate(String path, ReplicationOptions options) - Activate the node at the given path with supplied options.
deactivate(String path) - Deactivate the node at the given path.
deactivate(String path, ReplicationOptions options) - Deactivate the node at the given path with supplied options.
So your script should look like the following one:
activate('/content/geometrixx/en/')
Full list of the methods is available in Methods tab on Groovy Console page (/etc/groovyconsole.html).
Upvotes: 1
Reputation: 43
import com.day.cq.replication.Replicator;
import com.day.cq.replication.ReplicationActionType;
import com.day.cq.replication.ReplicationStatus;
import javax.jcr.Session;
import java.util.GregorianCalendar;
def replicator = sling.getService(Replicator.class);
def replicationstatus = sling.getService(ReplicationStatus.class);
def path = '/content/geometrixx/en/';
// Find current Replication Status
rs = replicator.getReplicationStatus(session, path);
GregorianCalendar date = rs.getLastPublished();
println("Published on: " + date.getTime());
println("Last Published By: " + rs.getLastPublishedBy());
println("Path is activated: " + rs.isActivated());
println("Path is delivered: " +rs.isDelivered());
// Activate the Page
def rp = replicator.replicate(session, ReplicationActionType.ACTIVATE, path);
// Verify new Replication Status
rs = replicator.getReplicationStatus(session, path);
date = rs.getLastPublished();
println("Published on: " + date.getTime());
println("Last Published By: " + rs.getLastPublishedBy());
println("Path is activated: " + rs.isActivated());
println("Path is deactivated: " + rs.isDeactivated());
Upvotes: 1
Reputation: 354
There are couple of issues in the code you provided:
def replicator = sling.getService(Replicator.class)
public abstract void replicate(Session paramSession, ReplicationActionType paramReplicationActionType, String paramString)
Final code sample:
import com.day.cq.replication.Replicator;
import com.day.cq.replication.ReplicationActionType
import javax.jcr.Session;
def replicator = sling.getService(Replicator.class)
def path = '/content/geometrixx/en/';
def rp = replicator.replicate(session, ReplicationActionType.ACTIVATE, path);
Upvotes: 0