Search in sources :

Example 1 with InternalProcessRuntime

use of io.automatiko.engine.workflow.base.instance.InternalProcessRuntime in project automatiko-engine by automatiko-io.

the class NodeInnerClassesTest method testNodeReading.

@Test
public void testNodeReading() {
    ExecutableProcess process = new ExecutableProcess();
    process.setId("org.company.core.process.event");
    process.setName("Event Process");
    List<Variable> variables = new ArrayList<Variable>();
    Variable variable = new Variable();
    variable.setName("event");
    ObjectDataType personDataType = new ObjectDataType(Person.class);
    variable.setType(personDataType);
    variables.add(variable);
    process.getVariableScope().setVariables(variables);
    process.setDynamic(true);
    CompositeNode compositeNode = new CompositeNode();
    compositeNode.setName("CompositeNode");
    compositeNode.setId(2);
    ForEachNode forEachNode = new ForEachNode();
    ForEachNode.ForEachSplitNode split = new ForEachNode.ForEachSplitNode();
    split.setName("ForEachSplit");
    split.setMetaData("hidden", true);
    split.setMetaData("UniqueId", forEachNode.getMetaData("Uniqueid") + ":foreach:split");
    forEachNode.internalAddNode(split);
    forEachNode.linkIncomingConnections(io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE, new CompositeNode.NodeAndType(split, io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE));
    process.addNode(forEachNode);
    InternalProcessRuntime ksession = createProcessRuntime(process);
    TestProcessEventListener procEventListener = new TestProcessEventListener();
    ksession.addEventListener(procEventListener);
    ProcessInstance processInstance = ksession.startProcess("org.company.core.process.event");
    assertNotNull(processInstance);
}
Also used : Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) ArrayList(java.util.ArrayList) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) ForEachNode(io.automatiko.engine.workflow.process.core.node.ForEachNode) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) TestProcessEventListener(io.automatiko.engine.workflow.process.test.TestProcessEventListener) Test(org.junit.jupiter.api.Test) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest)

Example 2 with InternalProcessRuntime

use of io.automatiko.engine.workflow.base.instance.InternalProcessRuntime in project automatiko-engine by automatiko-io.

the class EndNodeInstanceTest method testEndNode.

@Test
public void testEndNode() {
    MockNode mockNode = new MockNode();
    MockNodeInstanceFactory factory = new MockNodeInstanceFactory(new MockNodeInstance(mockNode));
    NodeInstanceFactoryRegistry.getInstance().register(mockNode.getClass(), factory);
    ExecutableProcess process = new ExecutableProcess();
    process.setId("test");
    InternalProcessRuntime processRuntime = createProcessRuntime(process);
    Node endNode = new EndNode();
    endNode.setId(1);
    endNode.setName("end node");
    mockNode.setId(2);
    new ConnectionImpl(mockNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
    process.addNode(mockNode);
    process.addNode(endNode);
    ExecutableProcessInstance processInstance = new ExecutableProcessInstance();
    processInstance.setId("1223");
    processInstance.setState(ProcessInstance.STATE_ACTIVE);
    processInstance.setProcess(process);
    processInstance.setProcessRuntime(processRuntime);
    MockNodeInstance mockNodeInstance = (MockNodeInstance) processInstance.getNodeInstance(mockNode);
    mockNodeInstance.triggerCompleted();
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Also used : EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) Node(io.automatiko.engine.workflow.process.core.Node) EndNode(io.automatiko.engine.workflow.process.core.node.EndNode) 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) Test(org.junit.jupiter.api.Test) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest)

Example 3 with InternalProcessRuntime

use of io.automatiko.engine.workflow.base.instance.InternalProcessRuntime 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)

Example 4 with InternalProcessRuntime

use of io.automatiko.engine.workflow.base.instance.InternalProcessRuntime in project automatiko-engine by automatiko-io.

the class NodeInstanceImpl method trigger.

public final void trigger(NodeInstance from, String type) {
    io.automatiko.engine.workflow.process.core.Node currentNode = (io.automatiko.engine.workflow.process.core.Node) getNode();
    // function flow check
    if (getProcessInstance().isFunctionFlow(this) && getProcessInstance().isExecutionNode(currentNode)) {
        Integer functionFlowCounter = (Integer) getProcessInstance().getMetaData("ATK_FUNC_FLOW_COUNTER");
        if (functionFlowCounter == null) {
            functionFlowCounter = 1;
            getProcessInstance().getMetaData().put("ATK_FUNC_FLOW_COUNTER", functionFlowCounter);
        } else {
            // function flow already called function
            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;
            });
            nodeInstanceContainer.removeNodeInstance(this);
            return;
        }
    }
    // check activation condition if this can be invoked
    if (currentNode.getActivationCheck().isPresent()) {
        if (!currentNode.getActivationCheck().get().isValid(getProcessInstance().getVariables())) {
            nodeInstanceContainer.removeNodeInstance(this);
            return;
        }
    }
    internalChangeState(NodeInstanceState.Active);
    boolean hidden = false;
    if (getNode().getMetaData().get(HIDDEN) != null) {
        hidden = true;
    }
    if (from != null) {
        int level = ((io.automatiko.engine.workflow.process.instance.NodeInstance) from).getLevel();
        ((io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) getNodeInstanceContainer()).setCurrentLevel(level);
        Collection<Connection> incoming = getNode().getIncomingConnections(type);
        for (Connection conn : incoming) {
            if (conn.getFrom().getId() == from.getNodeId()) {
                this.metaData.put(INCOMING_CONNECTION, conn.getMetaData().get(UNIQUE_ID));
                break;
            }
        }
    }
    if (dynamicParameters != null) {
        for (Entry<String, Object> entry : dynamicParameters.entrySet()) {
            setVariable(entry.getKey(), entry.getValue());
        }
    }
    configureSla();
    InternalProcessRuntime runtime = getProcessInstance().getProcessRuntime();
    if (!hidden) {
        runtime.getProcessEventSupport().fireBeforeNodeTriggered(this, runtime);
    }
    try {
        internalTrigger(from, type);
    } catch (Exception e) {
        String errorId = captureError(e);
        internalChangeState(NodeInstanceState.Failed);
        runtime.getProcessEventSupport().fireAfterNodeInstanceFailed(getProcessInstance(), this, errorId, getRootException(e).getMessage(), e, runtime);
        // stop after capturing error
        return;
    }
    if (!hidden) {
        runtime.getProcessEventSupport().fireAfterNodeTriggered(this, runtime);
    }
}
Also used : NodeInstanceContainer(io.automatiko.engine.api.runtime.process.NodeInstanceContainer) Node(io.automatiko.engine.api.definition.process.Node) Connection(io.automatiko.engine.api.definition.process.Connection) Process(io.automatiko.engine.api.definition.process.Process) WorkflowRuntimeException(io.automatiko.engine.workflow.process.instance.WorkflowRuntimeException) ArrayList(java.util.ArrayList) List(java.util.List) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) ActionNodeInstance(io.automatiko.engine.workflow.process.instance.node.ActionNodeInstance) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) CompositeNodeInstance(io.automatiko.engine.workflow.process.instance.node.CompositeNodeInstance)

Example 5 with InternalProcessRuntime

use of io.automatiko.engine.workflow.base.instance.InternalProcessRuntime in project automatiko-engine by automatiko-io.

the class NodeInstanceImpl method cancel.

public void cancel() {
    leaveTime = new Date();
    internalChangeState(NodeInstanceState.Teminated);
    boolean hidden = false;
    Node node = getNode();
    if (node != null && node.getMetaData().get(HIDDEN) != null) {
        hidden = true;
    }
    if (!hidden) {
        InternalProcessRuntime runtime = getProcessInstance().getProcessRuntime();
        runtime.getProcessEventSupport().fireBeforeNodeLeft(this, runtime);
    }
    nodeInstanceContainer.removeNodeInstance(this);
    if (!hidden) {
        InternalProcessRuntime runtime = getProcessInstance().getProcessRuntime();
        runtime.getProcessEventSupport().fireAfterNodeLeft(this, runtime);
    }
}
Also used : Node(io.automatiko.engine.api.definition.process.Node) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) Date(java.util.Date)

Aggregations

InternalProcessRuntime (io.automatiko.engine.workflow.base.instance.InternalProcessRuntime)39 Test (org.junit.jupiter.api.Test)18 AbstractBaseTest (io.automatiko.engine.workflow.test.util.AbstractBaseTest)17 ArrayList (java.util.ArrayList)17 ExecutableProcess (io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)16 HashMap (java.util.HashMap)12 ProcessInstance (io.automatiko.engine.api.runtime.process.ProcessInstance)11 EndNode (io.automatiko.engine.workflow.process.core.node.EndNode)10 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)10 List (java.util.List)10 Map (java.util.Map)10 ConnectionImpl (io.automatiko.engine.workflow.process.core.impl.ConnectionImpl)9 NodeInstance (io.automatiko.engine.api.runtime.process.NodeInstance)8 ProcessRuntimeImpl (io.automatiko.engine.workflow.base.instance.ProcessRuntimeImpl)7 Date (java.util.Date)7 Process (io.automatiko.engine.api.definition.process.Process)6 Variable (io.automatiko.engine.workflow.base.core.context.variable.Variable)6 ProcessAction (io.automatiko.engine.workflow.process.core.ProcessAction)6 ActionNode (io.automatiko.engine.workflow.process.core.node.ActionNode)6 WorkflowProcessInstance (io.automatiko.engine.workflow.process.instance.WorkflowProcessInstance)6