cancel
Showing results for 
Search instead for 
Did you mean: 

get nodeRef associated to Content

soeursourire
Champ in-the-making
Champ in-the-making
Hi!

Is there a fast way to get the NodeRef associated to a file contained into the repository: I have a xml file stored in the contents of admin, I know the id of this node file and I would like to get the NodeRef. With PersonServiceImpl we can do that: NodeRef getPerson(String name), is their a function NodeRef getContent(String id) somewhere in Alfresco?

Thanks
2 REPLIES 2

soeursourire
Champ in-the-making
Champ in-the-making
I guess the simplest way was to do this:

public NodeRef getRecordNodeRef(String recordId)
   {
      NodeRef rootNode = this.nodeService.getRootNode(storeRef);
       QueryParameterDefinition[] defs = new QueryParameterDefinition[1];
       DataTypeDefinition typeText = dictionaryService.getDataType(DataTypeDefinition.TEXT);
       defs[0] = new QueryParameterDefImpl(QName.createQName("sys", "var", namespacePrefixResolver), typeText, true,
               recordId);
       List<NodeRef> results = searchService.selectNodes(rootNode, ACTIVERECORDS_FOLDER
               + "/cm:Record.xml[@sys:node-uuid = $sys:var ]", defs, namespacePrefixResolver, false);
       if (results.size() != 1)
       {
           return null;
       }
       return results.get(0);
   }

anweber
Champ in-the-making
Champ in-the-making
Hi,

   Following the documentation, predicates are not supported in XPATH queries.

  Try this :


   public static NodeRef getNodeByUUID(ServiceRegistry serviceRegistry, StoreRef storeRef, String uuId) throws Exception{
       
       SearchService searchService = serviceRegistry.getSearchService();
        String searchString = "@sys\\:node-uuid:\"" + uuId + "\"";
         ResultSet rs = searchService.query(storeRef,SearchService.LANGUAGE_LUCENE, searchString );
        if (rs==null){
           return(null);
        }
        int nbRecords = rs.length();
        NodeRef nodeRef;
        if (nbRecords < 1) {
           nodeRef=null;
        }
        else nodeRef = rs.getNodeRef(0);
        rs.close();
        return(nodeRef);
    }


   I hope this may help you.

    Regards,

             Andre
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.