cancel
Showing results for 
Search instead for 
Did you mean: 

Policy method 'beforeDeleteNode' gives an invalid NodeRef

nicolasraoul
Star Contributor
Star Contributor
I want to perform something just before a node is deleted, so I implemented the "beforeNodeDelete" policy:

public void beforeDeleteNode(NodeRef node) {
   if ( nodeService.hasAspect(node, MYASPECT) )
      doSomething();
}

As expected, this method is called when I click on "delete" in the Web Client.
But when I use NodeService on the node (the "hasAspect" line above), I get an exception saying the node does not exist:

InvalidNodeRefException: Node does not exist: workspace://SpacesStore/6ea81fbd-f911-4884-a2a7-dea408a86c04

Why offer the NodeRef in the prototype of beforeDeleteNode(NodeRef node) if this NodeRef is invalid ?!
Can someone enlighten me?

Note: However, I can access this workspace://SpacesStore/6ea81fbd-f911-4884-a2a7-dea408a86c04 node using the node browser.
4 REPLIES 4

derek
Star Contributor
Star Contributor
Hi,
The NodeRef should be valid during beforeDeleteNode.  Can I see the code that sets up the policy callback, please?
Regards

nicolasraoul
Star Contributor
Star Contributor
Hello Derek!
Here is how I set up the policy callback:

public void initialize() {
   this.policyComponent.bindClassBehaviour(
         QName.createQName(NamespaceService.ALFRESCO_URI,"beforeDeleteNode"),
         QName.createQName("http://www.somecorp.co.jp/", "standardDocument"),
         new JavaBehaviour(this,"beforeDeleteNode",NotificationFrequency.TRANSACTION_COMMIT));
}

<bean id="deletePublishedContentPolicy" class="jp.co.somecorp.workflows.DeletePublishedContentPolicy" init-method="initialize">
   <property name="policyComponent" ref="policyComponent"/>
   <property name="nodeService" ref="nodeService"/>
   <property name="fileFolderService" ref="fileFolderService"/>
</bean>

Thanks for caring! 🙂

derek
Star Contributor
Star Contributor
Hi, Nicolas
If you use the default NotificationFrequency, then you will get the notification as soon as it happens rather than at the end of the transaction, by which time the node really is gone.  Naturally, should should not be trying to change the node you are about to delete but you could copy it and so on.  I hope this helps.
Regards

nicolasraoul
Star Contributor
Star Contributor
Thanks so much Derek!  Smiley Very Happy
Indeed, I changed TRANSACTION_COMMIT to EVERY_EVENT and it works!