The code below overrides
DfDocument.doCheckin in my TBO (Type Based Object). The method sets the document to its next major version when it is promoted to lifecycle state
Final.
protected void doPromote(String state, boolean override, boolean fTestOnly, Object[] extArgs ) throws DfException {
super.doPromote(state, override, fTestOnly, extArgs);
if (this.getCurrentStateName().equals("Final")){
if(this.isCheckedOut() == true){
throw new DfException("Cannot version if object is checked out.");
}
String newMajorVersion = this.getVersionPolicy().getNextMajorLabel();
this.mark(newMajorVersion);
this.save();
}
}
If the code above is not flexible enough... Below is the example from Documentum that uses
operations to set the document to the next major version by overriding
DfDocument.doCheckin.
public static void doCheckin( String strPath, IDfSession session ) throws DfException {
IDfClientX clientx = new DfClientX();
IDfCheckinOperation operation = clientx.getCheckinOperation();
IDfSysObject sysObj = (IDfSysObject) session.getObjectByPath( strPath );
if( sysObj == null ) {
System.out.println("Object " + strPath + " can not be found.");
return;
}
if (sysObj.isCheckedOut() == false) {
System.out.println("Object " + strPath + " is not checked out.");
return;
}
IDfCheckinNode node;
if( sysObj.isVirtualDocument() ) {
IDfVirtualDocument vDoc = sysObj.asVirtualDocument( "CURRENT", false );
node = (IDfCheckinNode)operation.add(vDoc);
} else {
node = (IDfCheckinNode)operation.add(sysObj);
}
//Other options for setCheckinVersion: VERSION_NOT_SET, NEXT_MAJOR,
// NEXT_MINOR, BRANCH_VERSION
operation.setCheckinVersion(IDfCheckinOperation.NEXT_MAJOR);
operation.execute();
}
No comments:
Post a Comment