use of com.evolveum.midpoint.xml.ns._public.common.common_3.ScriptVariableEvaluationTraceType in project midpoint by Evolveum.
the class AbstractScriptEvaluator method prepareScriptVariablesValueMap.
/**
* Returns simple variable map: name -> value.
*/
protected Map<String, Object> prepareScriptVariablesValueMap(ScriptExpressionEvaluationContext context) throws ExpressionSyntaxException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
Map<String, Object> scriptVariableMap = new HashMap<>();
// Functions
if (context.getFunctions() != null) {
for (FunctionLibrary funcLib : context.getFunctions()) {
scriptVariableMap.put(funcLib.getVariableName(), funcLib.getGenericFunctions());
}
}
// Variables
VariablesMap variables = context.getVariables();
if (variables != null) {
for (Entry<String, TypedValue> variableEntry : variables.entrySet()) {
if (variableEntry.getKey() == null) {
// This is the "root" node. We have no use for it in script expressions, just skip it
continue;
}
String variableName = variableEntry.getKey();
ValueVariableModeType valueVariableMode = ObjectUtils.defaultIfNull(context.getExpressionType().getValueVariableMode(), ValueVariableModeType.REAL_VALUE);
// noinspection rawtypes
TypedValue variableTypedValue = ExpressionUtil.convertVariableValue(variableEntry.getValue(), variableName, context.getObjectResolver(), context.getContextDescription(), context.getExpressionType().getObjectVariableMode(), valueVariableMode, prismContext, context.getTask(), context.getResult());
scriptVariableMap.put(variableName, variableTypedValue.getValue());
if (context.getTrace() != null && !variables.isAlias(variableName)) {
ScriptVariableEvaluationTraceType variableTrace = new ScriptVariableEvaluationTraceType(prismContext);
variableTrace.setName(new QName(variableName));
Object clonedValue = cloneIfPossible(variableTypedValue.getValue());
variableTrace.getValue().addAll(TraceUtil.toAnyValueTypeList(clonedValue, prismContext));
variables.getAliases(variableName).forEach(alias -> variableTrace.getAlias().add(new QName(alias)));
context.getTrace().getVariable().add(variableTrace);
}
}
}
putIfMissing(scriptVariableMap, ExpressionConstants.VAR_PRISM_CONTEXT, prismContext);
putIfMissing(scriptVariableMap, ExpressionConstants.VAR_LOCALIZATION_SERVICE, localizationService);
return scriptVariableMap;
}
Aggregations