cancel
Showing results for 
Search instead for 
Did you mean: 

Move a content to a space - moveNode()

redbull
Champ in-the-making
Champ in-the-making
Hi all.
I need to move the content of one space to another space.
I tried this (from http://alfrescotips.wordpress.com/)

NodeRef target = new NodeRef(new StoreRef("workspace://SpacesStore"), target.getUUID());
this.nodeService.moveNode(source, target, ContentModel.ASSOC_CONTAINS, ContentModel.ASSOC_CHILDREN);
but target.getUUID() is not correct.
any suggestion?
thanks.
13 REPLIES 13

billerby
Champ on-the-rise
Champ on-the-rise
In what context are you running this code? In the dialog framework of the jsf environment? The target referenced here is the node you want to move. You need to either operate directly on this node within an Action for example. Otherwise you will have to find the node you need to move with the SearchService or if you know its id you can always construct the NodeRef with the store and the id of the node.

Please clarify and we will try to help you.

Regards
/Erik

redbull
Champ in-the-making
Champ in-the-making
thank Erik,
about the target node I know only the name (Company home/SelectedDocs) and so I need its NodeRef

billerby
Champ on-the-rise
Champ on-the-rise
Ok, so you are moving a folder? I still need to know in what context you are executing the code? If you dont know what I refer to please paste the class inside code markup in your next post.

/Erik

redbull
Champ in-the-making
Champ in-the-making
I'm not moving a folder but its content (some docs) from it ("folderA") to target folder ("folderB") by activating a custom action that apply to content level.
I start from the Jeff Potts "Alfresco Developer Guide" sample code (an action executer class that I'm changing properly):

   protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
      Boolean activeFlag = (Boolean)action.getParameterValue(PARAM_ACTIVE);
      if (activeFlag == null) activeFlag = true;      
      if (logger.isDebugEnabled()) logger.debug("Inside executeImpl");               
      // set the sc:isActive property to true
      // set the sc:published property to now
      Map<QName, Serializable> properties = nodeService.getProperties(actionedUponNodeRef);
      properties.put(SomeCoModel.PROP_IS_ACTIVE, activeFlag);       
      if (activeFlag) {
         properties.put(SomeCoModel.PROP_PUBLISHED, new Date());
      }      
      Node node = new Node(actionedUponNodeRef);      
      // if the aspect has already been added, set the properties
      if (node.hasAspect(SomeCoModel.ASPECT_SC_WEBABLE)) {
         if (logger.isDebugEnabled()) logger.debug("Node has aspect");
         nodeService.setProperties(actionedUponNodeRef, properties);
      } else {
         // otherwise, add the aspect and set the properties
         if (logger.isDebugEnabled()) logger.debug("Node does not have aspect");
         nodeService.addAspect(actionedUponNodeRef, SomeCoModel.ASPECT_SC_WEBABLE, properties);
      }                              
      if (logger.isDebugEnabled()) logger.debug("Ran web enable/disable action");                                
   }


Thank

billerby
Champ on-the-rise
Champ on-the-rise
Ok, so my guess is that your action will be run on the parent folder and the requirement is that when the action is run, you need to move all content in this folder to another folder?

Some rough code:

   // Get all children of the action node
   List<ChildAssociationRef> children = nodeService.getChildAssocs(actionedUponNodeRef);
   for (ChildAssociationRef childAssociationRef : children){
   NodeRef nodeToMove = childAssociationRef.getChildRef();
        // For every child call nodeService.move with you target folder nodeRef.
    }


/Erik

redbull
Champ in-the-making
Champ in-the-making
yes, but how I get the target folder nodeRef? I know its name is: "company home/selectedDocs".
thanks!

mrogers
Star Contributor
Star Contributor
No - that's its path not name.

You either do a search and get the node ref from the search results. 
Or "walk the tree" to get details such as node ref.    

There are also many utility methods available to get nodes based on path.    Take a look at the FileFolderService first.

redbull
Champ in-the-making
Champ in-the-making
I use this function to get the target NodeRef:

      protected NodeRef getFolderRef()
       {
       StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
       ResultSet resultSet = searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, "PATH:\"/app:company_home/cm:selectedDocs\"");
       return resultSet.getNodeRef(0);
       }
and catch a NullPointerException on searchService.query
What I did wrong?
Thanks

billerby
Champ on-the-rise
Champ on-the-rise
You did not inject the SearchService into your java bean?

/Erik