How to modify a property of a CMIS document using DotCMIS/OpenCMIS

早过忘川 提交于 2019-12-12 03:02:45

问题


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

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.

How to do this with DotCMIS/OpenCMIS?


回答1:


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.

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);

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);
}


来源:https://stackoverflow.com/questions/16142353/how-to-modify-a-property-of-a-cmis-document-using-dotcmis-opencmis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!