use of io.automatiko.engine.workflow.process.instance.NodeInstanceContainer in project automatiko-engine by automatiko-io.
the class EventSubProcessNodeInstance method nodeInstanceCompleted.
@Override
public void nodeInstanceCompleted(io.automatiko.engine.workflow.process.instance.NodeInstance nodeInstance, String outType) {
if (nodeInstance instanceof EndNodeInstance) {
if (getCompositeNode().isKeepActive()) {
StartNode startNode = getCompositeNode().findStartNode();
triggerCompleted(true);
if (startNode.isInterrupting()) {
String faultName = getProcessInstance().getOutcome() == null ? "" : getProcessInstance().getOutcome();
if (startNode.getMetaData("FaultCode") != null) {
faultName = (String) startNode.getMetaData("FaultCode");
}
if (getNodeInstanceContainer() instanceof ProcessInstance) {
((ProcessInstance) getProcessInstance()).setState(ProcessInstance.STATE_ABORTED, faultName);
} else {
((NodeInstanceContainer) getNodeInstanceContainer()).setState(ProcessInstance.STATE_ABORTED);
// to allow top level process instance in case there are no more active nodes
((NodeInstanceContainer) ((ProcessInstance) getProcessInstance())).nodeInstanceCompleted(this, null);
}
}
}
} else {
throw new IllegalArgumentException("Completing a node instance that has no outgoing connection not supported.");
}
}
use of io.automatiko.engine.workflow.process.instance.NodeInstanceContainer in project automatiko-engine by automatiko-io.
the class FaultNodeInstance method internalTrigger.
public void internalTrigger(final NodeInstance from, String type) {
if (!io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
throw new IllegalArgumentException("A FaultNode only accepts default incoming connections!");
}
triggerTime = new Date();
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;
});
}
String faultName = getFaultName();
ExceptionScopeInstance exceptionScopeInstance = getExceptionScopeInstance(faultName);
NodeInstanceContainer nodeInstanceContainer = (NodeInstanceContainer) getNodeInstanceContainer();
nodeInstanceContainer.removeNodeInstance(this);
boolean exceptionHandled = false;
if (getFaultNode().isTerminateParent()) {
// events
if (exceptionScopeInstance != null) {
exceptionHandled = true;
handleException(faultName, exceptionScopeInstance);
}
if (nodeInstanceContainer instanceof CompositeNodeInstance) {
((CompositeNodeInstance) nodeInstanceContainer).cancel();
} else if (nodeInstanceContainer instanceof WorkflowProcessInstance) {
Collection<NodeInstance> nodeInstances = ((WorkflowProcessInstance) nodeInstanceContainer).getNodeInstances();
for (NodeInstance nodeInstance : nodeInstances) {
((io.automatiko.engine.workflow.process.instance.NodeInstance) nodeInstance).cancel();
}
}
}
String uniqueId = (String) getNode().getMetaData().get(UNIQUE_ID);
if (uniqueId == null) {
uniqueId = ((NodeImpl) getNode()).getUniqueId();
}
((WorkflowProcessInstanceImpl) getProcessInstance()).addCompletedNodeId(uniqueId);
if (exceptionScopeInstance != null) {
if (!exceptionHandled) {
handleException(faultName, exceptionScopeInstance);
}
boolean hidden = false;
if (getNode().getMetaData().get("hidden") != null) {
hidden = true;
}
if (!hidden) {
InternalProcessRuntime runtime = getProcessInstance().getProcessRuntime();
runtime.getProcessEventSupport().fireBeforeNodeLeft(this, runtime);
}
((NodeInstanceContainer) getNodeInstanceContainer()).nodeInstanceCompleted(this, null);
if (!hidden) {
InternalProcessRuntime runtime = getProcessInstance().getProcessRuntime();
runtime.getProcessEventSupport().fireAfterNodeLeft(this, runtime);
}
} else {
((ProcessInstance) getProcessInstance()).setState(ProcessInstance.STATE_ABORTED, faultName, getFaultData());
}
}
use of io.automatiko.engine.workflow.process.instance.NodeInstanceContainer in project automatiko-engine by automatiko-io.
the class AbstractProcessInstance method triggerNode.
@Override
public void triggerNode(String nodeId) {
lock();
WorkflowProcessInstanceImpl wfpi = ((WorkflowProcessInstanceImpl) processInstance());
ExecutableProcess rfp = ((ExecutableProcess) wfpi.getProcess());
Node node = rfp.getNodesRecursively().stream().filter(ni -> nodeId.equals(ni.getMetaData().get("UniqueId"))).findFirst().orElseThrow(() -> new NodeNotFoundException(this.id, nodeId));
Node parentNode = rfp.getParentNode(node.getId());
NodeInstanceContainer nodeInstanceContainerNode = parentNode == null ? wfpi : ((NodeInstanceContainer) wfpi.getNodeInstance(parentNode));
if (nodeInstanceContainerNode.getNodeInstances().isEmpty() && nodeInstanceContainerNode instanceof CompositeContextNodeInstance) {
((CompositeContextNodeInstance) nodeInstanceContainerNode).internalTriggerOnlyParent(null, nodeId);
}
nodeInstanceContainerNode.getNodeInstance(node).trigger(null, io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE);
}
use of io.automatiko.engine.workflow.process.instance.NodeInstanceContainer in project automatiko-engine by automatiko-io.
the class WorkflowReuseContextInstanceFactory method getContextInstance.
public ContextInstance getContextInstance(Context context, ContextInstanceContainer contextInstanceContainer, ProcessInstance processInstance) {
ContextInstance result = contextInstanceContainer.getContextInstance(context.getType(), context.getId());
if (result != null) {
return result;
}
try {
AbstractContextInstance contextInstance = (AbstractContextInstance) cls.newInstance();
contextInstance.setContextId(context.getId());
contextInstance.setContextInstanceContainer(contextInstanceContainer);
contextInstance.setProcessInstance(processInstance);
contextInstanceContainer.addContextInstance(context.getType(), contextInstance);
NodeInstanceContainer nodeInstanceContainer = null;
if (contextInstanceContainer instanceof NodeInstanceContainer) {
nodeInstanceContainer = (NodeInstanceContainer) contextInstanceContainer;
} else if (contextInstanceContainer instanceof ContextInstance) {
ContextInstanceContainer parent = ((ContextInstance) contextInstanceContainer).getContextInstanceContainer();
while (parent != null) {
if (parent instanceof NodeInstanceContainer) {
nodeInstanceContainer = (NodeInstanceContainer) parent;
} else if (contextInstanceContainer instanceof ContextInstance) {
parent = ((ContextInstance) contextInstanceContainer).getContextInstanceContainer();
} else {
parent = null;
}
}
}
((WorkflowContextInstance) contextInstance).setNodeInstanceContainer(nodeInstanceContainer);
return contextInstance;
} catch (Exception e) {
throw new RuntimeException("Unable to instantiate context '" + this.cls.getName() + "': " + e.getMessage());
}
}
use of io.automatiko.engine.workflow.process.instance.NodeInstanceContainer in project automatiko-engine by automatiko-io.
the class CompensationEventListener method createNodeInstanceContainers.
private Stack<NodeInstance> createNodeInstanceContainers(Node toCompensateNode, boolean generalCompensation) {
Stack<NodeContainer> nestedNodes = new Stack<NodeContainer>();
Stack<NodeInstance> generatedInstances = new Stack<NodeInstance>();
NodeContainer parentContainer = toCompensateNode.getParentContainer();
while (!(parentContainer instanceof ExecutableProcess)) {
nestedNodes.add(parentContainer);
parentContainer = ((Node) parentContainer).getParentContainer();
}
NodeInstanceContainer parentInstance;
if (nestedNodes.isEmpty()) {
// nestedNodes is empty
parentInstance = (NodeInstanceContainer) getProcessInstance();
} else {
parentInstance = (NodeInstanceContainer) ((WorkflowProcessInstanceImpl) getProcessInstance()).getNodeInstance((Node) nestedNodes.pop());
generatedInstances.add((NodeInstance) parentInstance);
}
NodeInstanceContainer childInstance;
while (!nestedNodes.isEmpty()) {
// generate
childInstance = (NodeInstanceContainer) parentInstance.getNodeInstance((Node) nestedNodes.pop());
assert childInstance instanceof CompositeNodeInstance : "A node with child nodes should end up creating a CompositeNodeInstance type.";
// track and modify
generatedInstances.add((NodeInstance) childInstance);
// loop
parentInstance = childInstance;
}
if (generalCompensation) {
childInstance = (NodeInstanceContainer) parentInstance.getNodeInstance(toCompensateNode);
generatedInstances.add((NodeInstance) childInstance);
}
return generatedInstances;
}
Aggregations