Search in sources :

Example 41 with ExpressionVariables

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

the class ChangeExecutor method prepareScripts.

private <F extends ObjectType, T extends ObjectType> OperationProvisioningScriptsType prepareScripts(PrismObject<T> changedObject, LensContext<F> context, LensElementContext<T> objectContext, ProvisioningOperationTypeType operation, ResourceType resource, Task task, 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();
    PrismObject<? extends ShadowType> resourceObject = (PrismObject<? extends ShadowType>) changedObject;
    PrismObject<F> user = null;
    if (context.getFocusContext() != null) {
        if (context.getFocusContext().getObjectNew() != null) {
            user = context.getFocusContext().getObjectNew();
        } else if (context.getFocusContext().getObjectOld() != null) {
            user = context.getFocusContext().getObjectOld();
        }
    }
    ResourceShadowDiscriminator discr = ((LensProjectionContext) objectContext).getResourceShadowDiscriminator();
    ExpressionVariables variables = Utils.getDefaultExpressionVariables(user, resourceObject, discr, resource.asPrismObject(), context.getSystemConfiguration(), objectContext);
    return evaluateScript(resourceScripts, discr, operation, null, variables, context, objectContext, task, result);
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) ResourceShadowDiscriminator(com.evolveum.midpoint.schema.ResourceShadowDiscriminator)

Example 42 with ExpressionVariables

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

the class Utils method getDefaultExpressionVariables.

public static <O extends ObjectType> ExpressionVariables getDefaultExpressionVariables(PrismObject<? extends ObjectType> focus, PrismObject<? extends ShadowType> shadow, ResourceShadowDiscriminator discr, PrismObject<ResourceType> resource, PrismObject<SystemConfigurationType> configuration, LensElementContext<O> affectedElementContext) {
    ExpressionVariables variables = new ExpressionVariables();
    addDefaultExpressionVariables(variables, focus, shadow, discr, resource, configuration, affectedElementContext);
    return variables;
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables)

Example 43 with ExpressionVariables

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

the class CorrelationConfirmationEvaluator method satisfyCondition.

private boolean satisfyCondition(ShadowType currentShadow, ConditionalSearchFilterType conditionalFilter, ResourceType resourceType, SystemConfigurationType configurationType, String shortDesc, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
    if (conditionalFilter.getCondition() == null) {
        return true;
    }
    ExpressionType condition = conditionalFilter.getCondition();
    ExpressionVariables variables = Utils.getDefaultExpressionVariables(null, currentShadow, resourceType, configurationType);
    ItemDefinition outputDefinition = new PrismPropertyDefinitionImpl(ExpressionConstants.OUTPUT_ELEMENT_NAME, DOMUtil.XSD_BOOLEAN, prismContext);
    PrismPropertyValue<Boolean> satisfy = (PrismPropertyValue) ExpressionUtil.evaluateExpression(variables, outputDefinition, condition, expressionFactory, shortDesc, task, parentResult);
    if (satisfy.getValue() == null) {
        return false;
    }
    return satisfy.getValue();
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType)

Example 44 with ExpressionVariables

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

the class CustomTransport method getDefaultVariables.

protected ExpressionVariables getDefaultVariables(Message message, Event event) throws UnsupportedEncodingException {
    ExpressionVariables variables = new ExpressionVariables();
    variables.addVariableDefinition(SchemaConstants.C_MESSAGE, message);
    variables.addVariableDefinition(SchemaConstants.C_EVENT, event);
    return variables;
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables)

Example 45 with ExpressionVariables

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

the class SimpleSmsTransport method getDefaultVariables.

protected ExpressionVariables getDefaultVariables(String from, String to, Message message) throws UnsupportedEncodingException {
    ExpressionVariables variables = new ExpressionVariables();
    variables.addVariableDefinition(SchemaConstants.C_FROM, from);
    variables.addVariableDefinition(SchemaConstants.C_TO, to);
    variables.addVariableDefinition(SchemaConstants.C_ENCODED_MESSAGE_TEXT, URLEncoder.encode(message.getBody(), "US-ASCII"));
    variables.addVariableDefinition(SchemaConstants.C_MESSAGE, message);
    return variables;
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables)

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