0

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.

Sharath Madappa
  • 3,393
  • 1
  • 24
  • 41
  • Are you getting any error messages..?? Can you add the log information here which makes it easy to debug – Praveen Jul 03 '14 at 12:43
  • I'm not getting any error messages.. I guess the problem was i wasn't calling save() method on the parent node of the node i was deleting, session.save() apparently isn't enough to persist the change.I dropped this approach and moved on to an alternative, so haven't verified the node.save() part in practice. – Sharath Madappa Jul 06 '14 at 06:49

0 Answers0