cancel
Showing results for 
Search instead for 
Did you mean: 

node from uuid

vinhqchu
Champ in-the-making
Champ in-the-making
how do i get the node from a uuid? also, how would I get the space path from this?

thank you,
vinh
5 REPLIES 5

robertito
Champ in-the-making
Champ in-the-making
Hi,

Assuming that you want to get a NodeRef, you can use something like the following:


   ResultSet nodeResultSet = null;
  
   SearchService searchService = serviceRegistry.getSearchService();
  
   try {
          StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");

          nodeResultSet = searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, "@sys\\:node-uuid:\"" + uuId + "\");

          if (nodeResultSet == null || nodeResultSet.length() == 0) {
               throw new NodeNotFoundException(…);
          }

          NodeRef nodeRef = nodeResultSet.getNodeRef(0);
   }
  finally {
          if (nodeResultSet != null) {
               nodeResultSet.close();
          }
   }
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Hope it helps!

Regrads,
Robert

calle
Champ in-the-making
Champ in-the-making
Wouldn the easiest way be to just create the NodeRef object?


final NodeRef ref = new NodeRef(uuid);
‍‍‍

You have to give the complete uuid prefixed with teh store to the constructor, like
workspace://SpacesStore/d17ed131-ba34-401c-9237-a2f75ed07e84

The you can use the NodeService to get properties for the node.

//Carl

robertito
Champ in-the-making
Champ in-the-making
Smiley Happy

you learn something new every day!

iblanco
Confirmed Champ
Confirmed Champ
Whooooh!!!! Is it documented somewhere in the Wiki ?

By the way, is there such an easy way to reference a node by its "file path"?

I saw in the wiki that there should be getRef(StoreRef storeRef,String path) in the NodeService but it doesn't exist.

vinhqchu
Champ in-the-making
Champ in-the-making
thank you thank you, everything seems to work good.