Search in sources :

Example 41 with ProcessInstance

use of io.automatiko.engine.api.runtime.process.ProcessInstance in project automatiko-engine by automatiko-io.

the class ProcessEventSupport method fireBeforeSLAViolated.

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

Example 42 with ProcessInstance

use of io.automatiko.engine.api.runtime.process.ProcessInstance in project automatiko-engine by automatiko-io.

the class ProcessEventSupport method fireBeforeProcessSignaled.

public void fireBeforeProcessSignaled(String signal, Object data, final ProcessInstance instance, ProcessRuntime runtime) {
    final Iterator<ProcessEventListener> iter = getEventListenersIterator();
    final List<ProcessEventListener> delayedListeners = new ArrayList<ProcessEventListener>();
    final ProcessSignaledEvent event = new ProcessSignaledEventImpl(signal, data, instance, runtime);
    if (iter.hasNext()) {
        do {
            ProcessEventListener listener = iter.next();
            if (listener instanceof DelayedExecution) {
                delayedListeners.add(listener);
            } else {
                listener.beforeProcessSignaled(event);
            }
        } while (iter.hasNext());
    }
    unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, (e) -> {
        delayedListeners.forEach(l -> l.beforeProcessSignaled(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) ProcessSignaledEvent(io.automatiko.engine.api.event.process.ProcessSignaledEvent)

Example 43 with ProcessInstance

use of io.automatiko.engine.api.runtime.process.ProcessInstance in project automatiko-engine by automatiko-io.

the class CleanFilesEventListener method afterProcessCompleted.

@Override
public void afterProcessCompleted(ProcessCompletedEvent event) {
    ProcessInstance pi = event.getProcessInstance();
    for (Entry<String, Object> variable : pi.getVariables().entrySet()) {
        if (variable.getValue() instanceof ByteArrayFile) {
            ByteArrayFile file = (ByteArrayFile) variable.getValue();
            store.remove(pi.getProcess().getId(), pi.getProcess().getVersion(), pi.getId(), variable.getKey(), file.name());
        } else if (variable.getValue() instanceof Collection) {
            for (Object potentialFile : (Collection<?>) variable.getValue()) {
                if (potentialFile instanceof ByteArrayFile) {
                    ByteArrayFile file = (ByteArrayFile) potentialFile;
                    store.remove(pi.getProcess().getId(), pi.getProcess().getVersion(), pi.getId(), variable.getKey(), file.name());
                }
            }
        }
    }
}
Also used : Collection(java.util.Collection) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) ByteArrayFile(io.automatiko.engine.workflow.file.ByteArrayFile)

Example 44 with ProcessInstance

use of io.automatiko.engine.api.runtime.process.ProcessInstance in project automatiko-engine by automatiko-io.

the class JbpmBpmn2TestCase method assertNodeActive.

public void assertNodeActive(String processInstanceId, InternalProcessRuntime processRuntime, String... name) {
    List<String> names = new ArrayList<String>();
    for (String n : name) {
        names.add(n);
    }
    ProcessInstance processInstance = processRuntime.getProcessInstance(processInstanceId);
    if (processInstance instanceof WorkflowProcessInstance) {
        assertNodeActive((WorkflowProcessInstance) processInstance, names);
    }
    if (!names.isEmpty()) {
        String s = names.get(0);
        for (int i = 1; i < names.size(); i++) {
            s += ", " + names.get(i);
        }
        fail("Node(s) not active: " + s);
    }
}
Also used : ArrayList(java.util.ArrayList) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)

Example 45 with ProcessInstance

use of io.automatiko.engine.api.runtime.process.ProcessInstance in project automatiko-engine by automatiko-io.

the class JbpmBpmn2TestCase method assertProcessInstanceCompleted.

protected void assertProcessInstanceCompleted(String processInstanceId, InternalProcessRuntime processRuntime) {
    ProcessInstance processInstance = processRuntime.getProcessInstance(processInstanceId);
    assertNull(processInstance, "Process instance has not completed.");
}
Also used : ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)

Aggregations

ProcessInstance (io.automatiko.engine.api.runtime.process.ProcessInstance)56 ArrayList (java.util.ArrayList)25 NodeInstance (io.automatiko.engine.api.runtime.process.NodeInstance)19 List (java.util.List)18 WorkItem (io.automatiko.engine.api.runtime.process.WorkItem)17 ProcessCompletedEvent (io.automatiko.engine.api.event.process.ProcessCompletedEvent)16 ProcessEventListener (io.automatiko.engine.api.event.process.ProcessEventListener)16 ProcessNodeLeftEvent (io.automatiko.engine.api.event.process.ProcessNodeLeftEvent)16 ProcessNodeTriggeredEvent (io.automatiko.engine.api.event.process.ProcessNodeTriggeredEvent)16 ProcessStartedEvent (io.automatiko.engine.api.event.process.ProcessStartedEvent)16 ProcessVariableChangedEvent (io.automatiko.engine.api.event.process.ProcessVariableChangedEvent)16 ProcessRuntime (io.automatiko.engine.api.runtime.process.ProcessRuntime)16 DelayedExecution (io.automatiko.engine.api.event.process.DelayedExecution)15 ProcessNodeInstanceFailedEvent (io.automatiko.engine.api.event.process.ProcessNodeInstanceFailedEvent)15 ProcessSignaledEvent (io.automatiko.engine.api.event.process.ProcessSignaledEvent)15 ProcessWorkItemTransitionEvent (io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent)15 SLAViolatedEvent (io.automatiko.engine.api.event.process.SLAViolatedEvent)15 UnitOfWorkManager (io.automatiko.engine.api.uow.UnitOfWorkManager)15 WorkUnit (io.automatiko.engine.api.uow.WorkUnit)15 Transition (io.automatiko.engine.api.workflow.workitem.Transition)15