I have nodes' shared between parent and child pages through mix:shareable mixin. The synchronization of data works fine in author instance but when the pages are activated the shared nodes get created with different UUID(this breaks the sync). I wrote this piece of code to re clone the nodes when UUID are different
//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();
}
The problem is when this code runs, the node is not deleted. So when the node is cloned it creates foo[2] node, but the log shows "session saved false" (currentPageNode.hasNode("foo") is returning false even when it actually did not delete the node). Strangely there are no exceptions due to the remove() call.How do I delete the node when UUID id different and resynchronize child page foo node with parent page foo node on publish Instance.