Search in sources :

Example 1 with ExpressionEnvironment

use of com.evolveum.midpoint.model.common.expression.ExpressionEnvironment in project midpoint by Evolveum.

the class ScriptExecutor method prepareScriptArgument.

private void prepareScriptArgument(ProvisioningScriptArgumentType argument, VariablesMap variables, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
    final QName fakeScriptArgumentName = new QName(SchemaConstants.NS_C, "arg");
    PrismPropertyDefinition<String> scriptArgumentDefinition = b.prismContext.definitionFactory().createPropertyDefinition(fakeScriptArgumentName, DOMUtil.XSD_STRING);
    scriptArgumentDefinition.freeze();
    String shortDesc = "Provisioning script argument expression";
    Expression<PrismPropertyValue<String>, PrismPropertyDefinition<String>> expression = b.expressionFactory.makeExpression(argument, scriptArgumentDefinition, MiscSchemaUtil.getExpressionProfile(), shortDesc, task, result);
    ExpressionEvaluationContext params = new ExpressionEvaluationContext(null, variables, shortDesc, task);
    ExpressionEnvironment<?, ?, ?> env = new ExpressionEnvironment<>(context, projCtx, task, result);
    PrismValueDeltaSetTriple<PrismPropertyValue<String>> outputTriple = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, params, env, result);
    Collection<PrismPropertyValue<String>> nonNegativeValues = outputTriple != null ? outputTriple.getNonNegativeValues() : emptySet();
    replaceScriptArgumentWithComputedValues(argument, nonNegativeValues);
}
Also used : ExpressionEnvironment(com.evolveum.midpoint.model.common.expression.ExpressionEnvironment) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) QName(javax.xml.namespace.QName) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 2 with ExpressionEnvironment

use of com.evolveum.midpoint.model.common.expression.ExpressionEnvironment 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 3 with ExpressionEnvironment

use of com.evolveum.midpoint.model.common.expression.ExpressionEnvironment in project midpoint by Evolveum.

the class FocusLifecycleProcessor method shouldTransition.

private <F extends AssignmentHolderType> boolean shouldTransition(LensContext<F> context, LifecycleStateTransitionType transitionType, String targetLifecycleState, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
    ExpressionType conditionExpressionType = transitionType.getCondition();
    if (conditionExpressionType == null) {
        return false;
    }
    String desc = "condition for transition to state " + targetLifecycleState + " for " + context.getFocusContext().getHumanReadableName();
    VariablesMap variables = new VariablesMap();
    variables.put(ExpressionConstants.VAR_OBJECT, context.getFocusContext().getObjectNew(), context.getFocusContext().getObjectNew().getDefinition());
    // TODO: more variables?
    Expression<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> expression = expressionFactory.makeExpression(conditionExpressionType, ExpressionUtil.createConditionOutputDefinition(), MiscSchemaUtil.getExpressionProfile(), desc, task, result);
    ExpressionEvaluationContext expressionContext = new ExpressionEvaluationContext(null, variables, desc, task);
    ExpressionEnvironment<?, ?, ?> env = new ExpressionEnvironment<>(context, null, task, result);
    PrismValueDeltaSetTriple<PrismPropertyValue<Boolean>> outputTriple = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, expressionContext, env, result);
    PrismPropertyValue<Boolean> expressionOutputValue = ExpressionUtil.getExpressionOutputValue(outputTriple, desc);
    return ExpressionUtil.getBooleanConditionOutput(expressionOutputValue);
}
Also used : ExpressionEnvironment(com.evolveum.midpoint.model.common.expression.ExpressionEnvironment) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap)

Example 4 with ExpressionEnvironment

use of com.evolveum.midpoint.model.common.expression.ExpressionEnvironment in project midpoint by Evolveum.

the class LensUtil method evaluateIterationCondition.

public static <F extends ObjectType> boolean evaluateIterationCondition(LensContext<F> context, LensElementContext<?> accountContext, IterationSpecificationType iterationSpecification, int iteration, String iterationToken, boolean beforeIteration, ExpressionFactory expressionFactory, VariablesMap variables, Task task, OperationResult result) throws ExpressionEvaluationException, SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
    if (iterationSpecification == null) {
        return true;
    }
    ExpressionType expressionType;
    String desc;
    if (beforeIteration) {
        expressionType = iterationSpecification.getPreIterationCondition();
        desc = "pre-iteration expression in " + accountContext.getHumanReadableName();
    } else {
        expressionType = iterationSpecification.getPostIterationCondition();
        desc = "post-iteration expression in " + accountContext.getHumanReadableName();
    }
    if (expressionType == null) {
        return true;
    }
    Expression<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> expression = expressionFactory.makeExpression(expressionType, ExpressionUtil.createConditionOutputDefinition(), MiscSchemaUtil.getExpressionProfile(), desc, task, result);
    variables.put(ExpressionConstants.VAR_ITERATION, iteration, Integer.class);
    variables.put(ExpressionConstants.VAR_ITERATION_TOKEN, iterationToken, String.class);
    ExpressionEvaluationContext expressionContext = new ExpressionEvaluationContext(null, variables, desc, task);
    ExpressionEnvironment<?, ?, ?> env = new ExpressionEnvironment<>(context, null, task, result);
    PrismValueDeltaSetTriple<PrismPropertyValue<Boolean>> outputTriple = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, expressionContext, env, result);
    Collection<PrismPropertyValue<Boolean>> outputValues = outputTriple.getNonNegativeValues();
    if (outputValues.isEmpty()) {
        return false;
    }
    if (outputValues.size() > 1) {
        throw new ExpressionEvaluationException(desc + " returned more than one value (" + outputValues.size() + " values)");
    }
    Boolean realValue = outputValues.iterator().next().getValue();
    if (realValue == null) {
        return false;
    }
    return realValue;
}
Also used : ExpressionEnvironment(com.evolveum.midpoint.model.common.expression.ExpressionEnvironment) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Aggregations

ExpressionEnvironment (com.evolveum.midpoint.model.common.expression.ExpressionEnvironment)4 ExpressionEvaluationContext (com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext)3 VariablesMap (com.evolveum.midpoint.schema.expression.VariablesMap)2 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)1 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 SystemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)1 QName (javax.xml.namespace.QName)1