AnsweredAssumed Answered

Deleting nodes in BeforeDeleteNode Behaviour

Question asked by krzysztof.nowacki on Dec 4, 2013
Latest reply on Dec 4, 2013 by krzysztof.nowacki
I created following code:

public class DocumentBehavior implements NodeServicePolicies.BeforeDeleteNodePolicy {

private Behaviour beforeDeleteNode;

public void beforeDeleteNode(NodeRef nodeRef) {
   //In this function I'm searching others nodes and then I'm trying delete them.
   String type = (String)nodeService.getProperty(nodeRef, QName.createQName("kn", "docType"););
   StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
   SearchParameters sp = new SearchParameters();
   sp.setQuery("SELECT d.* FROM kn:document AS d WHERE d.cmis:objectId <> '" + nodeRef.toString() + "' AND '" + type + "'");
   ResultSet resultSet = searchService.query(sp);
   List<NodeRef> nodes = resultSet.getNodeRefs();
   for (NodeRef node : nodes) {
      if (nodeService.exists(node)) {

public void init() {
   this.beforeDeleteNode = new JavaBehaviour(this, "beforeDeleteNode", NotificationFrequency.EVERY_EVENT);
      NamespaceService.ALFRESCO_URI, "beforeDeleteNode"), QName.createQName("kn", "document"),


When I'm trying delete node in Alfresco Share I have a error: "Could not delete node". There is no exceptions in Alfresco Log.

When I'm trying detele node in Alfresco Explorer, the code executes 40 times (why?) and finally there is an exception (please find attached)

When I'm change NotificationFrequency to TRANSACTION_COMMIT or FIRST_EVENT the main node is deleted, but the nodes that I am searching are not deleted.

Is this a bug in Alfresco or do I implemented it the wrong way?