Search in sources :

Example 21 with ExpressionVariables

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

the class ChangeExecutor method executeReconciliationScript.

private <T extends ObjectType, F extends ObjectType> void executeReconciliationScript(LensProjectionContext projContext, LensContext<F> context, BeforeAfterType order, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, SecurityViolationException, ObjectAlreadyExistsException {
    if (!projContext.isDoReconciliation()) {
        return;
    }
    ResourceType resource = projContext.getResource();
    if (resource == null) {
        LOGGER.warn("Resource does not exist. Skipping processing reconciliation scripts.");
        return;
    }
    OperationProvisioningScriptsType resourceScripts = resource.getScripts();
    if (resourceScripts == null) {
        return;
    }
    PrismObject<F> user = null;
    PrismObject<ShadowType> shadow = null;
    if (context.getFocusContext() != null) {
        if (context.getFocusContext().getObjectNew() != null) {
            user = context.getFocusContext().getObjectNew();
        } else if (context.getFocusContext().getObjectOld() != null) {
            user = context.getFocusContext().getObjectOld();
        }
    // if (order == ProvisioningScriptOrderType.BEFORE) {
    // user = context.getFocusContext().getObjectOld();
    // } else if (order == ProvisioningScriptOrderType.AFTER) {
    // user = context.getFocusContext().getObjectNew();
    // } else {
    // throw new IllegalArgumentException("Unknown order "+order);
    // }
    }
    if (order == BeforeAfterType.BEFORE) {
        shadow = (PrismObject<ShadowType>) projContext.getObjectOld();
    } else if (order == BeforeAfterType.AFTER) {
        shadow = (PrismObject<ShadowType>) projContext.getObjectNew();
    } else {
        throw new IllegalArgumentException("Unknown order " + order);
    }
    ExpressionVariables variables = Utils.getDefaultExpressionVariables(user, shadow, projContext.getResourceShadowDiscriminator(), resource.asPrismObject(), context.getSystemConfiguration(), projContext);
    OperationProvisioningScriptsType evaluatedScript = evaluateScript(resourceScripts, projContext.getResourceShadowDiscriminator(), ProvisioningOperationTypeType.RECONCILE, order, variables, context, projContext, task, parentResult);
    for (OperationProvisioningScriptType script : evaluatedScript.getScript()) {
        Utils.setRequestee(task, context);
        provisioning.executeScript(resource.getOid(), script, task, parentResult);
        Utils.clearRequestee(task);
    }
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables)

Example 22 with ExpressionVariables

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

the class ObjectMerger method evaluateValueExpression.

private <O extends ObjectType> Collection<PrismValue> evaluateValueExpression(PrismObject<O> objectLeft, PrismObject<O> objectRight, String side, PrismValue origValue, Expression<PrismValue, ItemDefinition> valueExpression, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
    ExpressionVariables variables = new ExpressionVariables();
    variables.addVariableDefinition(ExpressionConstants.VAR_SIDE, side);
    variables.addVariableDefinition(ExpressionConstants.VAR_OBJECT_LEFT, side);
    variables.addVariableDefinition(ExpressionConstants.VAR_OBJECT_RIGHT, side);
    variables.addVariableDefinition(ExpressionConstants.VAR_INPUT, origValue);
    variables.addVariableDefinition(ExpressionConstants.VAR_VALUE, origValue);
    ExpressionEvaluationContext exprContext = new ExpressionEvaluationContext(null, variables, "for value " + origValue, task, result);
    PrismValueDeltaSetTriple<PrismValue> triple = valueExpression.evaluate(exprContext);
    if (triple == null) {
        return null;
    }
    return triple.getNonNegativeValues();
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Example 23 with ExpressionVariables

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

the class PageRepositoryQuery method updateRequestWithMidpointQuery.

private void updateRequestWithMidpointQuery(RepositoryQueryDiagRequest request, QName objectType, String queryText, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
    PrismContext prismContext = getPrismContext();
    if (objectType == null) {
        objectType = ObjectType.COMPLEX_TYPE;
    }
    @SuppressWarnings("unchecked") Class<? extends ObjectType> clazz = (Class<? extends ObjectType>) prismContext.getSchemaRegistry().getCompileTimeClassForObjectType(objectType);
    if (clazz == null) {
        throw new SchemaException("Couldn't find compile-time class for object type of " + objectType);
    }
    QueryType queryType = prismContext.parserFor(queryText).xml().parseRealValue(QueryType.class);
    request.setType(clazz);
    ObjectQuery objectQuery = QueryJaxbConvertor.createObjectQuery(clazz, queryType, prismContext);
    ObjectQuery queryWithExprEvaluated = ExpressionUtil.evaluateQueryExpressions(objectQuery, new ExpressionVariables(), getExpressionFactory(), getPrismContext(), "evaluate query expressions", task, result);
    request.setQuery(queryWithExprEvaluated);
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismContext(com.evolveum.midpoint.prism.PrismContext) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery)

Example 24 with ExpressionVariables

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

the class GenerateExpressionEvaluator method getObject.

// determine object from the variables
@SuppressWarnings("unchecked")
private <O extends ObjectType> PrismObject<O> getObject(ExpressionEvaluationContext params) throws SchemaException {
    ExpressionVariables variables = params.getVariables();
    if (variables == null) {
        return null;
    }
    PrismObject<O> object = variables.getObjectNew(ExpressionConstants.VAR_PROJECTION);
    if (object != null) {
        return object;
    }
    object = variables.getObjectNew(ExpressionConstants.VAR_FOCUS);
    return object;
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables)

Example 25 with ExpressionVariables

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

the class AbstractValueTransformationExpressionEvaluator method evaluateScriptExpression.

private Collection<V> evaluateScriptExpression(Collection<Source<?, ?>> sources, ExpressionVariables variables, String contextDescription, boolean useNew, ExpressionEvaluationContext params, Task task, OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
    ExpressionVariables scriptVariables = new ExpressionVariables();
    if (useNew) {
        scriptVariables.addVariableDefinitionsNew(variables);
    } else {
        scriptVariables.addVariableDefinitionsOld(variables);
    }
    if (sources != null) {
        // Add sources to variables
        for (Source<?, ?> source : sources) {
            LOGGER.trace("source: {}", source);
            QName name = source.getName();
            if (name == null) {
                if (sources.size() == 1) {
                    name = ExpressionConstants.VAR_INPUT;
                } else {
                    throw new ExpressionSyntaxException("No name definition for source in " + contextDescription);
                }
            }
            Object value = null;
            if (useNew) {
                value = getRealContent(source.getItemNew(), source.getResidualPath());
            } else {
                value = getRealContent(source.getItemOld(), source.getResidualPath());
            }
            scriptVariables.addVariableDefinition(name, value);
        }
    }
    List<V> scriptResults = transformSingleValue(scriptVariables, null, useNew, params, (useNew ? "(new) " : "(old) ") + contextDescription, task, result);
    if (scriptResults == null || scriptResults.isEmpty()) {
        return null;
    }
    Collection<V> outputSet = new ArrayList<V>(scriptResults.size());
    for (V pval : scriptResults) {
        if (pval instanceof PrismPropertyValue<?>) {
            if (((PrismPropertyValue<?>) pval).getValue() == null) {
                continue;
            }
            Object realValue = ((PrismPropertyValue<?>) pval).getValue();
            if (realValue instanceof String) {
                if (((String) realValue).isEmpty()) {
                    continue;
                }
            }
            if (realValue instanceof PolyString) {
                if (((PolyString) realValue).isEmpty()) {
                    continue;
                }
            }
        }
        outputSet.add(pval);
    }
    return outputSet;
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) QName(javax.xml.namespace.QName) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectDeltaObject(com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ExpressionSyntaxException(com.evolveum.midpoint.repo.common.expression.ExpressionSyntaxException) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

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