If you want to save an (udpated) object with a new version, you won't find a method for that in the IDfSysObject implementation.
You will have to do 2 operations: checkout, then a checkin specifying a new version.
Well, there are 2 approaches to do that: using the IDfCheckoutOperation and IDfCheckinOperation operations or methods of the IDfSysObject class: checkout() and checkin(boolean keepLock, String versionLabels).
The second approach is quite simple as requires just 2 lines of code, while the first one is more complex, so let's see the code sample.
Beware: if you don't set the 'CURRENT' version on your new version, it will be the last, but not the current one. So it will be 'hidden'.
Find below code samples for the operations.
public IDfId saveAsNewVersion(IDfSysObject object) throws DfException {
try {
checkOut(object);
// update object here if necessary
IDfClientX clientX = new DfClientX();
IDfCheckinOperation ciop = clientX.getCheckinOperation();
ciop.setCheckinVersion(IDfCheckinOperation.NEXT_MAJOR);
IDfCheckinNode ciNode = (IDfCheckinNode) ciop.add(object);
// if you don't specify the CURRENT version this document won't be the current version
ciNode.setVersionLabels("CURRENT");
if (! ciop.execute()) {
DfLogger.error(this,"saveAsNewVersion: Save signed document with new version failed!", null, null);
}
IDfId id = ciNode.getNewObjectId();
DfLogger.debug(this, "Signed document saved with new version, ID: " + id.getId(),null,null);
return id;
} catch (DfException e) {
DfLogger.error(this, "",null,e);
throw e;
}
}
public void checkOut(IDfSysObject object) throws DfException {
IDfClientX clientX = new DfClientX();
IDfCheckoutOperation coop = clientX.getCheckoutOperation();
IDfCheckoutNode coNode = (IDfCheckoutNode) coop.add(object);
if (coNode == null || ! coop.execute()) {
throw new DfException("Could not checkout document: " + object.getObjectId());
}
}
Hi,
ReplyDeleteThanks for the post.
Can you please tell me how to update the content of the object?
You commented as " // update object here if necessary"
I want to know how we update the object.
I tried setContent and setFile . For these two methods, I gave the new file which needs to be checked in as the new version.
But these dont work.I am not able to see the new file.A new version is created, but the content is not changed.
Please let me know how we update the content of the file.