Search in sources :

Example 21 with InternalProcessRuntime

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

the class ProcessInstanceResolverStrategy method connectProcessInstanceToRuntimeAndProcess.

/**
 * Fill the process instance .kruntime and .process fields with the appropriate
 * values.
 *
 * @param processInstance
 * @param streamContext
 */
private void connectProcessInstanceToRuntimeAndProcess(ProcessInstance processInstance, Object streamContext) {
    ProcessInstanceImpl processInstanceImpl = (ProcessInstanceImpl) processInstance;
    InternalProcessRuntime runtime = processInstanceImpl.getProcessRuntime();
    // Attach the process if not present
    if (processInstance.getProcess() == null) {
        String processId = processInstance.getProcessId();
        if (processId != null) {
            Process process = runtime.getProcess(processId);
            if (process != null) {
                processInstanceImpl.setProcess(process);
            }
        }
    }
}
Also used : ProcessInstanceImpl(io.automatiko.engine.workflow.base.instance.impl.ProcessInstanceImpl) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) Process(io.automatiko.engine.api.definition.process.Process)

Example 22 with InternalProcessRuntime

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

the class FactoryTest method test.

@Test
public void test() {
    ExecutableProcessFactory factory = ExecutableProcessFactory.createProcess("ExampleProcess");
    factory.variable("x", new ObjectDataType(java.lang.String.class));
    factory.variable("y", new ObjectDataType(java.lang.String.class));
    factory.variable("list", new ObjectDataType(java.util.List.class, "java.util.List<String>"));
    factory.variable("listOut", new ObjectDataType(java.util.List.class, "java.util.List<String>"));
    factory.name("Example Process");
    factory.packageName("org.company.bpmn2");
    factory.dynamic(false);
    factory.version("1.0");
    factory.visibility("Private");
    factory.metaData("TargetNamespace", "http://www.example.org/MinimalExample");
    factory.startNode(1).name("StartProcess").done();
    factory.dynamicNode(2).metaData("UniqueId", "_2").metaData("MICollectionOutput", "_2_listOutOutput").metaData("x", 96).metaData("y", 16).activationExpression(kcontext -> Objects.equals(kcontext.getVariable("x"), kcontext.getVariable("oldValue"))).variable("x", new ObjectDataType(java.lang.String.class)).exceptionHandler(RuntimeException.class.getName(), "java", "System.out.println(\"Error\");").autoComplete(true).language("java").done();
    factory.humanTaskNode(3).name("Task").taskName("Task Name").actorId("Actor").comment("Hey").content("Some content").workParameter("x", "Parameter").inMapping("x", "y").outMapping("y", "x").waitForCompletion(true).timer("1s", null, "java", "").onEntryAction("java", "").onExitAction("java", "").done();
    factory.faultNode(4).name("Fault").faultName("Fault Name").faultVariable("x").done();
    factory.connection(1, 2, "_1-_2").connection(2, 3, "_2-_3").connection(3, 4, "_3-_4");
    factory.validate();
    List<String> list = new ArrayList<String>();
    list.add("first");
    list.add("second");
    List<String> listOut = new ArrayList<String>();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("x", "oldValue");
    parameters.put("list", list);
    InternalProcessRuntime ksession = createProcessRuntime(factory.getProcess());
    ksession.startProcess("ExampleProcess", parameters);
}
Also used : Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest) List(java.util.List) ExecutableProcessFactory(io.automatiko.engine.workflow.process.executable.core.ExecutableProcessFactory) Map(java.util.Map) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) List(java.util.List) ArrayList(java.util.ArrayList) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) ExecutableProcessFactory(io.automatiko.engine.workflow.process.executable.core.ExecutableProcessFactory) Test(org.junit.jupiter.api.Test) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest)

Example 23 with InternalProcessRuntime

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

the class ForEachTest method test.

@Test
public void test() {
    ExecutableProcessFactory factory = ExecutableProcessFactory.createProcess("ParentProcess");
    factory.variable("x", new ObjectDataType(java.lang.String.class));
    factory.variable("y", new ObjectDataType(java.lang.String.class));
    factory.variable("list", new ObjectDataType(java.util.List.class, "java.util.List<String>"));
    factory.variable("listOut", new ObjectDataType(java.util.List.class, "java.util.List<String>"));
    factory.name("Parent Process");
    factory.packageName("org.company.bpmn2");
    factory.dynamic(false);
    factory.version("1.0");
    factory.visibility("Private");
    factory.metaData("TargetNamespace", "http://www.example.org/MinimalExample");
    io.automatiko.engine.workflow.process.executable.core.factory.StartNodeFactory startNode1 = factory.startNode(1);
    startNode1.name("StartProcess");
    startNode1.done();
    io.automatiko.engine.workflow.process.executable.core.factory.ForEachNodeFactory forEachNode2 = factory.forEachNode(2);
    forEachNode2.metaData("UniqueId", "_2");
    forEachNode2.metaData("MICollectionOutput", "_2_listOutOutput");
    forEachNode2.metaData("x", 96);
    forEachNode2.metaData("width", 110);
    forEachNode2.metaData("y", 16);
    forEachNode2.metaData("MICollectionInput", "_2_input");
    forEachNode2.metaData("height", 48);
    forEachNode2.collectionExpression("list");
    forEachNode2.variable("x", new ObjectDataType(java.lang.String.class));
    forEachNode2.outputCollectionExpression("listOut");
    forEachNode2.outputVariable("y", new ObjectDataType(java.lang.String.class));
    forEachNode2.actionNode(5).action((kcontext) -> System.out.println(kcontext.getVariable("x"))).done();
    forEachNode2.linkIncomingConnections(5);
    forEachNode2.linkOutgoingConnections(5);
    forEachNode2.done();
    io.automatiko.engine.workflow.process.executable.core.factory.EndNodeFactory endNode3 = factory.endNode(3);
    endNode3.name("EndProcess");
    endNode3.terminate(true);
    endNode3.done();
    factory.connection(1, 2, "_1-_2");
    factory.connection(2, 3, "_2-_3");
    factory.validate();
    List<String> list = new ArrayList<String>();
    list.add("first");
    list.add("second");
    List<String> listOut = new ArrayList<String>();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("x", "oldValue");
    parameters.put("list", list);
    parameters.put("listOut", listOut);
    InternalProcessRuntime ksession = createProcessRuntime(factory.getProcess());
    ksession.startProcess("ParentProcess", parameters);
}
Also used : Test(org.junit.jupiter.api.Test) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest) List(java.util.List) ExecutableProcessFactory(io.automatiko.engine.workflow.process.executable.core.ExecutableProcessFactory) Map(java.util.Map) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ObjectDataType(io.automatiko.engine.workflow.base.core.datatype.impl.type.ObjectDataType) ExecutableProcessFactory(io.automatiko.engine.workflow.process.executable.core.ExecutableProcessFactory) List(java.util.List) ArrayList(java.util.ArrayList) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) Test(org.junit.jupiter.api.Test) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest)

Example 24 with InternalProcessRuntime

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

the class ProcessEventSupportTest method testProcessEventListenerWithStartEvent.

@Test
public void testProcessEventListenerWithStartEvent() 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);
    EventTrigger trigger = new EventTrigger();
    EventTypeFilter eventFilter = new EventTypeFilter();
    eventFilter.setType("signal");
    trigger.addEventFilter(eventFilter);
    startNode.addTrigger(trigger);
    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<ProcessEvent> processEventList = new ArrayList<ProcessEvent>();
    final ProcessEventListener processEventListener = new ProcessEventListener() {

        public void afterNodeLeft(ProcessNodeLeftEvent event) {
            processEventList.add(event);
        }

        public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
            processEventList.add(event);
        }

        public void afterProcessCompleted(ProcessCompletedEvent event) {
            processEventList.add(event);
        }

        public void afterProcessStarted(ProcessStartedEvent event) {
            processEventList.add(event);
        }

        public void beforeNodeLeft(ProcessNodeLeftEvent event) {
            processEventList.add(event);
        }

        public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
            processEventList.add(event);
        }

        public void beforeProcessCompleted(ProcessCompletedEvent event) {
            processEventList.add(event);
        }

        public void beforeProcessStarted(ProcessStartedEvent event) {
            processEventList.add(event);
        }

        public void beforeVariableChanged(ProcessVariableChangedEvent event) {
            processEventList.add(event);
        }

        public void afterVariableChanged(ProcessVariableChangedEvent event) {
            processEventList.add(event);
        }
    };
    processRuntime.addEventListener(processEventListener);
    // execute the process
    // session.startProcess("org.company.core.process.event");
    processRuntime.signalEvent("signal", null);
    assertEquals(16, processEventList.size());
    assertEquals("org.company.core.process.event", ((ProcessStartedEvent) processEventList.get(0)).getProcessInstance().getProcessId());
    assertEquals("Start", ((ProcessNodeTriggeredEvent) processEventList.get(1)).getNodeInstance().getNodeName());
    assertEquals("Start", ((ProcessNodeLeftEvent) processEventList.get(2)).getNodeInstance().getNodeName());
    assertEquals("Print", ((ProcessNodeTriggeredEvent) processEventList.get(3)).getNodeInstance().getNodeName());
    assertEquals("Print", ((ProcessNodeLeftEvent) processEventList.get(4)).getNodeInstance().getNodeName());
    assertEquals("End", ((ProcessNodeTriggeredEvent) processEventList.get(5)).getNodeInstance().getNodeName());
    assertEquals("End", ((ProcessNodeLeftEvent) processEventList.get(6)).getNodeInstance().getNodeName());
    assertEquals("org.company.core.process.event", ((ProcessCompletedEvent) processEventList.get(7)).getProcessInstance().getProcessId());
    assertEquals("org.company.core.process.event", ((ProcessCompletedEvent) processEventList.get(8)).getProcessInstance().getProcessId());
    assertEquals("End", ((ProcessNodeLeftEvent) processEventList.get(9)).getNodeInstance().getNodeName());
    assertEquals("End", ((ProcessNodeTriggeredEvent) processEventList.get(10)).getNodeInstance().getNodeName());
    assertEquals("Print", ((ProcessNodeLeftEvent) processEventList.get(11)).getNodeInstance().getNodeName());
    assertEquals("Print", ((ProcessNodeTriggeredEvent) processEventList.get(12)).getNodeInstance().getNodeName());
    assertEquals("Start", ((ProcessNodeLeftEvent) processEventList.get(13)).getNodeInstance().getNodeName());
    assertEquals("Start", ((ProcessNodeTriggeredEvent) processEventList.get(14)).getNodeInstance().getNodeName());
    assertEquals("org.company.core.process.event", ((ProcessStartedEvent) processEventList.get(15)).getProcessInstance().getProcessId());
}
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) ProcessEvent(io.automatiko.engine.api.event.process.ProcessEvent) 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) EventTypeFilter(io.automatiko.engine.workflow.base.core.event.EventTypeFilter) 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) EventTrigger(io.automatiko.engine.workflow.process.core.node.EventTrigger) AbstractBaseTest(io.automatiko.engine.workflow.test.util.AbstractBaseTest) Test(org.junit.jupiter.api.Test)

Example 25 with InternalProcessRuntime

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

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