cancel
Showing results for 
Search instead for 
Did you mean: 

Search for a Node

luisg
Champ in-the-making
Champ in-the-making
Hi there
I'm trying to do a Web Service that can get the path for a Node. I did this:

protected static ResultSet getResultSpace(String idNode){
      ResultSet result = null;
      
      String searchQuery = "@\\{http\\://www.alfresco.org/model/content/1.0\\}name:\"" + idNode+ "\"";
      Query query = new Query();
                query.setLanguage(Constants.QUERY_LANG_LUCENE);
                query.setStatement(searchQuery);
       
        try {
            QueryResult resultQuery = WebServiceFactory.getRepositoryService().query(STORE, query, false);
            result = resultQuery.getResultSet();
           
            //imprime os resultados
            ResultSetRow[] rows = result.getRows();
            System.out.println("–>"+rows.length);
        }
        catch(Exception e){}
       
        return result;
}

All the folders in Alfresco have different names.
The thing is, if I search for a Node with name 'id123', I will get some nodes I dont want. eg: 'id', '123', 'id123456'.
The method I create return all the results that have, as sub-string, the given string, but I just want the space with full name equals to the given string, so I will ALWAYS get 1 result.

One more thing…
With this method I get a path like this:
/{http://www.alfresco.org/model/application/1.0}company_home/{http://www.alfresco.org/model/content/1....
from the resultSetRow.path.
How can I get this path as: /app:company_home/cm:folderX/… ?

Can somebody help me?

Thanks
Luis

Can you help me?
7 REPLIES 7

openpj
Elite Collaborator
Elite Collaborator
You can try to use XPATH notation as the following example:
String xpath = "/app:company_home/*[@cm:name="folderX"]/*[@cm:name="folderY"]"
Or you can try to use Lucene Query but you must encode all the names of the spaces with ISO9075 class in this way:

String path = "/app:company_home/cm:"+ISO9075.encode("folderX")+"/cm:"+ISO9075.encode("folderY")";
Hope this helps.

luisg
Champ in-the-making
Champ in-the-making
Hi man, and thanks for your reply.

The problem is, I dont know the path. I need to perform a search for the name of the folder first. Initially I only have the name of the folder, and I know that it is in:
Company Home -> Specific.
But inside this path I have a tree of spaces (and sub-spaces), and the folder I want to find is in one of the tree leaf.
Did I make myself clear?

Thanks

Luis

luisg
Champ in-the-making
Champ in-the-making
Hi…
I did the search with Lucene Query, and I get results, but not the ones I want.

if I search for a node with name 'id' ("@cm\\:name:\"id"") I will get nodes with names like 'id1', 'id123', etc.
This will be a problem in my application cause I will have a node with full name '1' and a node will full name '11' (and '111'…).

It's possible to get a reference to the node with only its full name? Or the only way is to search for it's UUID? The thing is, initially, I only have the folder name so, to find its uuid, I need to perform a search with its name.

Or there is another way to do that?

Thanks

Luis

luisg
Champ in-the-making
Champ in-the-making
Hi again

I found the solution.
I erased my code and start again, reading carefully the documentation.
We can search a node for it's name.

Thanks

salvatore_bagli
Champ in-the-making
Champ in-the-making
how?

dinair
Champ in-the-making
Champ in-the-making
Very nice and great,
Thanks for sharing it

luisg
Champ in-the-making
Champ in-the-making
sorry… I did it like this:


protected ResultSet NodeSearch(String nodeName){
      ResultSet result = null;
      try{
         RepositoryServiceSoapBindingStub repositoryService = WebServiceFactory.getRepositoryService();
                        //the following query search for a node of type folder. If you have another type, you mus change the query.
         Query query = new Query(Constants.QUERY_LANG_LUCENE, "TYPE:\"cm:folder\" AND @cm\\:name:\""+normilizeNodeName(nodeName)+"\"");
         QueryResult queryResult = repositoryService.query(STORE, query, false);
         result = queryResult.getResultSet();
         ResultSetRow[] rows = result.getRows();
         rows[0].getColumns();
      }
      catch(Exception e){
         System.out.println("O node with name '"+nodeName+"' dont exist.");
         e.printStackTrace();
         result = null;
      }
      
      return result;
   }

It work for me.
Hope it helps