Search in sources :

Example 16 with NodeInstance

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

the class AbstractProtobufProcessInstanceMarshaller method writeProcessInstance.

// Output methods
public AutomatikoMessages.ProcessInstance writeProcessInstance(MarshallerWriteContext context, ProcessInstance processInstance) throws IOException {
    WorkflowProcessInstanceImpl workFlow = (WorkflowProcessInstanceImpl) processInstance;
    AutomatikoMessages.ProcessInstance.Builder _instance = AutomatikoMessages.ProcessInstance.newBuilder().setId(workFlow.getId()).setProcessId(workFlow.getProcessId()).setState(workFlow.getState()).setProcessType(workFlow.getProcess().getType()).setSignalCompletion(workFlow.isSignalCompletion()).setSlaCompliance(workFlow.getSlaCompliance()).setStartDate(workFlow.getStartDate().getTime());
    if (workFlow.getProcessXml() != null) {
        _instance.setProcessXml(workFlow.getProcessXml());
    }
    if (workFlow.getDescription() != null) {
        _instance.setDescription(workFlow.getDescription());
    }
    if (workFlow.getInitiator() != null) {
        _instance.setInitiator(workFlow.getInitiator());
    }
    _instance.addAllCompletedNodeIds(workFlow.getCompletedNodeIds());
    if (workFlow.getCorrelationKey() != null) {
        _instance.setCorrelationKey(workFlow.getCorrelationKey());
    }
    if (workFlow.getSlaDueDate() != null) {
        _instance.setSlaDueDate(workFlow.getSlaDueDate().getTime());
    }
    if (workFlow.getSlaTimerId() != null) {
        _instance.setSlaTimerId(workFlow.getSlaTimerId());
    }
    if (workFlow.getParentProcessInstanceId() != null) {
        _instance.setParentProcessInstanceId(workFlow.getParentProcessInstanceId());
    }
    if (workFlow.getRootProcessInstanceId() != null) {
        _instance.setRootProcessInstanceId(workFlow.getRootProcessInstanceId());
    }
    if (workFlow.getRootProcessId() != null) {
        _instance.setRootProcessId(workFlow.getRootProcessId());
    }
    if (workFlow.getReferenceFromRoot() != null) {
        _instance.setReferenceFromRoot(workFlow.getReferenceFromRoot());
    }
    if (workFlow.getProcess().getVersion() != null) {
        _instance.setProcessVersion(workFlow.getProcess().getVersion());
    }
    List<ExecutionsErrorInfo> errors = workFlow.errors();
    if (errors != null) {
        for (ExecutionsErrorInfo error : errors) {
            _instance.addErrors(AutomatikoMessages.ProcessInstance.Error.newBuilder().setErrorNodeId(error.getFailedNodeId()).setErrorId(error.getErrorId()).setErrorMessage(error.getErrorMessage() == null ? "" : error.getErrorMessage()).setErrorDetails(error.getErrorDetails() == null ? "" : error.getErrorDetails()));
        }
    }
    if (workFlow.getReferenceId() != null) {
        _instance.setReferenceId(workFlow.getReferenceId());
    }
    Map<String, List<String>> children = workFlow.getChildren();
    if (children != null) {
        for (Entry<String, List<String>> entry : children.entrySet()) {
            _instance.addChildren(AutomatikoMessages.ProcessInstance.ProcessInstanchChildren.newBuilder().setProcessId(entry.getKey()).addAllIds(entry.getValue()).build());
        }
    }
    Collection<Tag> tags = workFlow.getTags();
    if (tags != null) {
        for (Tag tag : tags) {
            _instance.addTags(AutomatikoMessages.ProcessInstance.Tag.newBuilder().setId(tag.getId()).setValue(tag.getValue()));
        }
    }
    SwimlaneContextInstance swimlaneContextInstance = (SwimlaneContextInstance) workFlow.getContextInstance(SwimlaneContext.SWIMLANE_SCOPE);
    if (swimlaneContextInstance != null) {
        Map<String, String> swimlaneActors = swimlaneContextInstance.getSwimlaneActors();
        for (Map.Entry<String, String> entry : swimlaneActors.entrySet()) {
            _instance.addSwimlaneContext(AutomatikoMessages.ProcessInstance.SwimlaneContextInstance.newBuilder().setSwimlane(entry.getKey()).setActorId(entry.getValue()).build());
        }
    }
    List<NodeInstance> nodeInstances = new ArrayList<NodeInstance>(workFlow.getNodeInstances());
    Collections.sort(nodeInstances, new Comparator<NodeInstance>() {

        public int compare(NodeInstance o1, NodeInstance o2) {
            return (int) (o1.getId().compareTo(o2.getId()));
        }
    });
    for (NodeInstance nodeInstance : nodeInstances) {
        _instance.addNodeInstance(writeNodeInstance(context, nodeInstance));
    }
    List<ContextInstance> exclusiveGroupInstances = workFlow.getContextInstances(ExclusiveGroup.EXCLUSIVE_GROUP);
    if (exclusiveGroupInstances != null) {
        for (ContextInstance contextInstance : exclusiveGroupInstances) {
            AutomatikoMessages.ProcessInstance.ExclusiveGroupInstance.Builder _exclusive = AutomatikoMessages.ProcessInstance.ExclusiveGroupInstance.newBuilder();
            ExclusiveGroupInstance exclusiveGroupInstance = (ExclusiveGroupInstance) contextInstance;
            Collection<NodeInstance> groupNodeInstances = exclusiveGroupInstance.getNodeInstances();
            for (NodeInstance nodeInstance : groupNodeInstances) {
                _exclusive.addGroupNodeInstanceId(nodeInstance.getId());
            }
            _instance.addExclusiveGroup(_exclusive.build());
        }
    }
    if (!(boolean) context.env.getOrDefault("_ignore_vars_", false)) {
        writeVariableScope(context, workFlow, _instance);
    }
    List<Map.Entry<String, Integer>> iterationlevels = new ArrayList<Map.Entry<String, Integer>>(workFlow.getIterationLevels().entrySet());
    Collections.sort(iterationlevels, new Comparator<Map.Entry<String, Integer>>() {

        public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
            return o1.getKey().compareTo(o2.getKey());
        }
    });
    for (Map.Entry<String, Integer> level : iterationlevels) {
        if (level.getValue() != null) {
            _instance.addIterationLevels(AutomatikoMessages.IterationLevel.newBuilder().setId(level.getKey()).setLevel(level.getValue()));
        }
    }
    return _instance.build();
}
Also used : ExecutionsErrorInfo(io.automatiko.engine.api.workflow.ExecutionsErrorInfo) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) ArrayList(java.util.ArrayList) Entry(java.util.Map.Entry) List(java.util.List) ArrayList(java.util.ArrayList) ExclusiveGroupInstance(io.automatiko.engine.workflow.base.instance.context.exclusive.ExclusiveGroupInstance) SwimlaneContextInstance(io.automatiko.engine.workflow.base.instance.context.swimlane.SwimlaneContextInstance) SwimlaneContextInstance(io.automatiko.engine.workflow.base.instance.context.swimlane.SwimlaneContextInstance) ContextInstance(io.automatiko.engine.workflow.base.instance.ContextInstance) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) Tag(io.automatiko.engine.api.workflow.Tag) Map(java.util.Map) HashMap(java.util.HashMap) CompositeContextNodeInstance(io.automatiko.engine.workflow.process.instance.node.CompositeContextNodeInstance) StateNodeInstance(io.automatiko.engine.workflow.process.instance.node.StateNodeInstance) ForEachNodeInstance(io.automatiko.engine.workflow.process.instance.node.ForEachNodeInstance) EventSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventSubProcessNodeInstance) TimerNodeInstance(io.automatiko.engine.workflow.process.instance.node.TimerNodeInstance) MilestoneNodeInstance(io.automatiko.engine.workflow.process.instance.node.MilestoneNodeInstance) HumanTaskNodeInstance(io.automatiko.engine.workflow.process.instance.node.HumanTaskNodeInstance) SubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.SubProcessNodeInstance) WorkItemNodeInstance(io.automatiko.engine.workflow.process.instance.node.WorkItemNodeInstance) DynamicNodeInstance(io.automatiko.engine.workflow.process.instance.node.DynamicNodeInstance) LambdaSubProcessNodeInstance(io.automatiko.engine.workflow.process.instance.node.LambdaSubProcessNodeInstance) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) RuleSetNodeInstance(io.automatiko.engine.workflow.process.instance.node.RuleSetNodeInstance) EventNodeInstance(io.automatiko.engine.workflow.process.instance.node.EventNodeInstance)

Example 17 with NodeInstance

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

the class StartNodeInstanceTest method testStartNode.

@Test
public void testStartNode() {
    MockNode mockNode = new MockNode();
    MockNodeInstanceFactory mockNodeFactory = new MockNodeInstanceFactory(new MockNodeInstance(mockNode));
    NodeInstanceFactoryRegistry.getInstance().register(mockNode.getClass(), mockNodeFactory);
    ExecutableProcess process = new ExecutableProcess();
    process.setId("test");
    InternalProcessRuntime processRuntime = createProcessRuntime(process);
    StartNode startNode = new StartNode();
    startNode.setId(1);
    startNode.setName("start node");
    mockNode.setId(2);
    new ConnectionImpl(startNode, io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE, mockNode, io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE);
    process.addNode(startNode);
    process.addNode(mockNode);
    ExecutableProcessInstance processInstance = new ExecutableProcessInstance();
    processInstance.setProcess(process);
    processInstance.setProcessRuntime(processRuntime);
    assertEquals(ProcessInstance.STATE_PENDING, processInstance.getState());
    processInstance.start();
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    MockNodeInstance mockNodeInstance = mockNodeFactory.getMockNodeInstance();
    List<NodeInstance> triggeredBy = mockNodeInstance.getTriggers().get(io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE);
    assertNotNull(triggeredBy);
    assertEquals(1, triggeredBy.size());
    assertSame(startNode.getId(), triggeredBy.get(0).getNodeId());
}
Also used : StartNode(io.automatiko.engine.workflow.process.core.node.StartNode) ExecutableProcessInstance(io.automatiko.engine.workflow.process.executable.instance.ExecutableProcessInstance) ConnectionImpl(io.automatiko.engine.workflow.process.core.impl.ConnectionImpl) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) Test(org.junit.jupiter.api.Test) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest)

Example 18 with NodeInstance

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

the class ProcessEventSupport method fireBeforeNodeTriggered.

public void fireBeforeNodeTriggered(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.beforeNodeTriggered(event);
            }
        } while (iter.hasNext());
    }
    unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, e -> {
        delayedListeners.forEach(l -> l.beforeNodeTriggered(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 19 with NodeInstance

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

the class ProcessEventSupport method fireAfterSLAViolated.

public void fireAfterSLAViolated(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.afterSLAViolated(event);
            }
        } while (iter.hasNext());
    }
    unitOfWorkManager.currentUnitOfWork().intercept(WorkUnit.create(event, e -> {
        delayedListeners.forEach(l -> l.afterSLAViolated(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 20 with NodeInstance

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

the class ProcessEventSupport method fireAfterNodeLeft.

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

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