Search in sources :

Example 11 with VariablesMap

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

the class TestExpressionProfileSafe method test130Const.

@Test
@Override
public void test130Const() throws Exception {
    given();
    OperationResult result = createOperationResult();
    rememberScriptExecutionCount();
    ExpressionType expressionType = parseExpression(EXPRESSION_CONST_FILE);
    Collection<Source<?, ?>> sources = prepareStringSources();
    VariablesMap variables = prepareBasicVariables();
    ExpressionEvaluationContext expressionContext = new ExpressionEvaluationContext(sources, variables, getTestNameShort(), null);
    when();
    evaluatePropertyExpressionRestricted(expressionType, PrimitiveType.STRING, expressionContext, result);
    then();
    assertScriptExecutionIncrement(0);
}
Also used : ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) Source(com.evolveum.midpoint.repo.common.expression.Source) Test(org.testng.annotations.Test)

Example 12 with VariablesMap

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

the class ModelInteractionServiceImpl method createLocalizableMessageType.

@Override
@NotNull
public LocalizableMessageType createLocalizableMessageType(LocalizableMessageTemplateType template, VariablesMap variables, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
    VariablesMap vars = new VariablesMap();
    vars.putAll(variables);
    return LensUtil.interpretLocalizableMessageTemplate(template, vars, expressionFactory, prismContext, task, result);
}
Also used : VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with VariablesMap

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

the class DeltaExecution method prepareScripts.

// endregion
// region Provisioning scripts
/**
 * TODO clarify the role of `object` parameter and why it is used only as a second choice (after ctx.objectAny).
 */
private OperationProvisioningScriptsType prepareScripts(PrismObject<E> object, ProvisioningOperationTypeType operation, OperationResult result) throws ObjectNotFoundException, SchemaException, CommunicationException, ConfigurationException, SecurityViolationException, ExpressionEvaluationException {
    if (resource == null) {
        LOGGER.warn("Resource does not exist. Skipping processing scripts.");
        return null;
    }
    OperationProvisioningScriptsType resourceScripts = resource.getScripts();
    LensProjectionContext projCtx = (LensProjectionContext) elementContext;
    PrismObject<ShadowType> shadow = getShadow(projCtx, object);
    PrismObject<O> focus = getFocus();
    ResourceShadowDiscriminator rsd = projCtx.getResourceShadowDiscriminator();
    VariablesMap variables = ModelImplUtils.getDefaultVariablesMap(focus, shadow, rsd, resource.asPrismObject(), context.getSystemConfiguration(), elementContext, b.prismContext);
    // Having delta in provisioning scripts may be very useful. E.g. the script can optimize execution of expensive operations.
    variables.put(ExpressionConstants.VAR_DELTA, projCtx.getCurrentDelta(), ObjectDelta.class);
    ExpressionProfile expressionProfile = MiscSchemaUtil.getExpressionProfile();
    ModelExpressionThreadLocalHolder.pushExpressionEnvironment(new ExpressionEnvironment<>(context, projCtx, task, result));
    try {
        ScriptExecutor<O> scriptExecutor = new ScriptExecutor<>(context, projCtx, task, b);
        return scriptExecutor.prepareScripts(resourceScripts, rsd, operation, null, variables, expressionProfile, result);
    } finally {
        ModelExpressionThreadLocalHolder.popExpressionEnvironment();
    }
}
Also used : VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) ExpressionProfile(com.evolveum.midpoint.schema.expression.ExpressionProfile)

Example 14 with VariablesMap

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

the class ProjectionValuesProcessor method formatIterationToken.

private <F extends ObjectType> String formatIterationToken(LensContext<F> context, LensProjectionContext accountContext, int iteration, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
    ResourceObjectTypeDefinitionType accDef = accountContext.getResourceObjectTypeDefinitionType();
    if (accDef == null) {
        return LensUtil.formatIterationTokenDefault(iteration);
    }
    IterationSpecificationType iterationType = accDef.getIteration();
    VariablesMap variables = createVariablesMap(context, accountContext);
    return LensUtil.formatIterationToken(context, accountContext, iterationType, iteration, expressionFactory, variables, task, result);
}
Also used : VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap)

Example 15 with VariablesMap

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

the class ConstructionResourceResolver method resolveResourceRefFilter.

@SuppressWarnings("SameParameterValue")
@NotNull
private ResourceType resolveResourceRefFilter(String sourceDescription, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException {
    VariablesMap variables = ModelImplUtils.getDefaultVariablesMap(construction.getFocusOdoAbsolute().getNewObject().asObjectable(), null, null, null, PrismContext.get());
    ModelImplUtils.addAssignmentPathVariables(construction.getAssignmentPathVariables(), variables, PrismContext.get());
    LOGGER.debug("Expression variables for filter evaluation: {}", variables);
    assert construction.constructionBean != null;
    ObjectFilter origFilter = PrismContext.get().getQueryConverter().parseFilter(construction.constructionBean.getResourceRef().getFilter(), ResourceType.class);
    LOGGER.debug("Orig filter {}", origFilter);
    ObjectFilter evaluatedFilter = ExpressionUtil.evaluateFilterExpressions(origFilter, variables, construction.expressionProfile, ModelBeans.get().commonBeans.expressionFactory, PrismContext.get(), " evaluating resource filter expression ", task, result);
    LOGGER.debug("evaluatedFilter filter {}", evaluatedFilter);
    if (evaluatedFilter == null) {
        throw new SchemaException("The OID is null and filter could not be evaluated in assignment targetRef in " + construction.source);
    }
    ObjectQuery query = PrismContext.get().queryFactory().createQuery(evaluatedFilter);
    Collection<PrismObject<ResourceType>> matchingResources = ModelBeans.get().modelObjectResolver.searchObjects(ResourceType.class, query, createReadOnlyCollection(), task, result);
    // TODO consider referential integrity settings
    if (CollectionUtils.isEmpty(matchingResources)) {
        throw new ObjectNotFoundException("Got no target from repository, filter:" + evaluatedFilter + ", class:" + ResourceType.class + " in " + sourceDescription);
    }
    if (matchingResources.size() > 1) {
        throw new IllegalArgumentException("Got more than one target from repository, filter:" + evaluatedFilter + ", class:" + ResourceType.class + " in " + sourceDescription);
    }
    return matchingResources.iterator().next().asObjectable();
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) VariablesMap(com.evolveum.midpoint.schema.expression.VariablesMap) ResourceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) 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