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);
}
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();
}
}
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());
}
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);
}
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());
}
Aggregations