Search in sources :

Example 16 with ExpressionVariables

use of com.evolveum.midpoint.repo.common.expression.ExpressionVariables in project midpoint by Evolveum.

the class Utils method getDefaultExpressionVariables.

public static ExpressionVariables getDefaultExpressionVariables(@NotNull LensContext<?> context, @Nullable LensProjectionContext projCtx) throws SchemaException {
    ExpressionVariables variables = new ExpressionVariables();
    if (context.getFocusContext() != null) {
        variables.addVariableDefinition(ExpressionConstants.VAR_FOCUS, context.getFocusContext().getObjectDeltaObject());
        variables.addVariableDefinition(ExpressionConstants.VAR_USER, context.getFocusContext().getObjectDeltaObject());
    }
    if (projCtx != null) {
        variables.addVariableDefinition(ExpressionConstants.VAR_PROJECTION, projCtx.getObjectDeltaObject());
        variables.addVariableDefinition(ExpressionConstants.VAR_SHADOW, projCtx.getObjectDeltaObject());
        variables.addVariableDefinition(ExpressionConstants.VAR_ACCOUNT, projCtx.getObjectDeltaObject());
        variables.addVariableDefinition(ExpressionConstants.VAR_RESOURCE, projCtx.getResource());
    }
    variables.addVariableDefinition(ExpressionConstants.VAR_OPERATION, projCtx.getOperation().getValue());
    variables.addVariableDefinition(ExpressionConstants.VAR_ITERATION, LensUtil.getIterationVariableValue(projCtx));
    variables.addVariableDefinition(ExpressionConstants.VAR_ITERATION_TOKEN, LensUtil.getIterationTokenVariableValue(projCtx));
    variables.addVariableDefinition(ExpressionConstants.VAR_CONFIGURATION, context.getSystemConfiguration());
    return variables;
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables)

Example 17 with ExpressionVariables

use of com.evolveum.midpoint.repo.common.expression.ExpressionVariables in project midpoint by Evolveum.

the class SynchronizationServiceImpl method evaluateSynchronizationPolicyCondition.

private Boolean evaluateSynchronizationPolicyCondition(ObjectSynchronizationType synchronizationPolicy, PrismObject<? extends ShadowType> currentShadow, PrismObject<ResourceType> resource, PrismObject<SystemConfigurationType> configuration, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
    if (synchronizationPolicy.getCondition() == null) {
        return null;
    }
    ExpressionType conditionExpressionType = synchronizationPolicy.getCondition();
    String desc = "condition in object synchronization " + synchronizationPolicy.getName();
    ExpressionVariables variables = Utils.getDefaultExpressionVariables(null, currentShadow, null, resource, configuration, null);
    try {
        ModelExpressionThreadLocalHolder.pushExpressionEnvironment(new ExpressionEnvironment<>(task, result));
        PrismPropertyValue<Boolean> evaluateCondition = ExpressionUtil.evaluateCondition(variables, conditionExpressionType, expressionFactory, desc, task, result);
        return evaluateCondition.getValue();
    } finally {
        ModelExpressionThreadLocalHolder.popExpressionEnvironment();
    }
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType)

Example 18 with ExpressionVariables

use of com.evolveum.midpoint.repo.common.expression.ExpressionVariables in project midpoint by Evolveum.

the class AssignmentEvaluator method resolveTargetsFromFilter.

@NotNull
private <O extends ObjectType> List<PrismObject<O>> resolveTargetsFromFilter(Class<O> targetClass, SearchFilterType filter, AssignmentPathSegmentImpl segment, EvaluationContext ctx) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
    ModelExpressionThreadLocalHolder.pushExpressionEnvironment(new ExpressionEnvironment<>(lensContext, null, ctx.task, ctx.result));
    try {
        PrismObject<SystemConfigurationType> systemConfiguration = systemObjectCache.getSystemConfiguration(ctx.result);
        ExpressionVariables variables = Utils.getDefaultExpressionVariables(segment.source, null, null, systemConfiguration.asObjectable());
        variables.addVariableDefinition(ExpressionConstants.VAR_SOURCE, segment.getOrderOneObject());
        AssignmentPathVariables assignmentPathVariables = LensUtil.computeAssignmentPathVariables(ctx.assignmentPath);
        if (assignmentPathVariables != null) {
            Utils.addAssignmentPathVariables(assignmentPathVariables, variables);
        }
        ObjectFilter origFilter = QueryConvertor.parseFilter(filter, targetClass, prismContext);
        ObjectFilter evaluatedFilter = ExpressionUtil.evaluateFilterExpressions(origFilter, variables, getMappingFactory().getExpressionFactory(), prismContext, " evaluating resource filter expression ", ctx.task, ctx.result);
        if (evaluatedFilter == null) {
            throw new SchemaException("The OID is null and filter could not be evaluated in assignment targetRef in " + segment.source);
        }
        return repository.searchObjects(targetClass, ObjectQuery.createObjectQuery(evaluatedFilter), null, ctx.result);
    // we don't check for no targets here; as we don't care for referential integrity
    } finally {
        ModelExpressionThreadLocalHolder.popExpressionEnvironment();
    }
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with ExpressionVariables

use of com.evolveum.midpoint.repo.common.expression.ExpressionVariables in project midpoint by Evolveum.

the class LensUtil method addAssignmentPathVariables.

public static <V extends PrismValue, D extends ItemDefinition> Mapping.Builder<V, D> addAssignmentPathVariables(Mapping.Builder<V, D> builder, AssignmentPathVariables assignmentPathVariables) {
    ExpressionVariables expressionVariables = new ExpressionVariables();
    Utils.addAssignmentPathVariables(assignmentPathVariables, expressionVariables);
    return builder.addVariableDefinitions(expressionVariables.getMap());
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables)

Example 20 with ExpressionVariables

use of com.evolveum.midpoint.repo.common.expression.ExpressionVariables in project midpoint by Evolveum.

the class Clockwork method evaluateScriptingHook.

private void evaluateScriptingHook(LensContext context, HookType hookType, ScriptExpressionEvaluatorType scriptExpressionEvaluatorType, String shortDesc, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
    LOGGER.trace("Evaluating {}", shortDesc);
    // TODO: it would be nice to cache this
    // null output definition: this script has no output
    ScriptExpression scriptExpression = scriptExpressionFactory.createScriptExpression(scriptExpressionEvaluatorType, null, shortDesc);
    ExpressionVariables variables = new ExpressionVariables();
    variables.addVariableDefinition(ExpressionConstants.VAR_PRISM_CONTEXT, prismContext);
    variables.addVariableDefinition(ExpressionConstants.VAR_MODEL_CONTEXT, context);
    LensFocusContext focusContext = context.getFocusContext();
    PrismObject focus = null;
    if (focusContext != null) {
        focus = focusContext.getObjectAny();
    }
    variables.addVariableDefinition(ExpressionConstants.VAR_FOCUS, focus);
    Utils.evaluateScript(scriptExpression, context, variables, false, shortDesc, task, result);
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) ScriptExpression(com.evolveum.midpoint.model.common.expression.script.ScriptExpression)

Aggregations

ExpressionVariables (com.evolveum.midpoint.repo.common.expression.ExpressionVariables)65 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)17 QName (javax.xml.namespace.QName)15 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)10 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)10 Test (org.testng.annotations.Test)10 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)9 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)9 ExpressionEvaluationContext (com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext)9 Task (com.evolveum.midpoint.task.api.Task)8 ArrayList (java.util.ArrayList)8 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)7 PrismObject (com.evolveum.midpoint.prism.PrismObject)6 PrismPropertyDefinitionImpl (com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl)6 ExpressionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType)6 PrismContext (com.evolveum.midpoint.prism.PrismContext)5 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)5 SystemException (com.evolveum.midpoint.util.exception.SystemException)5 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)5 ScriptExpression (com.evolveum.midpoint.model.common.expression.script.ScriptExpression)4