Search in sources :

Example 1 with ScriptVariableEvaluationTraceType

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;
}
Also used : ScriptVariableEvaluationTraceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ScriptVariableEvaluationTraceType) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) ValueVariableModeType(com.evolveum.midpoint.xml.ns._public.common.common_3.ValueVariableModeType) FunctionLibrary(com.evolveum.midpoint.model.common.expression.functions.FunctionLibrary) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) TypedValue(com.evolveum.midpoint.schema.expression.TypedValue)

Aggregations

FunctionLibrary (com.evolveum.midpoint.model.common.expression.functions.FunctionLibrary)1 TypedValue (com.evolveum.midpoint.schema.expression.TypedValue)1 VariablesMap (com.evolveum.midpoint.schema.expression.VariablesMap)1 ScriptVariableEvaluationTraceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ScriptVariableEvaluationTraceType)1 ValueVariableModeType (com.evolveum.midpoint.xml.ns._public.common.common_3.ValueVariableModeType)1 HashMap (java.util.HashMap)1 QName (javax.xml.namespace.QName)1