use of io.automatiko.engine.workflow.base.instance.InternalProcessRuntime in project automatiko-engine by automatiko-io.
the class NodeInstanceImpl method retry.
public void retry() {
boolean hidden = false;
if (getNode().getMetaData().get(HIDDEN) != null) {
hidden = true;
}
InternalProcessRuntime runtime = getProcessInstance().getProcessRuntime();
try {
internalChangeState(NodeInstanceState.Active);
internalTrigger(this, io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE);
Collection<Connection> outgoing = getNode().getOutgoingConnections(io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE);
for (Connection conn : outgoing) {
if (conn.getTo().getId() == getNodeId()) {
this.metaData.put(OUTGOING_CONNECTION, conn.getMetaData().get(UNIQUE_ID));
break;
}
}
if (!hidden) {
runtime.getProcessEventSupport().fireAfterNodeLeft(this, runtime);
}
} 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;
}
}
use of io.automatiko.engine.workflow.base.instance.InternalProcessRuntime in project automatiko-engine by automatiko-io.
the class NodeInstanceImpl method continueToNextNode.
protected void continueToNextNode(String type, Node node) {
List<Connection> connections = null;
if (node != null) {
if ("true".equals(System.getProperty("jbpm.enable.multi.con")) && ((NodeImpl) node).getConstraints().size() > 0) {
int priority;
connections = ((NodeImpl) node).getDefaultOutgoingConnections();
boolean found = false;
List<NodeInstanceTrigger> nodeInstances = new ArrayList<>();
List<Connection> outgoingCopy = new ArrayList<>(connections);
while (!outgoingCopy.isEmpty()) {
priority = Integer.MAX_VALUE;
Connection selectedConnection = null;
ConstraintEvaluator selectedConstraint = null;
for (final Connection connection : outgoingCopy) {
ConstraintEvaluator constraint = (ConstraintEvaluator) ((NodeImpl) node).getConstraint(connection);
if (constraint != null && constraint.getPriority() < priority && !constraint.isDefault()) {
priority = constraint.getPriority();
selectedConnection = connection;
selectedConstraint = constraint;
}
}
if (selectedConstraint == null) {
break;
}
if (selectedConstraint.evaluate(this, selectedConnection, selectedConstraint)) {
nodeInstances.add(new NodeInstanceTrigger(followConnection(selectedConnection), selectedConnection.getToType()));
found = true;
}
outgoingCopy.remove(selectedConnection);
}
for (NodeInstanceTrigger nodeInstance : nodeInstances) {
// stop if this process instance has been aborted / completed
if (((io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) getNodeInstanceContainer()).getState() != STATE_ACTIVE) {
return;
}
triggerNodeInstance(nodeInstance.getNodeInstance(), nodeInstance.getToType());
}
if (!found) {
for (final Connection connection : connections) {
ConstraintEvaluator constraint = (ConstraintEvaluator) ((NodeImpl) node).getConstraint(connection);
if (constraint.isDefault()) {
triggerConnection(connection);
found = true;
break;
}
}
}
if (!found) {
throw new IllegalArgumentException("Uncontrolled flow node could not find at least one valid outgoing connection " + getNode().getName());
}
return;
} else {
connections = node.getOutgoingConnections(type);
}
}
if (connections == null || connections.isEmpty()) {
boolean hidden = false;
Node currentNode = getNode();
if (currentNode != null && currentNode.getMetaData().get(HIDDEN) != null) {
hidden = true;
}
InternalProcessRuntime runtime = getProcessInstance().getProcessRuntime();
if (!hidden) {
runtime.getProcessEventSupport().fireBeforeNodeLeft(this, runtime);
}
// notify container
((io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) getNodeInstanceContainer()).nodeInstanceCompleted(this, type);
if (!hidden) {
runtime.getProcessEventSupport().fireAfterNodeLeft(this, runtime);
}
} else {
Map<io.automatiko.engine.workflow.process.instance.NodeInstance, String> nodeInstances = new HashMap<>();
for (Connection connection : connections) {
nodeInstances.put(followConnection(connection), connection.getToType());
}
for (Map.Entry<io.automatiko.engine.workflow.process.instance.NodeInstance, String> nodeInstance : nodeInstances.entrySet()) {
// stop if this process instance has been aborted / completed
int state = ((io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) getNodeInstanceContainer()).getState();
if (state == STATE_COMPLETED || state == STATE_ABORTED) {
return;
}
try {
triggerNodeInstance(nodeInstance.getKey(), nodeInstance.getValue());
} catch (Exception e) {
logger.warn("Error caught at executing node instance " + nodeInstance.getKey(), e);
}
}
}
}
use of io.automatiko.engine.workflow.base.instance.InternalProcessRuntime in project automatiko-engine by automatiko-io.
the class DmnDecisionInProcessTest method createProcessRuntime.
protected InternalProcessRuntime createProcessRuntime(Process... process) {
Map<String, Process> mappedProcesses = Stream.of(process).collect(Collectors.toMap(Process::getId, p -> p));
InternalProcessRuntime processRuntime = new ProcessRuntimeImpl(mappedProcesses);
return processRuntime;
}
use of io.automatiko.engine.workflow.base.instance.InternalProcessRuntime in project automatiko-engine by automatiko-io.
the class VariableScopeInstance method setVariable.
@SuppressWarnings("unchecked")
public void setVariable(NodeInstance nodeInstance, String name, Object value) {
if (name == null) {
throw new IllegalArgumentException("The name of a variable may not be null!");
}
Variable var = getVariableScope().findVariable(name);
if (var != null) {
name = var.getName();
}
Object oldValue = getVariable(name);
if (oldValue == null) {
if (value == null) {
return;
}
}
// check if variable that is being set is readonly and has already been set
if (oldValue != null && getVariableScope().isReadOnly(name)) {
throw new VariableViolationException(getProcessInstance().getId(), name, "Variable '" + name + "' is already set and is marked as read only");
}
// in case variable is marked as notnull (via tag) then null values should be ignored
if (value == null && getVariableScope().isNullable(name)) {
return;
}
// in case variable is versioned store the old value into versioned variable by variable name
if (var != null && var.hasTag(Variable.VERSIONED_TAG)) {
Map<String, List<Object>> versions = (Map<String, List<Object>>) variables.computeIfAbsent(VariableScope.VERSIONED_VARIABLES, key -> new ConcurrentHashMap<>());
List<Object> varVersions = versions.computeIfAbsent(name, k -> new ArrayList<>());
int versionLimit = Integer.parseInt(var.getMetaData().getOrDefault(Variable.VAR_VERSIONS_LIMIT, "10").toString());
if (oldValue != null) {
varVersions.add(oldValue);
// and remove the oldest if exceeding
if (varVersions.size() > versionLimit) {
varVersions.remove(0);
}
}
}
if (getProcessInstance().getProcessRuntime().getVariableInitializer() != null) {
for (VariableAugmentor augmentor : getProcessInstance().getProcessRuntime().getVariableInitializer().augmentors()) {
if (augmentor.accept(var, value)) {
// run any of the available augmentors on the value
if (oldValue != null) {
value = augmentor.augmentOnUpdate(getProcessInstance().getProcess().getId(), getProcessInstance().getProcess().getVersion(), getProcessInstance().getId(), var, value);
} else if (value == null) {
augmentor.augmentOnDelete(getProcessInstance().getProcess().getId(), getProcessInstance().getProcess().getVersion(), getProcessInstance().getId(), var, oldValue);
} else {
value = augmentor.augmentOnCreate(getProcessInstance().getProcess().getId(), getProcessInstance().getProcess().getVersion(), getProcessInstance().getId(), var, value);
}
}
}
}
ProcessInstance processInstance = getProcessInstance();
if (nodeInstance != null) {
processInstance = nodeInstance.getProcessInstance();
}
ProcessEventSupport processEventSupport = ((InternalProcessRuntime) getProcessInstance().getProcessRuntime()).getProcessEventSupport();
processEventSupport.fireBeforeVariableChanged((variableIdPrefix == null ? "" : variableIdPrefix + ":") + name, (variableInstanceIdPrefix == null ? "" : variableInstanceIdPrefix + ":") + name, oldValue, value, getVariableScope().tags(name), processInstance, nodeInstance, getProcessInstance().getProcessRuntime());
internalSetVariable(name, value);
processEventSupport.fireAfterVariableChanged((variableIdPrefix == null ? "" : variableIdPrefix + ":") + name, (variableInstanceIdPrefix == null ? "" : variableInstanceIdPrefix + ":") + name, oldValue, value, getVariableScope().tags(name), processInstance, nodeInstance, getProcessInstance().getProcessRuntime());
processInstance.signalEvent("variableChanged", value);
}
Aggregations