Search in sources :

Example 6 with ProcessCompletedEvent

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

the class ProcessEventSupportTest method testProcessEventListenerProcessState.

@Test
public void testProcessEventListenerProcessState() throws Exception {
    ExecutableProcess process = new ExecutableProcess();
    process.setId("org.company.core.process.event");
    process.setName("Event Process");
    StartNode startNode = new StartNode();
    startNode.setName("Start");
    startNode.setId(1);
    process.addNode(startNode);
    ActionNode actionNode = new ActionNode();
    actionNode.setName("Print");
    ProcessAction action = new ConsequenceAction("java", null);
    action.setMetaData("Action", new Action() {

        public void execute(ProcessContext context) throws Exception {
            logger.info("Executed action");
        }
    });
    actionNode.setAction(action);
    actionNode.setId(2);
    process.addNode(actionNode);
    new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, actionNode, Node.CONNECTION_DEFAULT_TYPE);
    EndNode endNode = new EndNode();
    endNode.setName("End");
    endNode.setId(3);
    process.addNode(endNode);
    new ConnectionImpl(actionNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
    InternalProcessRuntime processRuntime = new ProcessRuntimeImpl(Collections.singletonMap(process.getId(), process));
    final List<Integer> processEventStatusList = new ArrayList<Integer>();
    final ProcessEventListener processEventListener = new ProcessEventListener() {

        public void afterNodeLeft(ProcessNodeLeftEvent event) {
        }

        public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
        }

        public void afterProcessCompleted(ProcessCompletedEvent event) {
            processEventStatusList.add(new Integer(event.getProcessInstance().getState()));
        }

        public void afterProcessStarted(ProcessStartedEvent event) {
        }

        public void beforeNodeLeft(ProcessNodeLeftEvent event) {
        }

        public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
        }

        public void beforeProcessCompleted(ProcessCompletedEvent event) {
            processEventStatusList.add(new Integer(event.getProcessInstance().getState()));
        }

        public void beforeProcessStarted(ProcessStartedEvent event) {
        }

        public void beforeVariableChanged(ProcessVariableChangedEvent event) {
        }

        public void afterVariableChanged(ProcessVariableChangedEvent event) {
        }
    };
    processRuntime.addEventListener(processEventListener);
    // execute the process
    processRuntime.startProcess("org.company.core.process.event");
    assertEquals(2, processEventStatusList.size());
    assertEquals(new Integer(ProcessInstance.STATE_ACTIVE), processEventStatusList.get(0));
    assertEquals(new Integer(ProcessInstance.STATE_COMPLETED), processEventStatusList.get(1));
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) ProcessVariableChangedEvent(io.automatiko.engine.api.event.process.ProcessVariableChangedEvent) StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) Action(io.automatiko.engine.workflow.base.instance.impl.Action) ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) ConsequenceAction(io.automatiko.engine.workflow.process.core.impl.ConsequenceAction) ProcessEventListener(io.automatiko.engine.api.event.process.ProcessEventListener) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) ProcessRuntimeImpl(io.automatiko.engine.workflow.base.instance.ProcessRuntimeImpl) ArrayList(java.util.ArrayList) ProcessStartedEvent(io.automatiko.engine.api.event.process.ProcessStartedEvent) ConnectionImpl(io.automatiko.engine.workflow.process.core.impl.ConnectionImpl) ProcessCompletedEvent(io.automatiko.engine.api.event.process.ProcessCompletedEvent) ProcessContext(io.automatiko.engine.api.runtime.process.ProcessContext) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) ProcessNodeTriggeredEvent(io.automatiko.engine.api.event.process.ProcessNodeTriggeredEvent) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) ProcessNodeLeftEvent(io.automatiko.engine.api.event.process.ProcessNodeLeftEvent) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest) Test(org.junit.jupiter.api.Test)

Example 7 with ProcessCompletedEvent

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

the class ProcessEventSupport method fireBeforeProcessCompleted.

public void fireBeforeProcessCompleted(final ProcessInstance instance, ProcessRuntime runtime) {
    final Iterator<ProcessEventListener> iter = getEventListenersIterator();
    final List<ProcessEventListener> delayedListeners = new ArrayList<ProcessEventListener>();
    final ProcessCompletedEvent event = new ProcessCompletedEventImpl(instance, runtime);
    if (iter.hasNext()) {
        do {
            ProcessEventListener listener = iter.next();
            if (listener instanceof DelayedExecution) {
                delayedListeners.add(listener);
            } else {
                listener.beforeProcessCompleted(event);
            }
        } while (iter.hasNext());
    }
    unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, e -> {
        delayedListeners.forEach(l -> l.beforeProcessCompleted(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) ProcessEventListener(io.automatiko.engine.api.event.process.ProcessEventListener) ArrayList(java.util.ArrayList) ProcessCompletedEvent(io.automatiko.engine.api.event.process.ProcessCompletedEvent)

Example 8 with ProcessCompletedEvent

use of io.automatiko.engine.api.event.process.ProcessCompletedEvent 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)

Aggregations

ProcessCompletedEvent (io.automatiko.engine.api.event.process.ProcessCompletedEvent)8 ProcessNodeLeftEvent (io.automatiko.engine.api.event.process.ProcessNodeLeftEvent)8 ProcessNodeTriggeredEvent (io.automatiko.engine.api.event.process.ProcessNodeTriggeredEvent)8 ProcessVariableChangedEvent (io.automatiko.engine.api.event.process.ProcessVariableChangedEvent)8 ArrayList (java.util.ArrayList)8 ProcessEventListener (io.automatiko.engine.api.event.process.ProcessEventListener)7 ProcessStartedEvent (io.automatiko.engine.api.event.process.ProcessStartedEvent)7 ProcessEvent (io.automatiko.engine.api.event.process.ProcessEvent)5 ProcessContext (io.automatiko.engine.api.runtime.process.ProcessContext)5 InternalProcessRuntime (io.automatiko.engine.workflow.base.instance.InternalProcessRuntime)5 ProcessRuntimeImpl (io.automatiko.engine.workflow.base.instance.ProcessRuntimeImpl)5 Action (io.automatiko.engine.workflow.base.instance.impl.Action)5 ProcessAction (io.automatiko.engine.workflow.process.core.ProcessAction)5 ConnectionImpl (io.automatiko.engine.workflow.process.core.impl.ConnectionImpl)5 ConsequenceAction (io.automatiko.engine.workflow.process.core.impl.ConsequenceAction)5 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)5 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)5 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)5 ExecutableProcess (io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)5 AbstractBaseTest (io.automatiko.engine.workflow.test.util.AbstractBaseTest)5