AnsweredAssumed Answered

Problem while deleting node.

Question asked by rohit.chakraborty on Apr 21, 2016
Hi, I want to delete the documentLibrary folder, if there is no files in that folder.
  In the function onUpdateNode():If there is no files I am trying to delete the node.
  In the function beforeDeleteNode(): Before deleting the node, I am checking the files in it. If there is a file I am disabling
  the delete-behaviour.

The problem I am facing is, some time it works fine and some time won't. according to my knowledge the problem will be in the disableBehaviour(I am setting disablebehavior if files exist and I am not enabling that behavior again). Do I need to enable that behavior when there is no files in the folder.
Any suggestion,
following is my code snippet:

   public void beforeDeleteNode(NodeRef nodeInFolderNodeRef) {
      List<ChildAssociationRef> children = nodeService.getChildAssocs(nodeInFolderNodeRef);
      if (children.size() > 0) {
         logger.debug("Can not delete the folder " + nodeInFolderNodeRef + " since it has "
                        + children.size() + " file(s)");
      } else {
         logger.debug(nodeInFolderNodeRef + " will delete.");
   public void onUpdateNode(NodeRef incomingDateFolderRef) {
      List<ChildAssociationRef> children = nodeService.getChildAssocs(incomingDateFolderRef);
      if (children.size() == 0) {
         logger.debug("Folder contains : " + children.size() + " items" + incomingDateFolderRef );
         nodeService.addAspect(incomingDateFolderRef, ContentModel.ASPECT_TEMPORARY, null);
         boolean isExist = nodeService.exists(incomingDateFolderRef);
         System.out.println("Is Existing : " + isExist);
         if (!isExist) {

Thanks in advance.