cancel
Showing results for 
Search instead for 
Did you mean: 

OnCreateNode policy and archiveStore

billerby
Champ on-the-rise
Champ on-the-rise
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?
1 REPLY 1

tfrith
Champ on-the-rise
Champ on-the-rise
You are correct  that onCreateNode is called for the new archive store node.

You should be able to just check which store the node is being created in and then just don't create subfolders for those in the archive store.

I think you can do something like this:
if (StoreRef.PROTOCOL_WORKSPACE.equals(childAssocRef.getChildRef().getStoreRef().getProtocol())) {
    // Create subfolders, etc
}