Search in sources :

Example 21 with VariablesMap

use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.

the class ConstraintReferenceMatcher method filterMatches.

private boolean filterMatches(PrismObject<?> object, String contextDescription) throws SchemaException {
    assert targetReference != null;
    QName typeNameLookingFor = MoreObjects.firstNonNull(targetReference.getType(), ObjectType.COMPLEX_TYPE);
    PrismObjectDefinition<?> objectDefLookingFor = PrismContext.get().getSchemaRegistry().findObjectDefinitionByType(typeNameLookingFor);
    if (!object.canRepresent(objectDefLookingFor.getCompileTimeClass())) {
        return false;
    }
    SearchFilterType filterBean = MiscUtil.requireNonNull(targetReference.getFilter(), () -> "No filter in " + contextDescription);
    if (filter == null) {
        filter = PrismContext.get().getQueryConverter().parseFilter(filterBean, objectDefLookingFor);
        VariablesMap variables = new VariablesMap();
        variables.put(ExpressionConstants.VAR_POLICY_RULE, evalContext.policyRule, EvaluatedPolicyRule.class);
        ModelExpressionThreadLocalHolder.pushExpressionEnvironment(new ExpressionEnvironment<>(evalContext.lensContext, null, evalContext.task, operationResult));
        try {
            filter = ExpressionUtil.evaluateFilterExpressions(filter, variables, MiscSchemaUtil.getExpressionProfile(), expressionFactory, expressionFactory.getPrismContext(), contextDescription, evalContext.task, operationResult);
        } catch (ObjectNotFoundException | SecurityViolationException | ConfigurationException | CommunicationException | ExpressionEvaluationException e) {
            throw new SystemException("Error occurred during expression evaluation", e);
        } finally {
            ModelExpressionThreadLocalHolder.popExpressionEnvironment();
        }
    }
    return filter.match(object.getValue(), SchemaService.get().matchingRuleRegistry());
}
Also used : SearchFilterType(com.evolveum.prism.xml.ns._public.query_3.SearchFilterType) QName(javax.xml.namespace.QName) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap)

Example 22 with VariablesMap

use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.

the class ScriptingTaskCreator method createVariables.

private VariablesMap createVariables() throws SchemaException {
    VariablesMap variables = ModelImplUtils.getDefaultVariablesMap(actx.context, null, true);
    actx.putIntoVariables(variables);
    return variables;
}
Also used : VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap)

Example 23 with VariablesMap

use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.

the class ModelImplUtils method getDefaultVariablesMap.

public static <O extends ObjectType> VariablesMap getDefaultVariablesMap(PrismObject<? extends ObjectType> focus, PrismObject<? extends ShadowType> shadow, ResourceShadowDiscriminator discr, PrismObject<ResourceType> resource, PrismObject<SystemConfigurationType> configuration, LensElementContext<O> affectedElementContext, PrismContext prismContext) {
    VariablesMap variables = new VariablesMap();
    addDefaultVariablesMap(variables, focus, shadow, discr, resource, configuration, affectedElementContext, prismContext);
    return variables;
}
Also used : VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap)

Example 24 with VariablesMap

use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.

the class AdvancedActivityRunSupportImpl method evaluateQueryExpressions.

@Override
public ObjectQuery evaluateQueryExpressions(@NotNull ObjectQuery query, ExpressionProfile expressionProfile, @NotNull RunningTask task, OperationResult result) throws CommonException {
    PrismObject<SystemConfigurationType> configuration = systemObjectCache.getSystemConfiguration(result);
    VariablesMap variables = ModelImplUtils.getDefaultVariablesMap(null, null, null, configuration != null ? configuration.asObjectable() : null, PrismContext.get());
    try {
        ExpressionEnvironment<?, ?, ?> env = new ExpressionEnvironment<>(task, result);
        ModelExpressionThreadLocalHolder.pushExpressionEnvironment(env);
        return ExpressionUtil.evaluateQueryExpressions(query, variables, expressionProfile, expressionFactory, prismContext, "evaluate query expressions", task, result);
    } finally {
        ModelExpressionThreadLocalHolder.popExpressionEnvironment();
    }
}
Also used : ExpressionEnvironment(com.evolveum.midpoint.model.common.expression.ExpressionEnvironment) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap)

Example 25 with VariablesMap

use of com.evolveum.midpoint.schema.expression.VariablesMap in project midpoint by Evolveum.

the class TestExpressionSpec method prepareBasicVariablesNoDelta.

private VariablesMap prepareBasicVariablesNoDelta() {
    VariablesMap variables = new VariablesMap();
    variables.put(VAR_FOO, "fooValue", String.class);
    variables.put(VAR_BAR, "barValue", String.class);
    return variables;
}
Also used : VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap)

Aggregations

VariablesMap (com.evolveum.midpoint.schema.expression.VariablesMap)166 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)48 ExpressionEvaluationContext (com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext)30 Test (org.testng.annotations.Test)28 Task (com.evolveum.midpoint.task.api.Task)23 NotNull (org.jetbrains.annotations.NotNull)23 QName (javax.xml.namespace.QName)15 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)12 Source (com.evolveum.midpoint.repo.common.expression.Source)12 AbstractModelCommonTest (com.evolveum.midpoint.model.common.AbstractModelCommonTest)11 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)11 ExpressionFactory (com.evolveum.midpoint.repo.common.expression.ExpressionFactory)10 Trace (com.evolveum.midpoint.util.logging.Trace)10 TraceManager (com.evolveum.midpoint.util.logging.TraceManager)10 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)9 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)9 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)9 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)8 ExpressionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType)8 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)7