System.out.println("--------------Jump To NextActivity ----------------");
final List actorIds = new ArrayList();
actorIds.add("Zhang");
actorIds.add("Li");
actorIds.add("Chen");
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus arg0) {
try {
IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
IWorkItem workItem1 = workflowSession.findWorkItemById(workItem1Id);
DynamicAssignmentHandler dynamicAssignmentHandler = new DynamicAssignmentHandler();
dynamicAssignmentHandler.setActorIdsList(actorIds);
dynamicAssignmentHandler.setNeedClaim(true);
workItem1.complete(dynamicAssignmentHandler, "");
} catch (EngineException ex) {
Logger.getLogger(FireWorkflowEngineTest.class.getName()).log(Level.SEVERE, null, ex);
} catch (KernelException ex) {
Logger.getLogger(FireWorkflowEngineTest.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
IWorkItem wi = persistenceService.findWorkItemById(workItem1Id);
assertEquals(IWorkItem.COMPLETED, wi.getState().intValue());
taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "JumpTo.Activity2");
assertNotNull(taskInstanceList);
assertEquals(1,taskInstanceList.size());
taskInst = (ITaskInstance)taskInstanceList.get(0);
assertEquals(2,taskInst.getStepNumber().intValue());
tokensList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
assertNotNull(tokensList);
assertEquals(1, tokensList.size());
token = (IToken)tokensList.get(0);
assertEquals(2,token.getStepNumber().intValue());
//JumpTo.Activity2.Task1的所有WorkItem
List<IWorkItem> allTodoWorkItemList4Activity2 = persistenceService.findWorkItemsForTask("JumpTo.Activity2.Task1");
assertNotNull(allTodoWorkItemList4Activity2);
assertEquals(3,allTodoWorkItemList4Activity2.size());
List<IWorkItem> todoWorkItemsList = persistenceService.findTodoWorkItems("Zhang", "JumpTo", "JumpTo.Activity2.Task1");
assertNotNull(todoWorkItemsList);
assertEquals(1, todoWorkItemsList.size());
final String workItem2Id = ((IWorkItem) todoWorkItemsList.get(0)).getId();
//-----------------------------------------------------------------------
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus arg0) {
try {
IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
IWorkItem workItem2 = workflowSession.findWorkItemById(workItem2Id);
workItem2.claim();
workItem2.jumpTo("JumpTo.Activity3");
} catch (EngineException ex) {
Logger.getLogger(FireWorkflowEngineTest.class.getName()).log(Level.SEVERE, null, ex);
throw new RuntimeException(ex.getMessage());
} catch (KernelException ex) {
Logger.getLogger(FireWorkflowEngineTest.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
//----------------------------------------------------------------------------
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus arg0) {
try {
IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
IWorkItem workItem2 = workflowSession.findWorkItemById(workItem2Id);
workItem2.claim();
workItem2.jumpTo("JumpTo.Activity5");
} catch (EngineException ex) {
Logger.getLogger(FireWorkflowEngineTest.class.getName()).log(Level.SEVERE, null, ex);
throw new RuntimeException(ex.getMessage());
} catch (KernelException ex) {
Logger.getLogger(FireWorkflowEngineTest.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
wi = persistenceService.findWorkItemById(workItem2Id);
assertEquals(new Integer(IWorkItem.COMPLETED), wi.getState());
tokensList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
assertNotNull(tokensList);
assertEquals(1, tokensList.size());
token = (IToken)tokensList.get(0);
assertEquals(3,token.getStepNumber().intValue());
taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "JumpTo.Activity5");
assertNotNull(taskInstanceList);
assertEquals(1,taskInstanceList.size());
todoWorkItemsList = persistenceService.findTodoWorkItems(AssignmentHandlerMock.ACTOR_ID, "JumpTo", "JumpTo.Activity5.Task1");
assertNotNull(todoWorkItemsList);
assertEquals(1, todoWorkItemsList.size());
final String workItem5Id = ((IWorkItem) todoWorkItemsList.get(0)).getId();
//--------------------------------------------------------------------
System.out.println("--------------Complete WorkItem5 ----------------");
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus arg0) {
try {
IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
IWorkItem workItem5 = workflowSession.findWorkItemById(workItem5Id);
workItem5.claim();
workItem5.jumpTo("JumpTo.Activity2");
} catch (EngineException ex) {
Logger.getLogger(FireWorkflowEngineTest.class.getName()).log(Level.SEVERE, null, ex);
} catch (KernelException ex) {
Logger.getLogger(FireWorkflowEngineTest.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
wi = persistenceService.findWorkItemById(workItem5Id);
assertEquals(new Integer(IWorkItem.COMPLETED), wi.getState());
tokensList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
assertNotNull(tokensList);
assertEquals(1, tokensList.size());
token = (IToken)tokensList.get(0);
assertEquals(4,token.getStepNumber().intValue());
List<IWorkItem> workItemsList = persistenceService.findWorkItemsForTask("JumpTo.Activity2.Task1");
assertNotNull(workItemsList);
assertEquals(2,workItemsList.size());
List<IWorkItem> todoWorkItemList = persistenceService.findTodoWorkItems("Zhang");
assertNotNull(todoWorkItemList);
assertEquals(1,todoWorkItemList.size());
//IWorkItem todoWorkItem = (IWorkItem)todoWorkItemList.get(0);
//workItem2Id = todoWorkItem.getId();
//----------------------------------------------------------------------
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus arg0) {
try {
IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();
IWorkItem workItem2 = workflowSession.findWorkItemById(workItem2Id);
workItem2.jumpTo("JumpTo.Activity5");
} catch (EngineException ex) {
Logger.getLogger(FireWorkflowEngineTest.class.getName()).log(Level.SEVERE, null, ex);
throw new RuntimeException(ex.getMessage());
} catch (KernelException ex) {
Logger.getLogger(FireWorkflowEngineTest.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
wi = persistenceService.findWorkItemById(workItem2Id);
assertEquals(new Integer(IWorkItem.COMPLETED), wi.getState());
tokensList = persistenceService.findTokensForProcessInstance(currentProcessInstance.getId(), null);
assertNotNull(tokensList);
assertEquals(1, tokensList.size());
token = (IToken)tokensList.get(0);
assertEquals(6,token.getStepNumber().intValue());
taskInstanceList = persistenceService.findTaskInstancesForProcessInstance(currentProcessInstance.getId(), "JumpTo.Activity5");
assertNotNull(taskInstanceList);
assertEquals(1,taskInstanceList.size());
todoWorkItemsList = persistenceService.findTodoWorkItems(AssignmentHandlerMock.ACTOR_ID, "JumpTo", "JumpTo.Activity5.Task1");
assertNotNull(todoWorkItemsList);
assertEquals(0, todoWorkItemsList.size());
//---------------------------------------------
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus arg0) {
try {
IWorkflowSession workflowSession = runtimeContext.getWorkflowSession();