use of org.kie.internal.task.api.EventService in project jbpm by kiegroup.
the class ProcessPersistenceHumanTaskOnLaneTest method testProcessWithBAMListener.
@SuppressWarnings("unchecked")
@Test
public void testProcessWithBAMListener() throws Exception {
createRuntimeManager("org/jbpm/test/functional/task/HumanTaskOnLane.bpmn2");
RuntimeEngine runtimeEngine = getRuntimeEngine();
KieSession ksession = runtimeEngine.getKieSession();
TaskService taskService = runtimeEngine.getTaskService();
((EventService<TaskLifeCycleEventListener>) taskService).registerTaskEventListener(new BAMTaskEventListener(true));
ProcessInstance processInstance = ksession.startProcess("UserTask");
assertProcessInstanceActive(processInstance.getId());
long task1 = -1;
long task2 = -1;
// simulating a system restart
logger.debug("Reloading the environemnt to simulate system restart");
disposeRuntimeManager();
createRuntimeManager("org/jbpm/test/functional/task/HumanTaskOnLane.bpmn2");
runtimeEngine = getRuntimeEngine();
ksession = runtimeEngine.getKieSession();
taskService = runtimeEngine.getTaskService();
((EventService<TaskLifeCycleEventListener>) taskService).registerTaskEventListener(new BAMTaskEventListener(true));
// let john execute Task 1
String taskUser = "john";
String locale = "en-UK";
List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner(taskUser, locale);
assertEquals(1, list.size());
TaskSummary task = list.get(0);
task1 = task.getId();
taskService.claim(task.getId(), taskUser);
taskService.start(task.getId(), taskUser);
taskService.complete(task.getId(), taskUser, null);
List<Status> reservedOnly = new ArrayList<Status>();
reservedOnly.add(Status.Reserved);
list = taskService.getTasksAssignedAsPotentialOwnerByStatus(taskUser, reservedOnly, locale);
assertEquals(1, list.size());
task = list.get(0);
task2 = task.getId();
taskService.start(task.getId(), taskUser);
taskService.complete(task.getId(), taskUser, null);
assertProcessInstanceCompleted(processInstance.getId());
EntityManager em = getEmf().createEntityManager();
List<BAMTaskSummaryImpl> bamLogs = em.createQuery("from BAMTaskSummaryImpl").getResultList();
em.close();
assertNotNull(bamLogs);
assertEquals(2, bamLogs.size());
List<Long> taskIdsFromBAM = new ArrayList<Long>();
for (BAMTaskSummaryImpl bamEntry : bamLogs) {
taskIdsFromBAM.add(bamEntry.getTaskId());
}
assertTrue(taskIdsFromBAM.contains(task1));
assertTrue(taskIdsFromBAM.contains(task2));
}
use of org.kie.internal.task.api.EventService in project jbpm by kiegroup.
the class HTWorkItemHandlerBaseTest method testTaskCreateFailedWithLog.
@SuppressWarnings("unchecked")
@Test
public void testTaskCreateFailedWithLog() throws Exception {
TestWorkItemManager manager = new TestWorkItemManager();
((AbstractHTWorkItemHandler) handler).setAction(OnErrorAction.LOG);
TaskLifeCycleEventListener listener = new AddedTaskListener(true);
((EventService<TaskLifeCycleEventListener>) taskService).registerTaskEventListener(listener);
ksession.setWorkItemManager(manager);
WorkItemImpl workItem = new WorkItemImpl();
workItem.setName("Human Task");
workItem.setParameter("NodeName", "TaskName");
workItem.setParameter("Comment", "Comment");
workItem.setParameter("Priority", "10");
workItem.setParameter("ActorId", "DoesNotExist");
workItem.setProcessInstanceId(10);
handler.executeWorkItem(workItem, manager);
assertFalse(manager.isAborted());
((EventService<TaskLifeCycleEventListener>) taskService).removeTaskEventListener(listener);
}
use of org.kie.internal.task.api.EventService in project jbpm by kiegroup.
the class HTWorkItemHandlerBaseTest method testTaskCreateFailedWithAbort.
@SuppressWarnings("unchecked")
@Test
public void testTaskCreateFailedWithAbort() throws Exception {
TestWorkItemManager manager = new TestWorkItemManager();
TaskLifeCycleEventListener listener = new AddedTaskListener(true);
((EventService<TaskLifeCycleEventListener>) taskService).registerTaskEventListener(listener);
((AbstractHTWorkItemHandler) handler).setAction(OnErrorAction.ABORT);
ksession.setWorkItemManager(manager);
WorkItemImpl workItem = new WorkItemImpl();
workItem.setName("Human Task");
workItem.setParameter("NodeName", "TaskName");
workItem.setParameter("Comment", "Comment");
workItem.setParameter("Priority", "10");
workItem.setParameter("ActorId", "DoesNotExist");
workItem.setProcessInstanceId(10);
handler.executeWorkItem(workItem, manager);
assertTrue(manager.isAborted());
((EventService<TaskLifeCycleEventListener>) taskService).removeTaskEventListener(listener);
}
use of org.kie.internal.task.api.EventService in project jbpm by kiegroup.
the class HTWorkItemHandlerBaseTest method testTaskCreateFailedWithRethrow.
@SuppressWarnings("unchecked")
@Test
public void testTaskCreateFailedWithRethrow() throws Exception {
TestWorkItemManager manager = new TestWorkItemManager();
TaskLifeCycleEventListener listener = new AddedTaskListener(true);
((EventService<TaskLifeCycleEventListener>) taskService).registerTaskEventListener(listener);
((AbstractHTWorkItemHandler) handler).setAction(OnErrorAction.RETHROW);
ksession.setWorkItemManager(manager);
WorkItemImpl workItem = new WorkItemImpl();
workItem.setName("Human Task");
workItem.setParameter("NodeName", "TaskName");
workItem.setParameter("Comment", "Comment");
workItem.setParameter("Priority", "10");
workItem.setParameter("ActorId", "DoesNotExist");
workItem.setProcessInstanceId(10);
try {
handler.executeWorkItem(workItem, manager);
fail("Should fail due to OnErroAction set to rethrow");
} catch (Exception e) {
// do nothing
}
((EventService<TaskLifeCycleEventListener>) taskService).removeTaskEventListener(listener);
}
use of org.kie.internal.task.api.EventService in project jbpm by kiegroup.
the class HumanTaskConfigurator method getTaskService.
@SuppressWarnings("unchecked")
public TaskService getTaskService() {
if (service == null) {
TaskEventSupport taskEventSupport = new TaskEventSupport();
this.commandExecutor = new TaskCommandExecutorImpl(this.environment, taskEventSupport);
if (userGroupCallback == null) {
userGroupCallback = new MvelUserGroupCallbackImpl(true);
}
environment.set(EnvironmentName.TASK_USER_GROUP_CALLBACK, userGroupCallback);
if (userInfo == null) {
userInfo = new DefaultUserInfo(true);
}
environment.set(EnvironmentName.TASK_USER_INFO, userInfo);
addDefaultInterceptor();
addTransactionLockInterceptor();
addOptimisticLockInterceptor();
addErrorHandlingInterceptor();
for (PriorityInterceptor pInterceptor : interceptors) {
this.commandExecutor.addInterceptor(pInterceptor.getInterceptor());
}
service = new CommandBasedTaskService(this.commandExecutor, taskEventSupport, this.environment);
// register listeners
for (TaskLifeCycleEventListener listener : listeners) {
((EventService<TaskLifeCycleEventListener>) service).registerTaskEventListener(listener);
}
if (AssignmentServiceProvider.get().isEnabled()) {
((EventService<TaskLifeCycleEventListener>) service).registerTaskEventListener(new AssignmentTaskEventListener());
}
// initialize deadline service with command executor for processing
if (TaskDeadlinesServiceImpl.getInstance() == null) {
TaskDeadlinesServiceImpl.initialize(commandExecutor);
}
}
return service;
}
Aggregations