Search in sources :

Example 1 with ExecutableProcessInstance

use of io.automatiko.engine.workflow.process.executable.instance.ExecutableProcessInstance in project automatiko-engine by automatiko-io.

the class LightProcessRuntimeContext method createProcessInstance.

@Override
public ProcessInstance createProcessInstance(Process process, CorrelationKey correlationKey) {
    ExecutableProcessInstance processInstance = new ExecutableProcessInstance();
    processInstance.setProcess(process);
    if (correlationKey != null) {
        processInstance.getMetaData().put("CorrelationKey", correlationKey);
    }
    return processInstance;
}
Also used : ExecutableProcessInstance(io.automatiko.engine.workflow.process.executable.instance.ExecutableProcessInstance)

Example 2 with ExecutableProcessInstance

use of io.automatiko.engine.workflow.process.executable.instance.ExecutableProcessInstance 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 ExecutableProcessInstance

use of io.automatiko.engine.workflow.process.executable.instance.ExecutableProcessInstance in project automatiko-engine by automatiko-io.

the class ProcessInstanceResolverStrategy method unmarshal.

public Object unmarshal(String dataType, Context context, ObjectInputStream is, byte[] object, ClassLoader classloader) throws IOException, ClassNotFoundException {
    String processInstanceId = new String(object);
    ProcessInstanceManager pim = retrieveProcessInstanceManager(is);
    // load it as read only to avoid any updates to the data base
    ProcessInstance processInstance = pim.getProcessInstance(processInstanceId, true);
    if (processInstance == null) {
        ExecutableProcessInstance result = new ExecutableProcessInstance();
        result.setId(processInstanceId);
        result.internalSetState(ProcessInstance.STATE_COMPLETED);
        return result;
    } else {
        connectProcessInstanceToRuntimeAndProcess(processInstance, is);
        return processInstance;
    }
}
Also used : ProcessInstanceManager(io.automatiko.engine.workflow.base.instance.ProcessInstanceManager) ExecutableProcessInstance(io.automatiko.engine.workflow.process.executable.instance.ExecutableProcessInstance) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance) ExecutableProcessInstance(io.automatiko.engine.workflow.process.executable.instance.ExecutableProcessInstance)

Example 4 with ExecutableProcessInstance

use of io.automatiko.engine.workflow.process.executable.instance.ExecutableProcessInstance in project automatiko-engine by automatiko-io.

the class MilestoneTest method testSimpleMilestone.

@Test
void testSimpleMilestone() throws Exception {
    Application app = generateCodeProcessesOnly("cases/milestones/SimpleMilestone.bpmn");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("TestCase.SimpleMilestone_1_0");
    ProcessInstance<?> processInstance = p.createInstance(p.createModel());
    assertState(processInstance, ProcessInstance.STATE_PENDING);
    Collection<Milestone> expected = new ArrayList<>();
    expected.add(Milestone.builder().withName("AutoStartMilestone").withStatus(AVAILABLE).build());
    expected.add(Milestone.builder().withName("SimpleMilestone").withStatus(AVAILABLE).build());
    assertMilestones(expected, processInstance.milestones());
    processInstance.start();
    assertState(processInstance, ProcessInstance.STATE_COMPLETED);
    expected = expected.stream().map(m -> Milestone.builder().withId(m.getId()).withName(m.getName()).withStatus(COMPLETED).build()).collect(Collectors.toList());
    assertMilestones(expected, processInstance.milestones());
    ExecutableProcessInstance legacyProcessInstance = (ExecutableProcessInstance) ((AbstractProcessInstance<?>) processInstance).processInstance();
    assertThat(legacyProcessInstance.getNodeInstances()).isEmpty();
    Optional<String> milestoneId = Stream.of(legacyProcessInstance.getNodeContainer().getNodes()).filter(node -> node.getName().equals("SimpleMilestone")).map(n -> (String) n.getMetaData().get(Metadata.UNIQUE_ID)).findFirst();
    assertTrue(milestoneId.isPresent());
    assertThat(legacyProcessInstance.getCompletedNodeIds()).contains(milestoneId.get());
}
Also used : AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Metadata(io.automatiko.engine.workflow.process.executable.core.Metadata) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) HashMap(java.util.HashMap) COMPLETED(io.automatiko.engine.api.workflow.flexible.ItemDescription.Status.COMPLETED) ArrayList(java.util.ArrayList) Application(io.automatiko.engine.api.Application) Map(java.util.Map) Process(io.automatiko.engine.api.workflow.Process) Model(io.automatiko.engine.api.Model) Collection(java.util.Collection) ExecutableProcessInstance(io.automatiko.engine.workflow.process.executable.instance.ExecutableProcessInstance) ProcessTestUtils.assertState(io.automatiko.engine.codegen.tests.ProcessTestUtils.assertState) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) AVAILABLE(io.automatiko.engine.api.workflow.flexible.ItemDescription.Status.AVAILABLE) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) Milestone(io.automatiko.engine.api.workflow.flexible.Milestone) WorkItem(io.automatiko.engine.api.workflow.WorkItem) Milestone(io.automatiko.engine.api.workflow.flexible.Milestone) ArrayList(java.util.ArrayList) ExecutableProcessInstance(io.automatiko.engine.workflow.process.executable.instance.ExecutableProcessInstance) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 5 with ExecutableProcessInstance

use of io.automatiko.engine.workflow.process.executable.instance.ExecutableProcessInstance 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)

Aggregations

ExecutableProcessInstance (io.automatiko.engine.workflow.process.executable.instance.ExecutableProcessInstance)7 InternalProcessRuntime (io.automatiko.engine.workflow.base.instance.InternalProcessRuntime)3 Test (org.junit.jupiter.api.Test)3 ProcessInstance (io.automatiko.engine.api.runtime.process.ProcessInstance)2 AVAILABLE (io.automatiko.engine.api.workflow.flexible.ItemDescription.Status.AVAILABLE)2 COMPLETED (io.automatiko.engine.api.workflow.flexible.ItemDescription.Status.COMPLETED)2 Milestone (io.automatiko.engine.api.workflow.flexible.Milestone)2 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)2 StateNode (io.automatiko.engine.workflow.process.core.node.StateNode)2 Metadata (io.automatiko.engine.workflow.process.executable.core.Metadata)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 Application (io.automatiko.engine.api.Application)1