我想获取存储在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(实时,安全的竞争条件)
发布评论