且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 CMIS 在 Alfresco 中进行批量更新

更新时间:2023-11-25 20:29:22

困难的方法(和健谈的方法)是查询您的文档,然后设置每个文档的属性.但 CMIS 规范实际上提供了更好的方法:批量更新.

The hard way (and chatty way) is to query for your documents and then set the properties on each one. But the CMIS spec actually provides a better way: Bulk updates.

代码如下:

ArrayList<CmisObject> docList = new ArrayList<CmisObject>();
Document doc1 = (Document) getSession().getObjectByPath("/bulk/bulktest1.txt");
docList.add(doc1);
Document doc2 = (Document) getSession().getObjectByPath("/bulk/bulktest2.txt");
docList.add(doc2);
Document doc3 = (Document) getSession().getObjectByPath("/bulk/bulktest3.txt");
docList.add(doc3);

HashMap<String, Object> props = new HashMap<String, Object>();
props.put("cmis:description", "description set in bulk");
List<BulkUpdateObjectIdAndChangeToken> updatedIds = getSession().bulkUpdateProperties(docList, props, null, null);

System.out.println("Updated " + updatedIds.size() + " docs.");

在我的示例中,我按路径抓取每个文档,但当然您也可以运行查询并以这种方式构建您的列表.

In my example I am grabbing each document by path, but of course you could run a query and build your list that way as well.

要在 Alfresco 中使用它,您必须使用 CMIS 1.1 和浏览器绑定,因此请确保您的服务 URL 为 http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser.

To use this with Alfresco you must use CMIS 1.1 and the browser binding so make sure your service URL is http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser.