Search in sources :

Example 6 with EventService

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));
}
Also used : Status(org.kie.api.task.model.Status) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) BAMTaskEventListener(org.jbpm.services.task.lifecycle.listeners.BAMTaskEventListener) TaskService(org.kie.api.task.TaskService) ArrayList(java.util.ArrayList) EventService(org.kie.internal.task.api.EventService) EntityManager(javax.persistence.EntityManager) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) BAMTaskSummaryImpl(org.jbpm.services.task.audit.impl.model.BAMTaskSummaryImpl) Test(org.junit.Test)

Example 7 with EventService

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);
}
Also used : WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) EventService(org.kie.internal.task.api.EventService) TaskLifeCycleEventListener(org.kie.api.task.TaskLifeCycleEventListener) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 8 with EventService

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);
}
Also used : WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) EventService(org.kie.internal.task.api.EventService) TaskLifeCycleEventListener(org.kie.api.task.TaskLifeCycleEventListener) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 9 with EventService

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);
}
Also used : WorkItemImpl(org.drools.core.process.instance.impl.WorkItemImpl) EventService(org.kie.internal.task.api.EventService) PermissionDeniedException(org.jbpm.services.task.exception.PermissionDeniedException) TaskLifeCycleEventListener(org.kie.api.task.TaskLifeCycleEventListener) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 10 with EventService

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;
}
Also used : AssignmentTaskEventListener(org.jbpm.services.task.assignment.impl.AssignmentTaskEventListener) TaskCommandExecutorImpl(org.jbpm.services.task.commands.TaskCommandExecutorImpl) EventService(org.kie.internal.task.api.EventService) MvelUserGroupCallbackImpl(org.jbpm.services.task.identity.MvelUserGroupCallbackImpl) TaskEventSupport(org.jbpm.services.task.events.TaskEventSupport) CommandBasedTaskService(org.jbpm.services.task.impl.command.CommandBasedTaskService) DefaultUserInfo(org.jbpm.services.task.identity.DefaultUserInfo) TaskLifeCycleEventListener(org.kie.api.task.TaskLifeCycleEventListener)

Aggregations

EventService (org.kie.internal.task.api.EventService)16 Test (org.junit.Test)12 HashMap (java.util.HashMap)8 DefaultTaskEventListener (org.jbpm.services.task.events.DefaultTaskEventListener)7 TaskEvent (org.kie.api.task.TaskEvent)7 StringReader (java.io.StringReader)6 TaskLifeCycleEventListener (org.kie.api.task.TaskLifeCycleEventListener)6 Task (org.kie.api.task.model.Task)6 InternalTask (org.kie.internal.task.api.model.InternalTask)6 KieSession (org.kie.api.runtime.KieSession)5 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)5 TaskService (org.kie.api.task.TaskService)5 TaskSummary (org.kie.api.task.model.TaskSummary)5 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)4 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)4 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)3 ArrayList (java.util.ArrayList)2 EntityManager (javax.persistence.EntityManager)2 AbstractRuntimeManager (org.jbpm.runtime.manager.impl.AbstractRuntimeManager)2 TaskExecutionException (org.jbpm.services.task.exception.TaskExecutionException)2