Search in sources :

Example 91 with VariablesMap

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

the class DashboardServiceImpl method createVariables.

private static VariablesMap createVariables(PrismObject<? extends ObjectType> object, IntegerStatType statType, Collection<String> policySituations, String storedData) {
    VariablesMap variables = new VariablesMap();
    if (statType != null || policySituations != null) {
        VariablesMap variablesMap = new VariablesMap();
        if (statType != null) {
            variablesMap.put(ExpressionConstants.VAR_INPUT, statType, statType.getClass());
            variablesMap.put(VAR_PROPORTIONAL, statType, statType.getClass());
            variablesMap.registerAlias(VAR_PROPORTIONAL, ExpressionConstants.VAR_INPUT);
        }
        if (policySituations != null) {
            variablesMap.put(VAR_POLICY_SITUATIONS, policySituations, EvaluatedPolicyRule.class);
        }
        variables.addVariableDefinitions(variablesMap);
    }
    if (object != null) {
        variables.addVariableDefinition(ExpressionConstants.VAR_OBJECT, object, object.getDefinition());
    }
    if (storedData != null) {
        variables.put(VAR_STORED_DATA, storedData, String.class);
    }
    return variables;
}
Also used : VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap)

Example 92 with VariablesMap

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

the class SynchronizationContext method conditionMatches.

private boolean conditionMatches(SynchronizationReactionType reaction, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
    if (reaction.getCondition() != null) {
        ExpressionType expression = reaction.getCondition();
        String desc = "condition in synchronization reaction on " + reaction.getSituation() + (reaction.getName() != null ? " (" + reaction.getName() + ")" : "");
        VariablesMap variables = ModelImplUtils.getDefaultVariablesMap(getFocus(), shadowedResourceObject, null, resource, systemConfiguration, null, prismContext);
        variables.put(ExpressionConstants.VAR_RESOURCE_OBJECT_DELTA, resourceObjectDelta, ObjectDelta.class);
        try {
            ModelExpressionThreadLocalHolder.pushExpressionEnvironment(new ExpressionEnvironment<>(task, result));
            boolean value = ExpressionUtil.evaluateConditionDefaultFalse(variables, expression, expressionProfile, beans.expressionFactory, desc, task, result);
            if (!value) {
                LOGGER.trace("Skipping reaction {} because the condition was evaluated to false", reaction);
            }
            return value;
        } finally {
            ModelExpressionThreadLocalHolder.popExpressionEnvironment();
        }
    } else {
        return true;
    }
}
Also used : VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap)

Example 93 with VariablesMap

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

the class SynchronizationExpressionsEvaluator method generateTag.

// For now only used in sync service. but later can be used in outbound/assignments
@SuppressWarnings("WeakerAccess")
public String generateTag(ResourceObjectMultiplicityType multiplicity, PrismObject<ShadowType> shadow, PrismObject<ResourceType> resource, PrismObject<SystemConfigurationType> configuration, String shortDesc, Task task, OperationResult parentResult) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
    if (multiplicity == null) {
        return null;
    }
    ShadowTagSpecificationType tagSpec = multiplicity.getTag();
    if (tagSpec == null) {
        return shadow.getOid();
    }
    ExpressionType expressionType = tagSpec.getExpression();
    if (expressionType == null) {
        return shadow.getOid();
    }
    VariablesMap variables = ModelImplUtils.getDefaultVariablesMap(null, shadow, null, resource, configuration, null, prismContext);
    ItemDefinition outputDefinition = prismContext.definitionFactory().createPropertyDefinition(ExpressionConstants.OUTPUT_ELEMENT_NAME, PrimitiveType.STRING.getQname());
    PrismPropertyValue<String> tagProp = ExpressionUtil.evaluateExpression(variables, outputDefinition, expressionType, MiscSchemaUtil.getExpressionProfile(), expressionFactory, shortDesc, task, parentResult);
    return getRealValue(tagProp);
}
Also used : ShadowTagSpecificationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowTagSpecificationType) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType)

Example 94 with VariablesMap

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

the class SynchronizationServiceImpl method evaluateSynchronizationSorter.

private <F extends FocusType> ObjectSynchronizationDiscriminatorType evaluateSynchronizationSorter(@NotNull SynchronizationType synchronization, @NotNull SynchronizationContext<F> syncCtx, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException {
    ObjectSynchronizationSorterType synchronizationSorter = synchronization.getObjectSynchronizationSorter();
    if (synchronizationSorter == null || synchronizationSorter.getExpression() == null) {
        return null;
    }
    ExpressionType classificationExpression = synchronizationSorter.getExpression();
    String desc = "synchronization divider type ";
    VariablesMap variables = ModelImplUtils.getDefaultVariablesMap(null, syncCtx.getShadowedResourceObject(), null, syncCtx.getResource(), syncCtx.getSystemConfiguration(), null, syncCtx.getPrismContext());
    variables.put(ExpressionConstants.VAR_CHANNEL, syncCtx.getChannel(), String.class);
    try {
        ModelExpressionThreadLocalHolder.pushExpressionEnvironment(new ExpressionEnvironment<>(task, result));
        // noinspection unchecked
        PrismPropertyDefinition<ObjectSynchronizationDiscriminatorType> discriminatorDef = prismContext.getSchemaRegistry().findPropertyDefinitionByElementName(SchemaConstantsGenerated.C_OBJECT_SYNCHRONIZATION_DISCRIMINATOR);
        PrismPropertyValue<ObjectSynchronizationDiscriminatorType> discriminator = ExpressionUtil.evaluateExpression(variables, discriminatorDef, classificationExpression, syncCtx.getExpressionProfile(), expressionFactory, desc, task, result);
        return getRealValue(discriminator);
    } finally {
        ModelExpressionThreadLocalHolder.popExpressionEnvironment();
    }
}
Also used : VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap)

Example 95 with VariablesMap

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

the class BaseActionExecutor method createVariables.

/**
 * Creates variables for script evaluation based on some externally-supplied variables,
 * plus some generic ones (prism context, actor).
 */
@NotNull
protected VariablesMap createVariables(VariablesMap externalVariables) {
    VariablesMap variables = new VariablesMap();
    variables.put(ExpressionConstants.VAR_PRISM_CONTEXT, prismContext, PrismContext.class);
    ExpressionUtil.addActorVariable(variables, securityContextManager, prismContext);
    // noinspection unchecked
    externalVariables.forEach((k, v) -> variables.put(k, cloneIfNecessary(k, v)));
    variables.registerAliasesFrom(externalVariables);
    return variables;
}
Also used : VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) NotNull(org.jetbrains.annotations.NotNull)

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