use of io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance in project automatiko-engine by automatiko-io.
the class WorkflowProcessInstanceImpl method getVariables.
@Override
public Map<String, Object> getVariables() {
// be null and the associated working memory is no longer accessible)
if (getProcessRuntime() == null) {
List<ContextInstance> variableScopeInstances = getContextInstances(VariableScope.VARIABLE_SCOPE);
if (variableScopeInstances == null) {
return Collections.emptyMap();
}
Map<String, Object> result = new HashMap<>();
for (ContextInstance contextInstance : variableScopeInstances) {
Map<String, Object> variables = ((VariableScopeInstance) contextInstance).getVariables();
result.putAll(variables);
}
return result;
}
// else retrieve the variable scope
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) getContextInstance(VariableScope.VARIABLE_SCOPE);
if (variableScopeInstance == null) {
return null;
}
return variableScopeInstance.getVariables();
}
use of io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance in project automatiko-engine by automatiko-io.
the class CompositeContextNodeInstance method processInputMappings.
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void processInputMappings() {
VariableScopeInstance compositeVariableScopeInstance = (VariableScopeInstance) getContextInstance(VARIABLE_SCOPE);
for (DataAssociation association : getCompositeContextNode().getInAssociations()) {
if (association.getTransformation() != null) {
Transformation transformation = association.getTransformation();
DataTransformer transformer = DataTransformerRegistry.get().find(transformation.getLanguage());
if (transformer != null) {
Object parameterValue = transformer.transform(transformation.getCompiledExpression(), getProcessInstance().getVariables());
if (parameterValue != null) {
compositeVariableScopeInstance.setVariable(association.getTarget(), parameterValue);
}
}
} else if (association.getAssignments() == null || association.getAssignments().isEmpty()) {
Object parameterValue = null;
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(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("Continuing without setting parameter.");
}
}
if (parameterValue != null) {
compositeVariableScopeInstance.setVariable(association.getTarget(), parameterValue);
}
} else {
association.getAssignments().stream().forEach(assignment -> handleAssignment(assignment, compositeVariableScopeInstance));
}
}
}
use of io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance in project automatiko-engine by automatiko-io.
the class CompositeContextNodeInstance method triggerCompleted.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void triggerCompleted(String outType) {
VariableScopeInstance compositeVariableScopeInstance = (VariableScopeInstance) getContextInstance(VARIABLE_SCOPE);
for (DataAssociation association : getCompositeContextNode().getOutAssociations()) {
if (association.getTransformation() != null) {
Transformation transformation = association.getTransformation();
DataTransformer transformer = DataTransformerRegistry.get().find(transformation.getLanguage());
if (transformer != null) {
Object parameterValue = transformer.transform(transformation.getCompiledExpression(), compositeVariableScopeInstance.getVariables());
if (parameterValue != null) {
getProcessInstance().setVariable(association.getTarget(), parameterValue);
}
}
} else if (association.getAssignments() == null || association.getAssignments().isEmpty()) {
Object parameterValue = null;
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) resolveContextInstance(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("Continuing without setting parameter.");
}
}
if (parameterValue != null) {
getProcessInstance().setVariable(association.getTarget(), parameterValue);
}
} else {
association.getAssignments().stream().forEach(assignment -> handleAssignment(assignment, compositeVariableScopeInstance));
}
}
super.triggerCompleted(outType);
}
use of io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance in project automatiko-engine by automatiko-io.
the class WorkflowProcessInstanceImpl method setVariable.
@Override
public void setVariable(String name, Object value) {
VariableScope variableScope = (VariableScope) ((ContextContainer) getProcess()).getDefaultContext(VariableScope.VARIABLE_SCOPE);
VariableScopeInstance variableScopeInstance = (VariableScopeInstance) getContextInstance(VariableScope.VARIABLE_SCOPE);
if (variableScopeInstance == null) {
throw new IllegalArgumentException("No variable scope found.");
}
variableScope.validateVariable(getProcessName(), name, value);
variableScopeInstance.setVariable(name, value);
}
use of io.automatiko.engine.workflow.base.instance.context.variable.VariableScopeInstance in project automatiko-engine by automatiko-io.
the class NodeInstanceImpl method setVariable.
public void setVariable(String variableName, Object value) {
VariableScopeInstance variableScope = (VariableScopeInstance) resolveContextInstance(VariableScope.VARIABLE_SCOPE, variableName);
if (variableScope == null) {
variableScope = (VariableScopeInstance) getProcessInstance().getContextInstance(VariableScope.VARIABLE_SCOPE);
if (variableScope.getVariableScope().findVariable(variableName) == null) {
variableScope = null;
}
}
if (variableScope == null) {
logger.error("Could not find variable {}", variableName);
logger.error("Using process-level scope");
variableScope = (VariableScopeInstance) getProcessInstance().getContextInstance(VariableScope.VARIABLE_SCOPE);
}
variableScope.setVariable(this, variableName, value);
}
Aggregations