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;
}
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());
}
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;
}
}
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());
}
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());
}
Aggregations