use of io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance in project automatiko-engine by automatiko-io.
the class StateBasedNodeInstance method mapDynamicOutputData.
protected void mapDynamicOutputData(Map<String, Object> results) {
if (results != null && !results.isEmpty()) {
VariableScope variableScope = (VariableScope) ((ContextContainer) getProcessInstance().getProcess()).getDefaultContext(VariableScope.VARIABLE_SCOPE);
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) getProcessInstance().getContextInstance(VariableScope.VARIABLE_SCOPE);
for (Entry<String, Object> result : results.entrySet()) {
String variableName = result.getKey();
Variable variable = variableScope.findVariable(variableName);
if (variable != null) {
variableScopeInstance.getVariableScope().validateVariable(getProcessInstance().getProcessName(), variableName, result.getValue());
variableScopeInstance.setVariable(this, variableName, result.getValue());
}
}
}
}
use of io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance in project automatiko-engine by automatiko-io.
the class JoinInstance 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("An ActionNode only accepts default incoming connections!");
}
triggerTime = new Date();
final Join join = getJoin();
switch(join.getType()) {
case Join.TYPE_XOR:
triggerCompleted();
break;
case Join.TYPE_AND:
Integer count = (Integer) this.triggers.get(from.getNodeId());
if (count == null) {
this.triggers.put(from.getNodeId(), 1);
} else {
this.triggers.put(from.getNodeId(), count.intValue() + 1);
}
if (checkAllActivated()) {
decreaseAllTriggers();
triggerCompleted();
}
break;
case Join.TYPE_DISCRIMINATOR:
boolean triggerCompleted = triggers.isEmpty();
triggers.put(from.getNodeId(), new Integer(1));
if (checkAllActivated()) {
resetAllTriggers();
}
if (triggerCompleted) {
triggerCompleted();
}
break;
case Join.TYPE_N_OF_M:
count = (Integer) this.triggers.get(from.getNodeId());
if (count == null) {
this.triggers.put(from.getNodeId(), 1);
} else {
this.triggers.put(from.getNodeId(), count.intValue() + 1);
}
int counter = 0;
for (final Connection connection : getJoin().getDefaultIncomingConnections()) {
if (this.triggers.get(connection.getFrom().getId()) != null) {
counter++;
}
}
String n = join.getN();
Integer number = null;
if (n.startsWith("#{") && n.endsWith("}")) {
n = n.substring(2, n.length() - 1);
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VariableScope.VARIABLE_SCOPE, n);
if (variableScopeInstance == null) {
throw new IllegalArgumentException("Could not find variable " + n + " when executing join.");
}
Object value = variableScopeInstance.getVariable(n);
if (value instanceof Number) {
number = ((Number) value).intValue();
} else {
throw new IllegalArgumentException("Variable " + n + " did not return a number when executing join: " + value);
}
} else {
number = Integer.parseInt(n);
}
if (counter >= number) {
resetAllTriggers();
NodeInstanceContainer nodeInstanceContainer = (NodeInstanceContainer) getNodeInstanceContainer();
cancelRemainingDirectFlows(nodeInstanceContainer, getJoin());
triggerCompleted();
}
break;
case Join.TYPE_OR:
NodeInstanceContainer nodeInstanceContainer = (NodeInstanceContainer) getNodeInstanceContainer();
boolean activePathExists = existsActiveDirectFlow(nodeInstanceContainer, getJoin());
if (!activePathExists) {
triggerCompleted();
}
break;
default:
throw new IllegalArgumentException("Illegal join type " + join.getType());
}
}
use of io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance in project automatiko-engine by automatiko-io.
the class RuleSetNodeInstance method evaluateParameters.
@SuppressWarnings({ "unchecked", "rawtypes" })
protected Map<String, Object> evaluateParameters(RuleSetNode ruleSetNode) {
Map<String, Object> replacements = new HashMap<>();
for (Iterator<DataAssociation> iterator = ruleSetNode.getInAssociations().iterator(); iterator.hasNext(); ) {
DataAssociation association = iterator.next();
if (association.getTransformation() != null) {
Transformation transformation = association.getTransformation();
DataTransformer transformer = DataTransformerRegistry.get().find(transformation.getLanguage());
if (transformer != null) {
Object parameterValue = transformer.transform(transformation.getCompiledExpression(), getSourceParameters(association));
replacements.put(association.getTarget(), parameterValue);
}
} else if (association.getAssignments() == null || association.getAssignments().isEmpty()) {
Object parameterValue = null;
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VariableScope.VARIABLE_SCOPE, association.getSources().get(0));
if (variableScopeInstance != null) {
parameterValue = variableScopeInstance.getVariable(association.getSources().get(0));
} else {
try {
ExpressionEvaluator evaluator = (ExpressionEvaluator) ((WorkflowProcess) getProcessInstance().getProcess()).getDefaultContext(ExpressionEvaluator.EXPRESSION_EVALUATOR);
parameterValue = evaluator.evaluate(association.getSources().get(0), new NodeInstanceResolverFactory(this));
} catch (Throwable t) {
logger.error("Could not find variable scope for variable {}", association.getSources().get(0));
logger.error("when trying to execute RuleSetNode {}", ruleSetNode.getName());
logger.error("Continuing without setting parameter.");
}
}
replacements.put(association.getTarget(), parameterValue);
}
}
for (Map.Entry<String, Object> entry : ruleSetNode.getParameters().entrySet()) {
if (entry.getValue() instanceof String) {
Object value = resolveVariable(entry.getValue());
replacements.put(entry.getKey(), value);
}
}
return replacements;
}
use of io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance in project automatiko-engine by automatiko-io.
the class RuleSetNodeInstance method resolveVariable.
@SuppressWarnings({ "unchecked", "rawtypes" })
private Object resolveVariable(Object s) {
if (s instanceof String) {
Matcher matcher = PatternConstants.PARAMETER_MATCHER.matcher((String) s);
while (matcher.find()) {
String paramName = matcher.group(1);
String defaultValue = null;
if (paramName.contains(":")) {
String[] items = paramName.split(":");
paramName = items[0];
defaultValue = items[1];
}
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VariableScope.VARIABLE_SCOPE, paramName);
if (variableScopeInstance != null) {
Object variableValue = variableScopeInstance.getVariable(paramName);
if (variableValue != null) {
return variableValue;
} else {
return defaultValue;
}
} else {
try {
ExpressionEvaluator evaluator = (ExpressionEvaluator) ((WorkflowProcess) getProcessInstance().getProcess()).getDefaultContext(ExpressionEvaluator.EXPRESSION_EVALUATOR);
Object variableValue = evaluator.evaluate(paramName, new NodeInstanceResolverFactory(this));
if (variableValue != null) {
return variableValue;
} else {
return defaultValue;
}
} catch (Throwable t) {
logger.error("Could not find variable scope for variable {}", paramName);
}
}
}
}
return s;
}
use of io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance in project automatiko-engine by automatiko-io.
the class EventNodeInstance method resolveVariable.
private String resolveVariable(String s) {
if (s == null) {
return null;
}
Map<String, String> replacements = new HashMap<String, String>();
Matcher matcher = PatternConstants.PARAMETER_MATCHER.matcher(s);
while (matcher.find()) {
String paramName = matcher.group(1);
String replacementKey = paramName;
String defaultValue = "";
if (paramName.contains(":")) {
String[] items = paramName.split(":");
paramName = items[0];
defaultValue = items[1];
}
if (replacements.get(replacementKey) == null) {
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(VariableScope.VARIABLE_SCOPE, paramName);
if (variableScopeInstance != null) {
Object variableValue = variableScopeInstance.getVariable(paramName);
String variableValueString = variableValue == null ? defaultValue : variableValue.toString();
replacements.put(replacementKey, variableValueString);
}
}
}
for (Map.Entry<String, String> replacement : replacements.entrySet()) {
s = s.replace("#{" + replacement.getKey() + "}", replacement.getValue());
}
return s;
}
Aggregations