Title: What not to Expect from cancelEdit() Call
Fact: Interstage BPM(Business Process Manager) Model API
Symptom:
Exception thrown as shown below when cancelEdit() is invoked while there is either no startEdit() call or startEdit() is invoked by a different user session:
"Could not cancel the editing of the process instance for enactment. {The process
instance is not locked for enactment, so updates will not be saved.}
at com.fujitsu.iflow.model.wfcore.ProcessInstanceImpl.cancelEdit(Process
InstanceImpl.java:2123)
at com.fujitsu.iflow.model.wfcore.WorkItemImpl.cancelEdit(WorkItemImpl.j
ava:341)"
Fix:
This knowledge base article is to clarify what not to expect from the cancelEdit() APIs that remove edit lock on the pertinent workflow object (we are not concerned about commit edit in this article). In short, do not expect to use cancel edit to cancel the edit that is started by another user session.
The typical API isLockedForEdit() can be used to check whether there is already an edit on the workflow object. If there is already an edit started by another user session, then there is nothing much you can do further. Don't expect the cancel edit API to remove the edit.
There are three model APIs that are used to remove edit on the respective workflow object:
cancelEdit() - Method in interface com.fujitsu.iflow.model.workflow.DataAccessor
Unlocks this DataAccessor from edit-mode without committing any done changes.
cancelEdit() - Method in interface com.fujitsu.iflow.model.workflow.Plan
Cancels the current editing session discarding all modifications made since the last call to startEdit.
cancelStructuralEdit() - Method in interface com.fujitsu.iflow.model.workflow.ProcessInstance
Unlocks this process instance from edit-mode without committing any done changes.
For the cancel edit to work, there are two conditions that need to be met:
1. there is already an edit started
2. and the edit is started by the same user session who is going to call cancel edit
The same user session who starts the edit on the workflow object can call cancel edit to remove the lock. The exception will be thrown as shown in the symptom when cancel edit is called by a different user session. The error message indicates that there is no edit started by the current user session, so cancel edit fails. In brief, BPM server only allows a user session to cancel an edit, if and only if there is an edit and the edit is started by the same user session. Once an edit is started, what follows is either commit edit or cancel edit. Don't leave the edit dangling which results in a lock on the relevant workflow object.