通过路径获取Alfresco NodeRef(实时,安全的竞争条件) [英] Get Alfresco NodeRef by path (real-time, race condition safe)
问题描述
我想获取存储在Alfresco中的文档(或空间)的NodeRef。
I want to get the NodeRef of a document (or space) stored in Alfresco.
我的代码是Java,在Alfresco中运行(例如在AMP中) )。
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.
怎么办?
推荐答案
您需要避免碰触任何东西SOLR,如那些API最终都是一致的
You need to avoid anything that touches SOLR, as those APIs are only Eventually Consistent
具体来说,您需要一个基于 canned的API查询。您的用例主要是 NodeService.getChildAssocs 和 NodeService.getChildByName 。某些 FileFolderService
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
您最好的选择是将路径拆分为多个组件,然后通过它进行递归/循环下降。根据要使用名称( cm:name
)还是QName(基于asoc),您将使用两个 NodeService之一
方法
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 two NodeService
methods
例如(未完全测试...)
eg (not fully tested...)
String[] parts = path.split("\\/");
NodeRef nodeRef = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
for (String name : parts) {
NodeRef child = nodeService.getChildByName(nodeRef, ContentModel.ASSOC_CONTAINS, name);
if (child == null)
throw new Exception("Path part not found "+name+" in "+path+" at "+nodeRef);
nodeRef = child;
}
return nodeRef;
这篇关于通过路径获取Alfresco NodeRef(实时,安全的竞争条件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!