如何使用DotCMIS/OpenCMIS修改CMIS文档的属性 [英] How to modify a property of a CMIS document using DotCMIS/OpenCMIS

查看:101
本文介绍了如何使用DotCMIS/OpenCMIS修改CMIS文档的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个文档doc,我想将其barcode元数据更新为"01234".

Let's say I have a document doc and I want to update its barcode metadata to "01234".

该文档可能具有其他现有属性,我不想丢失它们.
如果doc已经有一个barcode,它将被覆盖.

The document might have existing other properties, I don't want to lose them.
In case doc already has a barcode, it will be overwritten.

如何使用DotCMIS/OpenCMIS做到这一点?

How to do this with DotCMIS/OpenCMIS?

推荐答案

在CMIS中,默认情况下,更新属性将覆盖现有值,并且默认情况下将保留不与updateProperties消息一起发送的属性.也就是说,协议语义已经保证了您的两个需求.

In CMIS, updating properties will overwrite existing values by default, and properties you don't send along with the updateProperties message are by default retained. That is to say that both your requirements are already guaranteed by the protocol semantic.

在代码方面,请看Updating properties 代码示例对于OpenCMIS,适用于您的情况:

Code wise, have a look at the Updating properties code sample for OpenCMIS, here's it applied to your case:

CmisObject cmisobject = ....
Map<String, Object> updateProperties = new HashMap<String, Object>();
updateProperties.put("acme:barcode", "new value"); // single-value property
cmisobject.updateProperties(updateProperties);

对于DotCMIS,示例页面提供了另一个有用的代码段,下面是修改后的版本以映射您的用例:

In case of DotCMIS, the samples page offer another useful snippet, here's the modified version to map your use case:

ICmisObject cmisObject = ...

IDictionary<string, object> properties = new Dictionary<string, object>();
properties["acme:barcode"] = "new value";
IObjectId newId = cmisObject.UpdateProperties(properties);

if (newId.Id == cmisObject.Id) 
{
    // the repository updated this object - refresh the object
    cmisObject.Refresh();
}
else
{
    // the repository created a new version - fetch the new version
    cmisObject = session.GetObject(newId);
}

这篇关于如何使用DotCMIS/OpenCMIS修改CMIS文档的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆