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