AnsweredAssumed Answered

OnCreateNode policy and archiveStore

Question asked by billerby on Feb 18, 2010
Latest reply on Mar 17, 2010 by tfrith
I have ran in to an interesting problem. I have created a policy that gets fired upon onCreateNode of a custom content type (folder). This triggers the creation of some subfolders in my newly created space.

This is the relevant code for my implementation:

   public void onCreateNode(ChildAssociationRef childAssocRef) {
      if (log.isDebugEnabled()){
         log.debug("entering onCreateNode policy for produktion");
      }
      NodeRef nodeRef = null;
      
      // Create subfolders
      nodeRef = this.nodeService.createNode(childAssocRef.getChildRef(),
            ContentModel.ASSOC_CONTAINS,
            QName.createQName("RelateradeAktiviteter"),
            ContentModel.TYPE_FOLDER).getChildRef();

      nodeService.setProperty(nodeRef, ContentModel.PROP_NAME, "Aktiviteter");

      nodeRef = this.nodeService.createNode(childAssocRef.getChildRef(),
            ContentModel.ASSOC_CONTAINS,
            QName.createQName("RelateradeForestallningar"),
            ContentModel.TYPE_FOLDER).getChildRef();

      nodeService.setProperty(nodeRef, ContentModel.PROP_NAME, "Föreställningar - Konserter");
      
      nodeRef = this.nodeService.createNode(childAssocRef.getChildRef(),
            ContentModel.ASSOC_CONTAINS,
            QName.createQName("RelateradeUppgifter"),
            ContentModel.TYPE_FOLDER).getChildRef();

      nodeService.setProperty(nodeRef, ContentModel.PROP_NAME, "Uppgifter");
      
      nodeRef = this.nodeService.createNode(childAssocRef.getChildRef(),
            ContentModel.ASSOC_CONTAINS,
            QName.createQName("RelateradeDokument"),
            ContentModel.TYPE_FOLDER).getChildRef();

      nodeService.setProperty(nodeRef, ContentModel.PROP_NAME, "Dokument");

      nodeRef = this.nodeService.createNode(childAssocRef.getChildRef(),
            ContentModel.ASSOC_CONTAINS,
            QName.createQName("RelateradeResursgrupper"),
            ContentModel.TYPE_FOLDER).getChildRef();

      nodeService.setProperty(nodeRef, ContentModel.PROP_NAME, "Resursgrupper");
      
      nodeRef = this.nodeService.createNode(childAssocRef.getChildRef(),
            ContentModel.ASSOC_CONTAINS,
            QName.createQName("RelateradMarknadsforing"),
            ContentModel.TYPE_FOLDER).getChildRef();

      nodeService.setProperty(nodeRef, ContentModel.PROP_NAME, "Marknadsföring");
      
      if (log.isDebugEnabled()){
         log.debug("exiting onCreateNode-policy for produktion");
      }

   }

   public void init() {
      this.policyComponent.bindClassBehaviour(QName.createQName(
            NamespaceService.ALFRESCO_URI, "onCreateNode"),
            SmotModel.TYPE_PRODUKTION, new JavaBehaviour(this,
                  "onCreateNode"));
   }


Everything is ok until I try to delete this newly created space. Then I get an error message stating that it is not allowed to create two folders of the same name in one parent folder.

After some debugging I found out that the cause could be that the onCreateNode policy gets fired when my folder structure is copied to the archiveStore before deletion.

What are my options here? Do I have to turn of archiving to be able to delete my folder structure?

Outcomes