我是Groovy的新手。使用Groovy我正在尝试确定页面的激活状态,并激活/停用页面。这是我的代码的核心元素,它抛出异常。
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);
这是它抛出的例外:
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)
我尝试了一些东西,但它们似乎没有起作用。复制返回void但似乎没有改变任何东西。声明Replicator是否似乎不起作用。它几乎无法找到导入。
帮助将不胜感激。
答案 0 :(得分:1)
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());
答案 1 :(得分:0)
您提供的代码中存在以下几个问题:
def replicator = sling.getService(Replicator.class)
public abstract void replicate(Session paramSession, ReplicationActionType paramReplicationActionType, String paramString)
最终代码示例:
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);
答案 2 :(得分:0)
Groovy Console提供了一些扩展方法。 其中之一是:
activate(字符串路径) - 激活给定路径上的节点。
activate(字符串路径,ReplicationOptions选项) - 使用提供的选项激活给定路径上的节点。
取消激活(字符串路径) - 停用指定路径的节点。
deactivate(字符串路径,ReplicationOptions选项) - 使用提供的选项停用给定路径上的节点。
所以你的脚本应该如下所示:
activate('/content/geometrixx/en/')
Groovy控制台页面上的方法选项卡(/etc/groovyconsole.html)中提供了完整的方法列表。