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