Search in sources :

Example 21 with TaskLifeCycleEventListener

use of org.kie.api.task.TaskLifeCycleEventListener in project jbpm by kiegroup.

the class TaskEventSupport method fireAfterTaskOutputVariablesChanged.

public void fireAfterTaskOutputVariablesChanged(final Task task, TaskContext context, Map<String, Object> variables) {
    final Iterator<TaskLifeCycleEventListener> iter = getEventListenersIterator();
    if (iter.hasNext()) {
        do {
            TaskLifeCycleEventListener listener = iter.next();
            listener.afterTaskOutputVariableChangedEvent(new TaskEventImpl(task, context), variables);
        } while (iter.hasNext());
    }
}
Also used : TaskLifeCycleEventListener(org.kie.api.task.TaskLifeCycleEventListener)

Example 22 with TaskLifeCycleEventListener

use of org.kie.api.task.TaskLifeCycleEventListener in project jbpm by kiegroup.

the class TaskEventSupport method fireBeforeTaskInputVariablesChanged.

public void fireBeforeTaskInputVariablesChanged(final Task task, TaskContext context, Map<String, Object> variables) {
    final Iterator<TaskLifeCycleEventListener> iter = getEventListenersIterator();
    if (iter.hasNext()) {
        do {
            TaskLifeCycleEventListener listener = iter.next();
            listener.beforeTaskInputVariableChangedEvent(new TaskEventImpl(task, context), variables);
        } while (iter.hasNext());
    }
}
Also used : TaskLifeCycleEventListener(org.kie.api.task.TaskLifeCycleEventListener)

Example 23 with TaskLifeCycleEventListener

use of org.kie.api.task.TaskLifeCycleEventListener in project jbpm by kiegroup.

the class AsyncWorkItemHandlerTest method testRunProcessWithAsyncHandlerRecordExecutionErrorTaskAutoAck.

@SuppressWarnings("unchecked")
@Test(timeout = 20000)
public void testRunProcessWithAsyncHandlerRecordExecutionErrorTaskAutoAck() throws Exception {
    CountDownAsyncJobListener countDownListener = new CountDownAsyncJobListener(1);
    ((ExecutorServiceImpl) executorService).addAsyncJobListener(countDownListener);
    ((ExecutorServiceImpl) executorService).setRetries(0);
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTaskWithRollback.bpmn2"), ResourceType.BPMN2).get();
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    ProcessInstance processInstance = ksession.startProcess("UserTaskWithRollback");
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    processInstance = runtime.getKieSession().getProcessInstance(processInstance.getId());
    assertNotNull(processInstance);
    manager.disposeRuntimeEngine(runtime);
    runtime = manager.getRuntimeEngine(EmptyContext.get());
    TaskService taskService = runtime.getTaskService();
    List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertEquals(1, tasks.size());
    long taskId = tasks.get(0).getId();
    TaskLifeCycleEventListener listener = new DefaultTaskEventListener() {

        @Override
        public void afterTaskStartedEvent(TaskEvent event) {
            throw new TaskExecutionException("On purpose");
        }
    };
    try {
        ((EventService<TaskLifeCycleEventListener>) taskService).registerTaskEventListener(listener);
        taskService.start(taskId, "john");
        fail("Start task should fail due to broken script");
    } catch (Throwable e) {
    // expected
    }
    manager.disposeRuntimeEngine(runtime);
    ExecutionErrorManager errorManager = ((AbstractRuntimeManager) manager).getExecutionErrorManager();
    assertNotNull("ErrorManager is null", errorManager);
    ExecutionErrorStorage errorStorage = errorManager.getStorage();
    assertNotNull("ErrorStorage is null", errorStorage);
    List<ExecutionError> errors = errorStorage.list(0, 10);
    assertEquals(1, errors.size());
    ExecutionError error = errors.get(0);
    assertNotNull(error);
    assertEquals("Task", error.getType());
    assertEquals("UserTaskWithRollback", error.getProcessId());
    assertEquals("Hello", error.getActivityName());
    assertEquals(manager.getIdentifier(), error.getDeploymentId());
    assertNotNull(error.getError());
    assertNotNull(error.getErrorMessage());
    assertNotNull(error.getActivityId());
    assertNotNull(error.getProcessInstanceId());
    assertNull(error.getAcknowledgedAt());
    assertNull(error.getAcknowledgedBy());
    assertFalse(error.isAcknowledged());
    countDownListener.reset(1);
    // first run should not ack the job as it's in error state
    CommandContext ctx = new CommandContext();
    ctx.setData("SingleRun", "true");
    ctx.setData("EmfName", "org.jbpm.persistence.complete");
    executorService.scheduleRequest(TaskAutoAckErrorCommand.class.getName(), ctx);
    countDownListener.waitTillCompleted();
    errors = errorStorage.list(0, 10);
    assertEquals(1, errors.size());
    error = errors.get(0);
    assertNotNull(error);
    assertFalse(error.isAcknowledged());
    runtime = manager.getRuntimeEngine(EmptyContext.get());
    tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertEquals(1, tasks.size());
    taskId = tasks.get(0).getId();
    ((EventService<TaskLifeCycleEventListener>) taskService).removeTaskEventListener(listener);
    taskService.start(taskId, "john");
    Map<String, Object> results = new HashMap<>();
    results.put("output1", "ok");
    taskService.complete(taskId, "john", results);
    manager.disposeRuntimeEngine(runtime);
    countDownListener.reset(1);
    // since task was completed auto ack should work
    executorService.scheduleRequest(TaskAutoAckErrorCommand.class.getName(), ctx);
    countDownListener.waitTillCompleted();
    errors = errorStorage.list(0, 10);
    assertEquals(1, errors.size());
    error = errors.get(0);
    assertNotNull(error);
    assertTrue(error.isAcknowledged());
}
Also used : ExecutionError(org.kie.internal.runtime.error.ExecutionError) CommandContext(org.kie.api.executor.CommandContext) HashMap(java.util.HashMap) AbstractRuntimeManager(org.jbpm.runtime.manager.impl.AbstractRuntimeManager) TaskAutoAckErrorCommand(org.jbpm.executor.commands.error.TaskAutoAckErrorCommand) DefaultTaskEventListener(org.jbpm.services.task.events.DefaultTaskEventListener) CountDownAsyncJobListener(org.jbpm.executor.test.CountDownAsyncJobListener) ExecutionErrorManager(org.kie.internal.runtime.error.ExecutionErrorManager) ExecutionErrorStorage(org.kie.internal.runtime.error.ExecutionErrorStorage) KieSession(org.kie.api.runtime.KieSession) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) ExecutorServiceImpl(org.jbpm.executor.impl.ExecutorServiceImpl) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) TaskService(org.kie.api.task.TaskService) EventService(org.kie.internal.task.api.EventService) TaskExecutionException(org.jbpm.services.task.exception.TaskExecutionException) TaskSummary(org.kie.api.task.model.TaskSummary) TaskEvent(org.kie.api.task.TaskEvent) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) TaskLifeCycleEventListener(org.kie.api.task.TaskLifeCycleEventListener) AbstractExecutorBaseTest(org.jbpm.test.util.AbstractExecutorBaseTest) Test(org.junit.Test)

Example 24 with TaskLifeCycleEventListener

use of org.kie.api.task.TaskLifeCycleEventListener in project jbpm by kiegroup.

the class DefaultRegisterableItemsFactory method getTaskListeners.

@Override
public List<TaskLifeCycleEventListener> getTaskListeners() {
    List<TaskLifeCycleEventListener> defaultListeners = new ArrayList<TaskLifeCycleEventListener>();
    defaultListeners.add(new JPATaskLifeCycleEventListener(true));
    // add any custom listeners
    defaultListeners.addAll(super.getTaskListeners());
    // add listeners from deployment descriptor
    defaultListeners.addAll(getTaskListenersFromDescriptor());
    return defaultListeners;
}
Also used : JPATaskLifeCycleEventListener(org.jbpm.services.task.audit.JPATaskLifeCycleEventListener) ArrayList(java.util.ArrayList) JPATaskLifeCycleEventListener(org.jbpm.services.task.audit.JPATaskLifeCycleEventListener) TaskLifeCycleEventListener(org.kie.api.task.TaskLifeCycleEventListener)

Example 25 with TaskLifeCycleEventListener

use of org.kie.api.task.TaskLifeCycleEventListener in project jbpm by kiegroup.

the class AbstractRuntimeManager method configureRuntimeOnTaskService.

@SuppressWarnings({ "unchecked", "rawtypes" })
protected void configureRuntimeOnTaskService(InternalTaskService internalTaskService, RuntimeEngine engine) {
    if (internalTaskService != null) {
        ExternalTaskEventListener listener = new ExternalTaskEventListener();
        if (internalTaskService instanceof EventService) {
            ((EventService) internalTaskService).registerTaskEventListener(listener);
        }
        // register task listeners if any
        RegisterableItemsFactory factory = environment.getRegisterableItemsFactory();
        for (TaskLifeCycleEventListener taskListener : factory.getTaskListeners()) {
            ((EventService<TaskLifeCycleEventListener>) internalTaskService).registerTaskEventListener(taskListener);
        }
        if (engine != null && engine instanceof Disposable) {
            ((Disposable) engine).addDisposeListener(new DisposeListener() {

                @Override
                public void onDispose(RuntimeEngine runtime) {
                    if (runtime.getTaskService() instanceof EventService) {
                        ((EventService) runtime.getTaskService()).clearTaskEventListeners();
                        ;
                    }
                }
            });
        }
    }
}
Also used : Disposable(org.kie.internal.runtime.manager.Disposable) DisposeListener(org.kie.internal.runtime.manager.DisposeListener) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) ExternalTaskEventListener(org.jbpm.services.task.wih.ExternalTaskEventListener) InternalRegisterableItemsFactory(org.kie.internal.runtime.manager.InternalRegisterableItemsFactory) RegisterableItemsFactory(org.kie.api.runtime.manager.RegisterableItemsFactory) EventService(org.kie.internal.task.api.EventService) TaskLifeCycleEventListener(org.kie.api.task.TaskLifeCycleEventListener)

Aggregations

TaskLifeCycleEventListener (org.kie.api.task.TaskLifeCycleEventListener)27 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 EventService (org.kie.internal.task.api.EventService)6 JPATaskLifeCycleEventListener (org.jbpm.services.task.audit.JPATaskLifeCycleEventListener)5 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)5 HashMap (java.util.HashMap)4 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)4 WorkItemImpl (org.drools.core.process.instance.impl.WorkItemImpl)3 KieSession (org.kie.api.runtime.KieSession)3 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)3 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)3 EntityManagerFactory (javax.persistence.EntityManagerFactory)2 DefaultTaskEventListener (org.jbpm.services.task.events.DefaultTaskEventListener)2 RegisterableItemsFactory (org.kie.api.runtime.manager.RegisterableItemsFactory)2 TaskEvent (org.kie.api.task.TaskEvent)2 TaskService (org.kie.api.task.TaskService)2 TaskSummary (org.kie.api.task.model.TaskSummary)2 DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)2 List (java.util.List)1