cancel
Showing results for 
Search instead for 
Did you mean: 

Avoid deletion behaviour on content when deleting a folder

iblanco
Confirmed Champ
Confirmed Champ
Hi everyone:

I have a behaviour that fires when a content with an specific aspect is deleted (using BeforeDeleteNodePolicy). When I put this kind of content on a folder and I delete the folder the behaviour also fires, as expected. I would like to be able to control this process and avoid the behaviour from firing or just be able to detect this scenario in the execution of the event.

I have tried this:

      ChildAssociationRef primaryAssoc = this.nodeService.getPrimaryParent(node);
      if (null == primaryAssoc) {
         /**
          * Is this an orphaned node ???
          */
         if (logger.isWarnEnabled()) {
            logger.warn("Can not notify node without a parent: " + node.toString());
         }
         return;
      }
      NodeRef parent = primaryAssoc.getParentRef();
      if (this.nodeService.getNodeStatus(parent).isDeleted()) {
         if (logger.isDebugEnabled()) {
            logger.debug("Node's parent is deleted, ommitting deletion notification for this node: " + node.toString());
         }
         return;
      }

But this doesn't do the trick, probably because the parent is not yet definitively deleted. Is there a way to "inspect" the transaction or something similar so that I can know if I'm a "direct" delete or an indirect one ?

I know I can disable the behaviour for the rest of the execution thread but that doesn't do the trick either because if I delete many different files at a time, for example from Share's document library, only the first one gets notified.

Thanks.
1 REPLY 1

iblanco
Confirmed Champ
Confirmed Champ
I didn't find a straight solution for the problem but as a workaraound I managed to solve the problem by using a behaviour filter that finds all the relevant children of the deleted node and disables the behaviour for those nodes during this execution thread:

                /**
       * Search and disable behaviour for all the children nodes.
       */
      String query = ".//*[hasAspect('"
            + Model.ASPECT_NOTIFY_IN_DISCUSSION.toString() + "')]";
      List<NodeRef> childrenNodes = this.searchService.selectNodes(node,
            query, null, this.namespaceService, false);
      for (NodeRef childNode : childrenNodes) {
         if (logger.isDebugEnabled()) {
            logger
                  .debug("Disabling behaviour for child node: "
                        + childNode);
         }
         this.behaviourFilter.disableBehaviour(childNode,
               Model.ASPECT_NOTIFY_IN_DISCUSSION);
      }

"behaviourFilter" is just the Alfresco defined "policyBehaviourFilter" bean injected into my bean.