cancel
Showing results for 
Search instead for 
Did you mean: 

Turning a qname path into a NodeRef, not by searching

nickburch
Confirmed Champ
Confirmed Champ
I thought that one of the core services supported this, but I can't for the life of me find it… I have a qname based path, something like "/app:company_home/app:dictionary/app:email_templates", and I want to get the NodeRef of that. However, I don't want to use the SearchService to do that lookup, as I'm using SOLR and I need to ensure I can find things that have just been added. (As I understand it, if I follow the various examples out there which use the SearchService to do that style of lookup, they risk missing anything that has just been added as SOLR doesn't guarantee to have things immediately, just fairly soon)

The FileFolderService offers a resolveNamePath method, which turns a list of node Names into a NodeRef. That would let me turn {"Company Home","Data Dictionary", "Email Templates"} into the NodeRef, but not the qname form.

All it needs to do is split the path by /, and lookup each child assoc qname in turn, so it's not too complicated. I just don't want to re-invent the wheel every time… Is there already a service that will do this, which I've missed, or have I found a gap left by the de-lucene work?
2 REPLIES 2

afaust
Legendary Innovator
Legendary Innovator
Hello,

your qname path is essentially a XPath expression and you can use the SearchService to resolve XPath expressions without going to SOLR. The XPath query language in Alfresco is implemented directly on top of the DB / core services - no SOLR involved. So SearchService.selectNodes() is the way to go here.

Regards
Axel

I just tried the XPath NodeLocatorService solution, it leads to race conditions:

Nodes that have been created recently are sometimes not found (about 30% of calls fail, in my tests).

So I switched to using serviceRegistry.getNodeLocatorService().getNode("xpath", null, params); to get the NodeRef of the folders that I know always exist (such as /app:company_home/app:shared), and then use serviceRegistry.getFileFolderService().resolveNamePath for everything below these nodes.

I would use resolveNamePath all the time if I could, but unfortunately it would fail on a Alfresco installed in Japanese, for instance, because "Shared" becomes "共有フォルダ" in a Japanese Alfresco (yes, the path is different).

If anyone has any better idea I would be glad to hear about it 🙂

Cheers!

Nicolas Raoul