Search in sources :

Example 1 with ProcessWorkItemTransitionEvent

use of io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent in project automatiko-engine by automatiko-io.

the class UserTaskTest method testBasicUserTaskProcess.

@Test
public void testBasicUserTaskProcess() throws Exception {
    Application app = generateCodeProcessesOnly("usertask/UserTasksProcess.bpmn2");
    assertThat(app).isNotNull();
    final List<String> workItemTransitionEvents = new ArrayList<>();
    app.config().process().processEventListeners().listeners().add(new DefaultProcessEventListener() {

        @Override
        public void beforeWorkItemTransition(ProcessWorkItemTransitionEvent event) {
            workItemTransitionEvents.add("BEFORE:: " + event);
        }

        @Override
        public void afterWorkItemTransition(ProcessWorkItemTransitionEvent event) {
            workItemTransitionEvents.add("AFTER:: " + event);
        }
    });
    Process<? extends Model> p = app.processes().processById("UserTasksProcess");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    List<WorkItem> workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    assertEquals("FirstTask", workItems.get(0).getName());
    processInstance.completeWorkItem(workItems.get(0).getId(), null, securityPolicy);
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    assertEquals("SecondTask", workItems.get(0).getName());
    processInstance.completeWorkItem(workItems.get(0).getId(), null, securityPolicy);
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    assertThat(workItemTransitionEvents).hasSize(8);
}
Also used : HashMap(java.util.HashMap) ProcessWorkItemTransitionEvent(io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent) ArrayList(java.util.ArrayList) WorkItem(io.automatiko.engine.api.workflow.WorkItem) Model(io.automatiko.engine.api.Model) DefaultProcessEventListener(io.automatiko.engine.api.event.process.DefaultProcessEventListener) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 2 with ProcessWorkItemTransitionEvent

use of io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent in project automatiko-engine by automatiko-io.

the class ProcessEventSupport method fireBeforeWorkItemTransition.

public void fireBeforeWorkItemTransition(final ProcessInstance instance, WorkItem workitem, Transition<?> transition, ProcessRuntime runtime) {
    final Iterator<ProcessEventListener> iter = getEventListenersIterator();
    final List<ProcessEventListener> delayedListeners = new ArrayList<ProcessEventListener>();
    final ProcessWorkItemTransitionEvent event = new ProcessWorkItemTransitionEventImpl(instance, workitem, transition, runtime, false);
    if (iter.hasNext()) {
        do {
            ProcessEventListener listener = iter.next();
            if (listener instanceof DelayedExecution) {
                delayedListeners.add(listener);
            } else {
                listener.beforeWorkItemTransition(event);
            }
        } while (iter.hasNext());
    }
    unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, (e) -> {
        delayedListeners.forEach(l -> l.beforeWorkItemTransition(e));
    }));
}
Also used : ProcessEventListener(io.automatiko.engine.api.event.process.ProcessEventListener) ProcessVariableChangedEvent(io.automatiko.engine.api.event.process.ProcessVariableChangedEvent) UnitOfWorkManager(io.automatiko.engine.api.uow.UnitOfWorkManager) DelayedExecution(io.automatiko.engine.api.event.process.DelayedExecution) ProcessNodeTriggeredEvent(io.automatiko.engine.api.event.process.ProcessNodeTriggeredEvent) WorkItem(io.automatiko.engine.api.runtime.process.WorkItem) Iterator(java.util.Iterator) ProcessNodeLeftEvent(io.automatiko.engine.api.event.process.ProcessNodeLeftEvent) ProcessSignaledEvent(io.automatiko.engine.api.event.process.ProcessSignaledEvent) ProcessStartedEvent(io.automatiko.engine.api.event.process.ProcessStartedEvent) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) ProcessRuntime(io.automatiko.engine.api.runtime.process.ProcessRuntime) ArrayList(java.util.ArrayList) WorkUnit(io.automatiko.engine.api.uow.WorkUnit) List(java.util.List) ProcessNodeInstanceFailedEvent(io.automatiko.engine.api.event.process.ProcessNodeInstanceFailedEvent) ProcessCompletedEvent(io.automatiko.engine.api.event.process.ProcessCompletedEvent) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) Transition(io.automatiko.engine.api.workflow.workitem.Transition) SLAViolatedEvent(io.automatiko.engine.api.event.process.SLAViolatedEvent) ProcessWorkItemTransitionEvent(io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent) DelayedExecution(io.automatiko.engine.api.event.process.DelayedExecution) ProcessWorkItemTransitionEvent(io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent) ProcessEventListener(io.automatiko.engine.api.event.process.ProcessEventListener) ArrayList(java.util.ArrayList)

Example 3 with ProcessWorkItemTransitionEvent

use of io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent in project automatiko-engine by automatiko-io.

the class ProcessEventSupport method fireAfterWorkItemTransition.

public void fireAfterWorkItemTransition(final ProcessInstance instance, WorkItem workitem, Transition<?> transition, ProcessRuntime runtime) {
    final Iterator<ProcessEventListener> iter = getEventListenersIterator();
    final List<ProcessEventListener> delayedListeners = new ArrayList<ProcessEventListener>();
    final ProcessWorkItemTransitionEvent event = new ProcessWorkItemTransitionEventImpl(instance, workitem, transition, runtime, true);
    if (iter.hasNext()) {
        do {
            ProcessEventListener listener = iter.next();
            if (listener instanceof DelayedExecution) {
                delayedListeners.add(listener);
            } else {
                listener.afterWorkItemTransition(event);
            }
        } while (iter.hasNext());
    }
    unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, (e) -> {
        delayedListeners.forEach(l -> l.afterWorkItemTransition(e));
    }));
}
Also used : ProcessEventListener(io.automatiko.engine.api.event.process.ProcessEventListener) ProcessVariableChangedEvent(io.automatiko.engine.api.event.process.ProcessVariableChangedEvent) UnitOfWorkManager(io.automatiko.engine.api.uow.UnitOfWorkManager) DelayedExecution(io.automatiko.engine.api.event.process.DelayedExecution) ProcessNodeTriggeredEvent(io.automatiko.engine.api.event.process.ProcessNodeTriggeredEvent) WorkItem(io.automatiko.engine.api.runtime.process.WorkItem) Iterator(java.util.Iterator) ProcessNodeLeftEvent(io.automatiko.engine.api.event.process.ProcessNodeLeftEvent) ProcessSignaledEvent(io.automatiko.engine.api.event.process.ProcessSignaledEvent) ProcessStartedEvent(io.automatiko.engine.api.event.process.ProcessStartedEvent) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) ProcessRuntime(io.automatiko.engine.api.runtime.process.ProcessRuntime) ArrayList(java.util.ArrayList) WorkUnit(io.automatiko.engine.api.uow.WorkUnit) List(java.util.List) ProcessNodeInstanceFailedEvent(io.automatiko.engine.api.event.process.ProcessNodeInstanceFailedEvent) ProcessCompletedEvent(io.automatiko.engine.api.event.process.ProcessCompletedEvent) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) Transition(io.automatiko.engine.api.workflow.workitem.Transition) SLAViolatedEvent(io.automatiko.engine.api.event.process.SLAViolatedEvent) ProcessWorkItemTransitionEvent(io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent) DelayedExecution(io.automatiko.engine.api.event.process.DelayedExecution) ProcessWorkItemTransitionEvent(io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent) ProcessEventListener(io.automatiko.engine.api.event.process.ProcessEventListener) ArrayList(java.util.ArrayList)

Example 4 with ProcessWorkItemTransitionEvent

use of io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent in project automatiko-engine by automatiko-io.

the class ProcessInstanceEventBatch method events.

@Override
public Collection<DataEvent<?>> events() {
    Map<String, ProcessInstanceEventBody> processInstances = new LinkedHashMap<>();
    Map<String, UserTaskInstanceEventBody> userTaskInstances = new LinkedHashMap<>();
    Set<VariableInstanceEventBody> variables = new LinkedHashSet<>();
    for (ProcessEvent event : rawEvents) {
        ProcessInstanceEventBody body = processInstances.computeIfAbsent(event.getProcessInstance().getId(), key -> create(event));
        if (event instanceof ProcessNodeTriggeredEvent) {
            handleProcessNodeTriggeredEvent((ProcessNodeTriggeredEvent) event, body);
        } else if (event instanceof ProcessNodeLeftEvent) {
            handleProcessNodeLeftEvent((ProcessNodeLeftEvent) event, body);
        } else if (event instanceof ProcessCompletedEvent) {
            handleProcessCompletedEvent((ProcessCompletedEvent) event, body);
        } else if (event instanceof ProcessWorkItemTransitionEvent) {
            handleProcessWorkItemTransitionEvent((ProcessWorkItemTransitionEvent) event, userTaskInstances);
        } else if (event instanceof ProcessVariableChangedEvent) {
            handleProcessVariableChangedEvent((ProcessVariableChangedEvent) event, variables);
        }
    }
    Collection<DataEvent<?>> processedEvents = new ArrayList<>();
    processInstances.values().stream().map(pi -> new ProcessInstanceDataEvent(extractRuntimeSource(pi.metaData()), addons.toString(), pi.metaData(), pi)).forEach(processedEvents::add);
    userTaskInstances.values().stream().map(pi -> new UserTaskInstanceDataEvent(extractRuntimeSource(pi.metaData()), addons.toString(), pi.metaData(), pi)).forEach(processedEvents::add);
    variables.stream().map(pi -> new VariableInstanceDataEvent(extractRuntimeSource(pi.metaData()), addons.toString(), pi.metaData(), pi)).forEach(processedEvents::add);
    return processedEvents;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ProcessVariableChangedEvent(io.automatiko.engine.api.event.process.ProcessVariableChangedEvent) ProcessVariableChangedEvent(io.automatiko.engine.api.event.process.ProcessVariableChangedEvent) DataEvent(io.automatiko.engine.api.event.DataEvent) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) WorkUnit(io.automatiko.engine.api.uow.WorkUnit) UserTaskInstanceDataEvent(io.automatiko.engine.services.event.UserTaskInstanceDataEvent) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent) ProcessCompletedEvent(io.automatiko.engine.api.event.process.ProcessCompletedEvent) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) Map(java.util.Map) LinkedHashSet(java.util.LinkedHashSet) ExecutionsErrorInfo(io.automatiko.engine.api.workflow.ExecutionsErrorInfo) HumanTaskWorkItem(io.automatiko.engine.api.runtime.process.HumanTaskWorkItem) Addons(io.automatiko.engine.api.Addons) ProcessNodeTriggeredEvent(io.automatiko.engine.api.event.process.ProcessNodeTriggeredEvent) WorkItem(io.automatiko.engine.api.runtime.process.WorkItem) ProcessEvent(io.automatiko.engine.api.event.process.ProcessEvent) ProcessNodeLeftEvent(io.automatiko.engine.api.event.process.ProcessNodeLeftEvent) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) Collection(java.util.Collection) Tag(io.automatiko.engine.api.workflow.Tag) Set(java.util.Set) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) VariableInstanceDataEvent(io.automatiko.engine.services.event.VariableInstanceDataEvent) Base64(java.util.Base64) List(java.util.List) ProcessNodeEvent(io.automatiko.engine.api.event.process.ProcessNodeEvent) EventBatch(io.automatiko.engine.api.event.EventBatch) ProcessWorkItemTransitionEvent(io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent) ProcessEvent(io.automatiko.engine.api.event.process.ProcessEvent) ProcessWorkItemTransitionEvent(io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent) ArrayList(java.util.ArrayList) DataEvent(io.automatiko.engine.api.event.DataEvent) UserTaskInstanceDataEvent(io.automatiko.engine.services.event.UserTaskInstanceDataEvent) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent) VariableInstanceDataEvent(io.automatiko.engine.services.event.VariableInstanceDataEvent) ProcessCompletedEvent(io.automatiko.engine.api.event.process.ProcessCompletedEvent) LinkedHashMap(java.util.LinkedHashMap) VariableInstanceDataEvent(io.automatiko.engine.services.event.VariableInstanceDataEvent) ProcessNodeTriggeredEvent(io.automatiko.engine.api.event.process.ProcessNodeTriggeredEvent) UserTaskInstanceDataEvent(io.automatiko.engine.services.event.UserTaskInstanceDataEvent) ProcessNodeLeftEvent(io.automatiko.engine.api.event.process.ProcessNodeLeftEvent) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent)

Example 5 with ProcessWorkItemTransitionEvent

use of io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent in project automatiko-engine by automatiko-io.

the class UserTaskTest method testBasicUserTaskProcessVersioned.

@Test
public void testBasicUserTaskProcessVersioned() throws Exception {
    Application app = generateCodeProcessesOnly("usertask/UserTasksProcessVersion.bpmn2", "usertask/UserTasksProcessVersion2.bpmn2");
    assertThat(app).isNotNull();
    final List<String> workItemTransitionEvents = new ArrayList<>();
    app.config().process().processEventListeners().listeners().add(new DefaultProcessEventListener() {

        @Override
        public void beforeWorkItemTransition(ProcessWorkItemTransitionEvent event) {
            workItemTransitionEvents.add("BEFORE:: " + event);
        }

        @Override
        public void afterWorkItemTransition(ProcessWorkItemTransitionEvent event) {
            workItemTransitionEvents.add("AFTER:: " + event);
        }
    });
    // verify that both versions have corresponding process definitions
    assertThat(app.processes().processById("UserTasksProcess_2")).isNotNull();
    Process<? extends Model> p = app.processes().processById("UserTasksProcess_1");
    assertThat(p).isNotNull();
    // verify that both version have corresponding data model classes
    Class<?> model1Class = Class.forName("org.kie.kogito.test.UserTasksProcess_1Model", true, testClassLoader());
    assertNotNull(model1Class);
    Class<?> model2Class = Class.forName("org.kie.kogito.test.UserTasksProcess_2Model", true, testClassLoader());
    assertNotNull(model2Class);
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    List<WorkItem> workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    assertEquals("FirstTask", workItems.get(0).getName());
    processInstance.completeWorkItem(workItems.get(0).getId(), null, securityPolicy);
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    assertEquals("SecondTask", workItems.get(0).getName());
    processInstance.completeWorkItem(workItems.get(0).getId(), null, securityPolicy);
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    assertThat(workItemTransitionEvents).hasSize(8);
}
Also used : HashMap(java.util.HashMap) ProcessWorkItemTransitionEvent(io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent) ArrayList(java.util.ArrayList) WorkItem(io.automatiko.engine.api.workflow.WorkItem) Model(io.automatiko.engine.api.Model) DefaultProcessEventListener(io.automatiko.engine.api.event.process.DefaultProcessEventListener) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Aggregations

ProcessWorkItemTransitionEvent (io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent)6 ArrayList (java.util.ArrayList)6 Application (io.automatiko.engine.api.Application)3 Model (io.automatiko.engine.api.Model)3 DefaultProcessEventListener (io.automatiko.engine.api.event.process.DefaultProcessEventListener)3 ProcessCompletedEvent (io.automatiko.engine.api.event.process.ProcessCompletedEvent)3 ProcessNodeLeftEvent (io.automatiko.engine.api.event.process.ProcessNodeLeftEvent)3 ProcessNodeTriggeredEvent (io.automatiko.engine.api.event.process.ProcessNodeTriggeredEvent)3 ProcessVariableChangedEvent (io.automatiko.engine.api.event.process.ProcessVariableChangedEvent)3 NodeInstance (io.automatiko.engine.api.runtime.process.NodeInstance)3 ProcessInstance (io.automatiko.engine.api.runtime.process.ProcessInstance)3 WorkItem (io.automatiko.engine.api.runtime.process.WorkItem)3 WorkUnit (io.automatiko.engine.api.uow.WorkUnit)3 WorkItem (io.automatiko.engine.api.workflow.WorkItem)3 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Test (org.junit.jupiter.api.Test)3 DelayedExecution (io.automatiko.engine.api.event.process.DelayedExecution)2 ProcessEventListener (io.automatiko.engine.api.event.process.ProcessEventListener)2