use of com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType in project midpoint by Evolveum.
the class CustomNotifier method evaluateExpression.
private List<NotificationMessageType> evaluateExpression(ExpressionType expressionType, ExpressionVariables expressionVariables, String shortDesc, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException {
QName resultName = new QName(SchemaConstants.NS_C, "result");
PrismPropertyDefinition<NotificationMessageType> resultDef = new PrismPropertyDefinitionImpl<>(resultName, NotificationMessageType.COMPLEX_TYPE, prismContext);
Expression<PrismPropertyValue<NotificationMessageType>, PrismPropertyDefinition<NotificationMessageType>> expression = expressionFactory.makeExpression(expressionType, resultDef, shortDesc, task, result);
ExpressionEvaluationContext params = new ExpressionEvaluationContext(null, expressionVariables, shortDesc, task, result);
PrismValueDeltaSetTriple<PrismPropertyValue<NotificationMessageType>> exprResult = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, params, task, result);
return exprResult.getZeroSet().stream().map(PrismPropertyValue::getValue).collect(Collectors.toList());
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType in project midpoint by Evolveum.
the class ExpressionFilterHelper method processEvent.
@Override
public boolean processEvent(Event event, EventHandlerType eventHandlerType, NotificationManager notificationManager, Task task, OperationResult result) {
if (eventHandlerType.getExpressionFilter().isEmpty()) {
return true;
}
logStart(LOGGER, event, eventHandlerType, eventHandlerType.getExpressionFilter());
boolean retval = true;
for (ExpressionType expressionType : eventHandlerType.getExpressionFilter()) {
if (!evaluateBooleanExpressionChecked(expressionType, getDefaultVariables(event, result), "event filter expression", task, result)) {
retval = false;
break;
}
}
logEnd(LOGGER, event, eventHandlerType, retval);
return retval;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType in project midpoint by Evolveum.
the class AbstractSearchExpressionEvaluator method evaluatePopulateExpression.
private <IV extends PrismValue, ID extends ItemDefinition, C extends Containerable> ItemDelta<IV, ID> evaluatePopulateExpression(PopulateItemType populateItem, ExpressionVariables variables, ExpressionEvaluationContext params, PrismContainerDefinition<C> objectDefinition, String contextDescription, boolean evaluateMinus, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
ExpressionType expressionType = populateItem.getExpression();
if (expressionType == null) {
LOGGER.warn("No expression in populateObject in assignment expression in {}, " + "skipping. Subsequent operations will most likely fail", contextDescription);
return null;
}
VariableBindingDefinitionType targetType = populateItem.getTarget();
if (targetType == null) {
LOGGER.warn("No target in populateObject in assignment expression in {}, " + "skipping. Subsequent operations will most likely fail", contextDescription);
return null;
}
ItemPathType itemPathType = targetType.getPath();
if (itemPathType == null) {
throw new SchemaException("No path in target definition in " + contextDescription);
}
ItemPath targetPath = itemPathType.getItemPath();
ID propOutputDefinition = ExpressionUtil.resolveDefinitionPath(targetPath, variables, objectDefinition, "target definition in " + contextDescription);
if (propOutputDefinition == null) {
throw new SchemaException("No target item that would conform to the path " + targetPath + " in " + contextDescription);
}
String expressionDesc = "expression in assignment expression in " + contextDescription;
ExpressionFactory expressionFactory = params.getExpressionFactory();
Expression<IV, ID> expression = expressionFactory.makeExpression(expressionType, propOutputDefinition, expressionDesc, task, result);
ExpressionEvaluationContext context = new ExpressionEvaluationContext(null, variables, expressionDesc, task, result);
context.setExpressionFactory(expressionFactory);
context.setStringPolicyResolver(params.getStringPolicyResolver());
context.setDefaultTargetContext(params.getDefaultTargetContext());
context.setSkipEvaluationMinus(true);
context.setSkipEvaluationPlus(false);
PrismValueDeltaSetTriple<IV> outputTriple = expression.evaluate(context);
LOGGER.trace("output triple: {}", outputTriple.debugDump());
Collection<IV> pvalues = outputTriple.getNonNegativeValues();
// Maybe not really clean but it works. TODO: refactor later
NameItemPathSegment first = (NameItemPathSegment) targetPath.first();
if (first.isVariable()) {
targetPath = targetPath.rest();
}
ItemDelta<IV, ID> itemDelta = propOutputDefinition.createEmptyDelta(targetPath);
itemDelta.addValuesToAdd(PrismValue.cloneCollection(pvalues));
LOGGER.trace("Item delta:\n{}", itemDelta.debugDump());
return itemDelta;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType in project midpoint by Evolveum.
the class ValuePolicyProcessor method testCheckExpression.
private <O extends ObjectType> void testCheckExpression(String newPassword, LimitationsType lims, PrismObject<O> object, String shortDesc, Task task, OperationResult result, StringBuilder message) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
List<CheckExpressionType> checkExpressions = lims.getCheckExpression();
if (checkExpressions.isEmpty()) {
return;
}
for (CheckExpressionType checkExpression : checkExpressions) {
ExpressionType expressionType = checkExpression.getExpression();
if (expressionType == null) {
return;
}
if (!checkExpression(newPassword, expressionType, object, shortDesc, task, result)) {
String msg = checkExpression.getFailureMessage();
if (msg == null) {
msg = "Check expression failed";
}
result.addSubresult(new OperationResult("Check expression", OperationResultStatus.FATAL_ERROR, msg));
message.append(msg);
message.append("\n");
}
}
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType in project midpoint by Evolveum.
the class ObjectMerger method mergeItem.
private <O extends ObjectType, I extends Item> ItemDelta mergeItem(PrismObject<O> objectLeft, PrismObject<O> objectRight, String mergeConfigurationName, ItemMergeConfigurationType itemMergeConfig, ItemPath itemPath, Task task, OperationResult result) throws SchemaException, ConfigurationException, ExpressionEvaluationException, ObjectNotFoundException {
I itemLeft = (I) objectLeft.findItem(itemPath);
I itemRight = (I) objectRight.findItem(itemPath);
if (itemLeft == null && itemRight == null) {
return null;
}
ItemDefinition itemDefinition = null;
if (itemLeft != null) {
itemDefinition = itemLeft.getDefinition();
} else {
itemDefinition = itemRight.getDefinition();
}
if (itemDefinition.isOperational()) {
// we do not want to modify them explicitly.
return null;
}
Expression<PrismValue, ItemDefinition> valueExpression = null;
if (itemMergeConfig.getValueExpression() != null) {
ExpressionType expressionType = itemMergeConfig.getValueExpression();
valueExpression = expressionFactory.makeExpression(expressionType, itemDefinition, "value expression for item " + itemPath + " in merge configuration " + mergeConfigurationName, task, result);
}
ItemDelta itemDelta = itemDefinition.createEmptyDelta(itemPath);
MergeStategyType leftStrategy = itemMergeConfig.getLeft();
MergeStategyType rightStrategy = itemMergeConfig.getRight();
if (leftStrategy == null || leftStrategy == MergeStategyType.IGNORE) {
if (rightStrategy == null || rightStrategy == MergeStategyType.IGNORE) {
// IGNORE both
if (itemLeft == null) {
return null;
} else {
itemDelta.setValueToReplace();
return itemDelta;
}
} else {
// IGNORE left, TAKE/EXPRESSION right
if (itemRight == null) {
itemDelta.setValueToReplace();
} else {
Collection<PrismValue> valuesToTake = getValuesToTake(objectLeft, objectRight, SIDE_RIGHT, itemRight, rightStrategy, valueExpression, task, result);
itemDelta.setValuesToReplace(valuesToTake);
}
return itemDelta;
}
} else {
if (rightStrategy == null || rightStrategy == MergeStategyType.IGNORE) {
if (leftStrategy == MergeStategyType.TAKE) {
// TAKE left, IGNORE right
return null;
} else {
// EXPRESSION left, IGNORE right
Collection<PrismValue> valuesToLeave = getValuesToTake(objectLeft, objectRight, SIDE_LEFT, itemLeft, leftStrategy, valueExpression, task, result);
List<PrismValue> currentLeftValues = itemLeft.getValues();
Collection<PrismValue> leftValuesToRemove = diffValues(currentLeftValues, valuesToLeave);
if (leftValuesToRemove != null && !leftValuesToRemove.isEmpty()) {
itemDelta.addValuesToDelete(leftValuesToRemove);
return itemDelta;
} else {
return null;
}
}
} else {
// TAKE/EXPRESSION left, TAKE/EXPRESSION right
if (itemLeft == null) {
Collection<PrismValue> valuesToTake = getValuesToTake(objectLeft, objectRight, SIDE_RIGHT, itemRight, rightStrategy, valueExpression, task, result);
itemDelta.addValuesToAdd(valuesToTake);
return itemDelta;
} else {
// We want to add only those values that are not yet there.
// E.g. adding assignments that are there can cause unnecessary churn
Collection<PrismValue> leftValuesToLeave = getValuesToTake(objectLeft, objectRight, SIDE_LEFT, itemLeft, leftStrategy, valueExpression, task, result);
Collection<PrismValue> rightValuesToTake = getValuesToTake(objectLeft, objectRight, SIDE_RIGHT, itemRight, rightStrategy, valueExpression, task, result);
for (PrismValue rightValueToTake : rightValuesToTake) {
if (!PrismValue.collectionContainsEquivalentValue(leftValuesToLeave, rightValueToTake)) {
itemDelta.addValueToAdd(rightValueToTake);
}
}
List<PrismValue> currentLeftValues = itemLeft.getValues();
Collection<PrismValue> leftValuesToRemove = diffValues(currentLeftValues, leftValuesToLeave);
if (leftValuesToRemove != null && !leftValuesToRemove.isEmpty()) {
itemDelta.addValuesToDelete(leftValuesToRemove);
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Merging item {} T/T case:\n leftValuesToLeave: {}\n rightValuesToTake: {}\n leftValuesToRemove: {}\n itemDelta:\n{}", new Object[] { itemPath, leftValuesToLeave, rightValuesToTake, leftValuesToRemove, itemDelta.debugDump(2) });
}
return itemDelta;
}
}
}
}
Aggregations