我通过 mix:shareable mixin在父页面和子页面之间共享节点。数据同步在作者实例中工作正常,但是当页面被激活时,共享节点将使用不同的UUID创建(这会中断同步)。我写了这段代码,以便在UUID不同时重新克隆节点
//parentPageNode and currentPageNode are jcr nodes of parent and current page respectively
Node parentFooNode = parentPageNode.getNode("foo");
Node currentFooNode = currentPageNode.getNode("foo");
if(!(parentFooNode.getUUID().equals(currentFooNode.getUUID()))){
log.info("parent page foo node and child page foo node have different UUID");
//revolver factory obtained through @Reference Injection
// need admin creds to delete node in publish
ResourceResolver resourceResolver = resolverFactory.getAdministrativeResourceResolver(null);
Session session = resourceResolver.adaptTo(Session.class);
Workspace workspace = session.getWorkspace();
currentfooNode.remove();
log.info("node removed");
session.save();
log.info("session saved "+currentPageNode.hasNode("foo"));
workspace.clone(workspace.getName(), parentfooNode.getPath(),currentPageNode.getPath()+"/foo", false);
session.save();
}
问题是当此代码运行时,节点不会被删除。因此,当克隆节点时,它会创建foo [2]节点,但是日志显示“session saved false”(currentPageNode.hasNode(“foo”)返回false,即使它实际上没有删除节点)。奇怪的是,由于remove()调用没有异常。当UUID id不同时如何删除节点,并在发布实例上将子页面foo节点与父页面foo节点重新同步。