use of com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType in project midpoint by Evolveum.
the class ExpressionHandlerImplTest method testEvaluateExpression.
@SuppressWarnings("unchecked")
@Test
public void testEvaluateExpression() throws Exception {
PrismObject<ShadowType> account = PrismTestUtil.parseObject(new File(TEST_FOLDER, "account.xml"));
ShadowType accountType = account.asObjectable();
PrismObject<ResourceType> resource = PrismTestUtil.parseObject(new File(TEST_FOLDER_COMMON, "resource-dummy.xml"));
ResourceType resourceType = resource.asObjectable();
accountType.setResource(resourceType);
ObjectSynchronizationType synchronization = resourceType.getSynchronization().getObjectSynchronization().get(0);
for (ConditionalSearchFilterType filter : synchronization.getCorrelation()) {
MapXNode clauseXNode = filter.getFilterClauseXNode();
// key = q:equal, value = map (path + expression)
RootXNode expressionNode = ((MapXNode) clauseXNode.getSingleSubEntry("filter value").getValue()).getEntryAsRoot(new QName(SchemaConstants.NS_C, "expression"));
ExpressionType expression = PrismTestUtil.getPrismContext().parserFor(expressionNode).parseRealValue(ExpressionType.class);
LOGGER.debug("Expression: {}", SchemaDebugUtil.prettyPrint(expression));
OperationResult result = new OperationResult("testCorrelationRule");
String name = expressionHandler.evaluateExpression(accountType, expression, "test expression", null, result);
LOGGER.info(result.debugDump());
assertEquals("Wrong expression result", "hbarbossa", name);
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.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 com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType in project midpoint by Evolveum.
the class Expression method evaluate.
public PrismValueDeltaSetTriple<V> evaluate(ExpressionEvaluationContext context) throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException {
ExpressionVariables processedVariables = null;
try {
processedVariables = processInnerVariables(context.getVariables(), context.getContextDescription(), context.getTask(), context.getResult());
ExpressionEvaluationContext contextWithProcessedVariables = context.shallowClone();
contextWithProcessedVariables.setVariables(processedVariables);
PrismValueDeltaSetTriple<V> outputTriple;
ObjectReferenceType runAsRef = null;
if (expressionType != null) {
runAsRef = expressionType.getRunAsRef();
}
if (runAsRef == null) {
outputTriple = evaluateExpressionEvaluators(contextWithProcessedVariables);
} else {
UserType userType = objectResolver.resolve(runAsRef, UserType.class, null, "runAs in " + context.getContextDescription(), context.getTask(), context.getResult());
LOGGER.trace("Running {} as {} ({})", context.getContextDescription(), userType, runAsRef);
try {
outputTriple = securityEnforcer.runAs(() -> {
try {
return evaluateExpressionEvaluators(contextWithProcessedVariables);
} catch (SchemaException | ExpressionEvaluationException | ObjectNotFoundException e) {
throw new TunnelException(e);
}
}, userType.asPrismObject());
} catch (TunnelException te) {
Throwable e = te.getCause();
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
if (e instanceof Error) {
throw (Error) e;
}
if (e instanceof SchemaException) {
throw (SchemaException) e;
}
if (e instanceof ExpressionEvaluationException) {
throw (ExpressionEvaluationException) e;
}
if (e instanceof ObjectNotFoundException) {
throw (ObjectNotFoundException) e;
}
throw te;
}
}
traceSuccess(context, processedVariables, outputTriple);
return outputTriple;
} catch (SchemaException | ExpressionEvaluationException | ObjectNotFoundException | RuntimeException | Error e) {
traceFailure(context, processedVariables, e);
throw e;
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.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 com.evolveum.midpoint.xml.ns._public.common.common_3.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