Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
218 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...