I want to get the NodeRef of a document (or space) stored in Alfresco.
My code is in Java, running within Alfresco (for instance in an AMP).
My code needs to be safe against race conditions, for instance it must find nodes that have been created a second before. In this context, the usual methods (search-based) can not be used.
How to do?
You need to avoid anything that touches SOLR, as those APIs are only Eventually Consistent
Specifically, you need an API that's based on canned queries. The main ones for your use-case are NodeService.getChildAssocs and NodeService.getChildByName. Some of FileFolderService will work immediately too
Your best bet would be to split a path into components, then do a recursive / looping descent through it. Depending on if you want it by Name (
cm:name
) or QName (based on the assoc), you'd use one of the twoNodeService
methodseg (not fully tested...)
Transactional queries are supported, at least to some extent. http://docs.alfresco.com/5.2/concepts/intrans-metadata-overview.html
This method gets the company home NodeRef, which is always available (at least from an Alfresco-based application's point of view), then uses FileFolderService.resolveNamePath which is not search-based.
Syntax example of expected path:
/Company Home/Shared/My Folder/123.txt
Public domain, feel free to edit and improve :-)