String taskInstanceId) throws EngineException, KernelException {
IPersistenceService persistenceService = rtCtx.getPersistenceService();
persistenceService.lockTaskInstance(taskInstanceId);
IWorkItem workItem = persistenceService.findWorkItemById(workItemId);
if (workItem == null)
return null;
if (workItem.getState().intValue() != IWorkItem.INITIALIZED) {
TaskInstance thisTaskInst = (TaskInstance) workItem
.getTaskInstance();
throw new EngineException(thisTaskInst.getProcessInstanceId(),
thisTaskInst.getWorkflowProcess(),
thisTaskInst.getTaskId(),
"Claim work item failed. The state of the work item is "
+ workItem.getState());
}
if (workItem.getTaskInstance().getState().intValue() != ITaskInstance.INITIALIZED
&& workItem.getTaskInstance().getState().intValue() != ITaskInstance.RUNNING) {
TaskInstance thisTaskInst = (TaskInstance) workItem
.getTaskInstance();
throw new EngineException(thisTaskInst.getProcessInstanceId(),
thisTaskInst.getWorkflowProcess(),
thisTaskInst.getTaskId(),
"Claim work item failed .The state of the correspond task instance is "
+ workItem.getTaskInstance().getState());
}
if (workItem.getTaskInstance().isSuspended()) {
TaskInstance thisTaskInst = (TaskInstance) workItem
.getTaskInstance();
throw new EngineException(thisTaskInst.getProcessInstanceId(),
thisTaskInst.getWorkflowProcess(),
thisTaskInst.getTaskId(),
"Claim work item failed .The correspond task instance is suspended");
}
// 0、首先修改workitem的状态
((WorkItem) workItem).setState(IWorkItem.RUNNING);
((WorkItem) workItem).setClaimedTime(rtCtx.getCalendarService()
.getSysDate());
persistenceService.saveOrUpdateWorkItem(workItem);
// 1、如果不是会签,则删除其他的workitem
if (FormTask.ANY.equals(workItem.getTaskInstance()
.getAssignmentStrategy())) {
persistenceService.deleteWorkItemsInInitializedState(workItem
.getTaskInstance().getId());
}
// 2、将TaskInstance的canBeWithdrawn字段改称false。即不允许被撤销
TaskInstance taskInstance = (TaskInstance) workItem.getTaskInstance();
taskInstance.setCanBeWithdrawn(false);
persistenceService.saveOrUpdateTaskInstance(taskInstance);
return workItem;