Search in sources :

Example 6 with NodeInstance

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

the class ProcessEventSupport method fireAfterNodeInstanceFailed.

public void fireAfterNodeInstanceFailed(final ProcessInstance instance, NodeInstance nodeInstance, String errorId, String errorMessage, Exception exception, ProcessRuntime runtime) {
    final Iterator<ProcessEventListener> iter = getEventListenersIterator();
    final List<ProcessEventListener> delayedListeners = new ArrayList<ProcessEventListener>();
    final ProcessNodeInstanceFailedEvent event = new ProcessNodeInstanceFailedEventImpl(instance, nodeInstance, errorId, errorMessage, exception, runtime);
    if (iter.hasNext()) {
        do {
            ProcessEventListener listener = iter.next();
            if (listener instanceof DelayedExecution) {
                delayedListeners.add(listener);
            } else {
                listener.afterNodeInstanceFailed(event);
            }
        } while (iter.hasNext());
    }
    unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, (e) -> {
        delayedListeners.forEach(l -> l.afterNodeInstanceFailed(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) ProcessNodeInstanceFailedEvent(io.automatiko.engine.api.event.process.ProcessNodeInstanceFailedEvent) DelayedExecution(io.automatiko.engine.api.event.process.DelayedExecution) ProcessEventListener(io.automatiko.engine.api.event.process.ProcessEventListener) ArrayList(java.util.ArrayList)

Example 7 with NodeInstance

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

the class ProcessEventSupport method fireAfterNodeTriggered.

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

Example 8 with NodeInstance

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

the class ProcessEventSupport method fireBeforeVariableChanged.

public void fireBeforeVariableChanged(final String id, final String instanceId, final Object oldValue, final Object newValue, final List<String> tags, final ProcessInstance processInstance, NodeInstance nodeInstance, ProcessRuntime runtime) {
    final Iterator<ProcessEventListener> iter = getEventListenersIterator();
    final List<ProcessEventListener> delayedListeners = new ArrayList<ProcessEventListener>();
    final ProcessVariableChangedEvent event = new ProcessVariableChangedEventImpl(id, instanceId, oldValue, newValue, tags, processInstance, nodeInstance, runtime);
    if (iter.hasNext()) {
        do {
            ProcessEventListener listener = iter.next();
            if (listener instanceof DelayedExecution) {
                delayedListeners.add(listener);
            } else {
                listener.beforeVariableChanged(event);
            }
        } while (iter.hasNext());
    }
    unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, e -> {
        delayedListeners.forEach(l -> l.beforeVariableChanged(e));
    }));
}
Also used : ProcessVariableChangedEvent(io.automatiko.engine.api.event.process.ProcessVariableChangedEvent) 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)

Example 9 with NodeInstance

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

the class MockNodeInstance method internalTrigger.

public void internalTrigger(NodeInstance from, String type) {
    if (type == null) {
        throw new IllegalArgumentException("Trigger type is null!");
    }
    triggerTime = new Date();
    List<NodeInstance> list = triggers.get(type);
    if (list == null) {
        list = new ArrayList<NodeInstance>();
        triggers.put(type, list);
    }
    list.add(from);
}
Also used : NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) Date(java.util.Date)

Example 10 with NodeInstance

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

the class EndNodeInstance method internalTrigger.

public void internalTrigger(final NodeInstance from, String type) {
    super.internalTrigger(from, type);
    if (!io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
        throw new IllegalArgumentException("An EndNode only accepts default incoming connections!");
    }
    leaveTime = new Date();
    boolean hidden = false;
    if (getNode().getMetaData().get(HIDDEN) != null) {
        hidden = true;
    }
    if (getProcessInstance().isFunctionFlow(this) && getNodeInstanceContainer() instanceof ProcessInstance) {
        // only when running as function flow and node is in the top level node container meaning process instance
        // and not subprocesses
        getProcessInstance().getMetaData().compute("ATK_FUNC_FLOW_NEXT", (k, v) -> {
            if (v == null) {
                v = new ArrayList<String>();
            }
            Process process = getProcessInstance().getProcess();
            String version = "";
            if (process.getVersion() != null && !process.getVersion().trim().isEmpty()) {
                version = ".v" + process.getVersion().replaceAll("\\.", "_");
            }
            String defaultNextNode = process.getPackageName() + "." + process.getId() + version + "." + getNodeName().toLowerCase();
            ((List<String>) v).add((String) getNode().getMetaData().getOrDefault("functionType", defaultNextNode));
            return v;
        });
    }
    InternalProcessRuntime runtime = getProcessInstance().getProcessRuntime();
    if (!hidden) {
        runtime.getProcessEventSupport().fireBeforeNodeLeft(this, runtime);
    }
    ((NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
    if (getEndNode().isTerminate()) {
        if (getNodeInstanceContainer() instanceof CompositeNodeInstance) {
            if (getEndNode().getScope() == PROCESS_SCOPE) {
                getProcessInstance().setState(STATE_COMPLETED);
            } else {
                while (!getNodeInstanceContainer().getNodeInstances().isEmpty()) {
                    ((io.automatiko.engine.workflow.process.instance.NodeInstance) getNodeInstanceContainer().getNodeInstances().iterator().next()).cancel();
                }
                ((NodeInstanceContainer) getNodeInstanceContainer()).nodeInstanceCompleted(this, null);
            }
        } else {
            ((NodeInstanceContainer) getNodeInstanceContainer()).setState(STATE_COMPLETED);
        }
    } else {
        ((NodeInstanceContainer) getNodeInstanceContainer()).nodeInstanceCompleted(this, null);
    }
    if (!hidden) {
        runtime.getProcessEventSupport().fireAfterNodeLeft(this, runtime);
    }
    String uniqueId = (String) getNode().getMetaData().get(UNIQUE_ID);
    if (uniqueId == null) {
        uniqueId = ((NodeImpl) getNode()).getUniqueId();
    }
    ((WorkflowProcessInstanceImpl) getProcessInstance()).addCompletedNodeId(uniqueId);
}
Also used : NodeInstanceContainer(io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) Process(io.automatiko.engine.api.definition.process.Process) Date(java.util.Date) ProcessInstance(io.automatiko.engine.workflow.base.instance.ProcessInstance) ArrayList(java.util.ArrayList) List(java.util.List) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance)

Aggregations

NodeInstance (io.automatiko.engine.api.runtime.process.NodeInstance)26 ArrayList (java.util.ArrayList)20 List (java.util.List)15 ProcessInstance (io.automatiko.engine.api.runtime.process.ProcessInstance)14 DelayedExecution (io.automatiko.engine.api.event.process.DelayedExecution)9 ProcessCompletedEvent (io.automatiko.engine.api.event.process.ProcessCompletedEvent)9 ProcessEventListener (io.automatiko.engine.api.event.process.ProcessEventListener)9 ProcessNodeInstanceFailedEvent (io.automatiko.engine.api.event.process.ProcessNodeInstanceFailedEvent)9 ProcessNodeLeftEvent (io.automatiko.engine.api.event.process.ProcessNodeLeftEvent)9 ProcessNodeTriggeredEvent (io.automatiko.engine.api.event.process.ProcessNodeTriggeredEvent)9 ProcessSignaledEvent (io.automatiko.engine.api.event.process.ProcessSignaledEvent)9 ProcessStartedEvent (io.automatiko.engine.api.event.process.ProcessStartedEvent)9 ProcessVariableChangedEvent (io.automatiko.engine.api.event.process.ProcessVariableChangedEvent)9 ProcessWorkItemTransitionEvent (io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent)9 SLAViolatedEvent (io.automatiko.engine.api.event.process.SLAViolatedEvent)9 ProcessRuntime (io.automatiko.engine.api.runtime.process.ProcessRuntime)9 WorkItem (io.automatiko.engine.api.runtime.process.WorkItem)9 UnitOfWorkManager (io.automatiko.engine.api.uow.UnitOfWorkManager)9 WorkUnit (io.automatiko.engine.api.uow.WorkUnit)9 Transition (io.automatiko.engine.api.workflow.workitem.Transition)9