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