Search in sources :

Example 1 with ExpressionType

use of oasis.names.tc.xacml._3_0.core.schema.wd_17.ExpressionType in project midpoint by Evolveum.

the class TestExpression method testIterationCondition.

@Test
public void testIterationCondition() throws Exception {
    final String TEST_NAME = "testIterationCondition";
    TestUtil.displayTestTile(TEST_NAME);
    // GIVEN
    OperationResult result = new OperationResult(TestExpression.class.getName() + "." + TEST_NAME);
    rememberScriptExecutionCount();
    ExpressionType expressionType = PrismTestUtil.parseAtomicValue(EXPRESSION_ITERATION_CONDITION_FILE, ExpressionType.COMPLEX_TYPE);
    PrismPropertyDefinition<Boolean> outputDefinition = new PrismPropertyDefinitionImpl<>(ExpressionConstants.OUTPUT_ELEMENT_NAME, DOMUtil.XSD_BOOLEAN, prismContext);
    Expression<PrismPropertyValue<Boolean>, PrismPropertyDefinition<Boolean>> expression = expressionFactory.makeExpression(expressionType, outputDefinition, TEST_NAME, null, result);
    ExpressionVariables variables = new ExpressionVariables();
    PrismObject<UserType> user = PrismTestUtil.parseObject(USER_JACK_FILE);
    variables.addVariableDefinition(ExpressionConstants.VAR_FOCUS, user);
    variables.addVariableDefinition(ExpressionConstants.VAR_USER, user);
    PrismObject<ShadowType> account = PrismTestUtil.parseObject(ACCOUNT_JACK_DUMMYFILE);
    variables.addVariableDefinition(ExpressionConstants.VAR_SHADOW, account);
    variables.addVariableDefinition(ExpressionConstants.VAR_ITERATION, 1);
    variables.addVariableDefinition(ExpressionConstants.VAR_ITERATION_TOKEN, "001");
    ExpressionEvaluationContext expressionContext = new ExpressionEvaluationContext(null, variables, TEST_NAME, null, result);
    // WHEN
    PrismValueDeltaSetTriple<PrismPropertyValue<Boolean>> outputTriple = expression.evaluate(expressionContext);
    // THEN
    assertNotNull(outputTriple);
    outputTriple.checkConsistence();
    // Make sure that the script is executed only once. There is no delta in the variables, no need to do it twice.
    assertScriptExecutionIncrement(1);
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 2 with ExpressionType

use of oasis.names.tc.xacml._3_0.core.schema.wd_17.ExpressionType in project midpoint by Evolveum.

the class SynchronizationServiceImpl method evaluateSynchronizationPolicyCondition.

private Boolean evaluateSynchronizationPolicyCondition(ObjectSynchronizationType synchronizationPolicy, PrismObject<? extends ShadowType> currentShadow, PrismObject<ResourceType> resource, PrismObject<SystemConfigurationType> configuration, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
    if (synchronizationPolicy.getCondition() == null) {
        return null;
    }
    ExpressionType conditionExpressionType = synchronizationPolicy.getCondition();
    String desc = "condition in object synchronization " + synchronizationPolicy.getName();
    ExpressionVariables variables = Utils.getDefaultExpressionVariables(null, currentShadow, null, resource, configuration, null);
    try {
        ModelExpressionThreadLocalHolder.pushExpressionEnvironment(new ExpressionEnvironment<>(task, result));
        PrismPropertyValue<Boolean> evaluateCondition = ExpressionUtil.evaluateCondition(variables, conditionExpressionType, expressionFactory, desc, task, result);
        return evaluateCondition.getValue();
    } finally {
        ModelExpressionThreadLocalHolder.popExpressionEnvironment();
    }
}
Also used : ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType)

Example 3 with ExpressionType

use of oasis.names.tc.xacml._3_0.core.schema.wd_17.ExpressionType in project midpoint by Evolveum.

the class TestParseMappingConst method assertPrismPropertyValueLocal.

@Override
protected void assertPrismPropertyValueLocal(PrismPropertyValue<MappingType> value) throws SchemaException {
    MappingType mappingType = value.getValue();
    ExpressionType expressionType = mappingType.getExpression();
    List<JAXBElement<?>> expressionEvaluatorElements = expressionType.getExpressionEvaluator();
    assertEquals("Wrong number of expression evaluator elemenets", 1, expressionEvaluatorElements.size());
    JAXBElement<?> expressionEvaluatorElement = expressionEvaluatorElements.get(0);
    Object evaluatorElementObject = expressionEvaluatorElement.getValue();
    if (!(evaluatorElementObject instanceof ConstExpressionEvaluatorType)) {
        AssertJUnit.fail("Const expression is of type " + evaluatorElementObject.getClass().getName());
    }
    ConstExpressionEvaluatorType constExpressionEvaluatorType = (ConstExpressionEvaluatorType) evaluatorElementObject;
    System.out.println("ConstExpressionEvaluatorType: " + constExpressionEvaluatorType);
    assertEquals("Wrong value in const evaluator", "foo", constExpressionEvaluatorType.getValue());
}
Also used : MappingType(com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType) ConstExpressionEvaluatorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ConstExpressionEvaluatorType) JAXBElement(javax.xml.bind.JAXBElement) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType)

Example 4 with ExpressionType

use of oasis.names.tc.xacml._3_0.core.schema.wd_17.ExpressionType in project midpoint by Evolveum.

the class ValueSetDefinition method init.

public void init(ExpressionFactory expressionFactory) throws SchemaException, ObjectNotFoundException {
    ExpressionType conditionType = setDefinitionType.getCondition();
    condition = ExpressionUtil.createCondition(conditionType, expressionFactory, shortDesc, task, result);
}
Also used : ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType)

Example 5 with ExpressionType

use of oasis.names.tc.xacml._3_0.core.schema.wd_17.ExpressionType in project midpoint by Evolveum.

the class WfExpressionEvaluationHelper method evaluateExpression.

@SuppressWarnings("unchecked")
@NotNull
public <T> List<T> evaluateExpression(ExpressionType expressionType, ExpressionVariables variables, String contextDescription, Class<T> clazz, QName typeName, Function<Object, Object> additionalConvertor, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException {
    ExpressionFactory expressionFactory = getExpressionFactory();
    PrismContext prismContext = expressionFactory.getPrismContext();
    PrismPropertyDefinition<String> resultDef = new PrismPropertyDefinitionImpl<>(new QName(SchemaConstants.NS_C, "result"), typeName, prismContext);
    Expression<PrismPropertyValue<String>, PrismPropertyDefinition<String>> expression = expressionFactory.makeExpression(expressionType, resultDef, contextDescription, task, result);
    ExpressionEvaluationContext context = new ExpressionEvaluationContext(null, variables, contextDescription, task, result);
    context.setAdditionalConvertor(additionalConvertor);
    PrismValueDeltaSetTriple<PrismPropertyValue<String>> exprResultTriple = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, context, task, result);
    return exprResultTriple.getZeroSet().stream().map(ppv -> (T) ppv.getRealValue()).collect(Collectors.toList());
}
Also used : SchemaConstants(com.evolveum.midpoint.schema.constants.SchemaConstants) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) SpringApplicationContextHolder.getMiscDataUtil(com.evolveum.midpoint.wf.impl.processes.common.SpringApplicationContextHolder.getMiscDataUtil) MiscDataUtil(com.evolveum.midpoint.wf.impl.util.MiscDataUtil) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) Function(java.util.function.Function) ArrayList(java.util.ArrayList) DOMUtil(com.evolveum.midpoint.util.DOMUtil) QNameUtil(com.evolveum.midpoint.util.QNameUtil) PrismContext(com.evolveum.midpoint.prism.PrismContext) PrismValueDeltaSetTriple(com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) Expression(com.evolveum.midpoint.repo.common.expression.Expression) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) Collection(java.util.Collection) SpringApplicationContextHolder.getExpressionFactory(com.evolveum.midpoint.wf.impl.processes.common.SpringApplicationContextHolder.getExpressionFactory) PrismPropertyDefinitionImpl(com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl) ModelExpressionThreadLocalHolder(com.evolveum.midpoint.model.impl.expr.ModelExpressionThreadLocalHolder) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) Task(com.evolveum.midpoint.task.api.Task) ApprovalUtils(com.evolveum.midpoint.wf.util.ApprovalUtils) JAXBException(javax.xml.bind.JAXBException) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) Component(org.springframework.stereotype.Component) List(java.util.List) ExpressionFactory(com.evolveum.midpoint.repo.common.expression.ExpressionFactory) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) DelegateExecution(org.activiti.engine.delegate.DelegateExecution) ExpressionUtil(com.evolveum.midpoint.repo.common.expression.ExpressionUtil) ApprovalLevelOutcomeType(com.evolveum.midpoint.xml.ns._public.common.common_3.ApprovalLevelOutcomeType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) QName(javax.xml.namespace.QName) NotNull(org.jetbrains.annotations.NotNull) SpringApplicationContextHolder.getExpressionFactory(com.evolveum.midpoint.wf.impl.processes.common.SpringApplicationContextHolder.getExpressionFactory) ExpressionFactory(com.evolveum.midpoint.repo.common.expression.ExpressionFactory) PrismPropertyDefinition(com.evolveum.midpoint.prism.PrismPropertyDefinition) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) PrismContext(com.evolveum.midpoint.prism.PrismContext) QName(javax.xml.namespace.QName) PrismPropertyDefinitionImpl(com.evolveum.midpoint.prism.PrismPropertyDefinitionImpl) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ExpressionType (com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType)37 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)12 ExpressionEvaluationContext (com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext)10 VariablesMap (com.evolveum.midpoint.schema.expression.VariablesMap)10 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)8 Task (com.evolveum.midpoint.task.api.Task)6 Test (org.testng.annotations.Test)6 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5 ExpressionVariables (com.evolveum.midpoint.repo.common.expression.ExpressionVariables)5 QName (javax.xml.namespace.QName)5 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 ExpressionFactory (com.evolveum.midpoint.repo.common.expression.ExpressionFactory)4 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)4 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)4 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)4 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)3 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)3 Source (com.evolveum.midpoint.repo.common.expression.Source)3 MappingType (com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType)3 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)3