use of com.evolveum.midpoint.prism.PrismValue 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;
}
}
}
}
use of com.evolveum.midpoint.prism.PrismValue in project midpoint by Evolveum.
the class AddExecutor method execute.
@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
boolean raw = getParamRaw(expression, input, context, globalResult);
boolean dryRun = getParamDryRun(expression, input, context, globalResult);
for (PipelineItem item : input.getData()) {
OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
context.checkTaskStop();
PrismValue value = item.getValue();
if (value instanceof PrismObjectValue) {
@SuppressWarnings({ "unchecked", "raw" }) PrismObject<? extends ObjectType> prismObject = ((PrismObjectValue) value).asPrismObject();
ObjectType objectType = prismObject.asObjectable();
long started = operationsHelper.recordStart(context, objectType);
Throwable exception = null;
try {
operationsHelper.applyDelta(createAddDelta(objectType), operationsHelper.createExecutionOptions(raw), dryRun, context, result);
operationsHelper.recordEnd(context, objectType, started, null);
} catch (Throwable ex) {
operationsHelper.recordEnd(context, objectType, started, ex);
exception = processActionException(ex, NAME, value, context);
}
context.println((exception != null ? "Attempted to add " : "Added ") + prismObject.toString() + rawDrySuffix(raw, dryRun) + exceptionSuffix(exception));
} else {
//noinspection ThrowableNotThrown
processActionException(new ScriptExecutionException("Item is not a PrismObject"), NAME, value, context);
}
operationsHelper.trimAndCloneResult(result, globalResult, context);
}
return input;
}
use of com.evolveum.midpoint.prism.PrismValue in project midpoint by Evolveum.
the class GenerateValueExecutor method execute.
@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
PolicyItemsDefinitionType itemsDefinition = expressionHelper.getSingleArgumentValue(expression.getParameter(), PARAMETER_ITEMS, false, false, PARAMETER_ITEMS, input, context, PolicyItemsDefinitionType.class, globalResult);
if (itemsDefinition == null) {
itemsDefinition = new PolicyItemsDefinitionType().policyItemDefinition(new PolicyItemDefinitionType().target(new PolicyItemTargetType().path(new ItemPathType(new ItemPath(UserType.F_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_VALUE)))).execute(false));
}
for (PipelineItem item : input.getData()) {
PrismValue value = item.getValue();
OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
context.checkTaskStop();
if (value instanceof PrismObjectValue) {
PrismObject<? extends ObjectType> object = ((PrismObjectValue) value).asPrismObject();
ObjectType objectBean = object.asObjectable();
long started = operationsHelper.recordStart(context, objectBean);
Throwable exception = null;
try {
LOGGER.trace("Generating value(s) for {}", objectBean);
modelInteraction.generateValue(object, itemsDefinition, context.getTask(), result);
operationsHelper.recordEnd(context, objectBean, started, null);
} catch (Throwable e) {
operationsHelper.recordEnd(context, objectBean, started, e);
exception = processActionException(e, NAME, value, context);
}
context.println((exception != null ? "Attempted to generate value(s) for " : "Generated value(s) for ") + objectBean.toString() + exceptionSuffix(exception));
} else {
//noinspection ThrowableNotThrown
processActionException(new ScriptExecutionException("Item is not a PrismObject"), NAME, value, context);
}
operationsHelper.trimAndCloneResult(result, globalResult, context);
}
return input;
}
use of com.evolveum.midpoint.prism.PrismValue in project midpoint by Evolveum.
the class NotifyExecutor method execute.
@Override
public PipelineData execute(ActionExpressionType expression, PipelineData input, ExecutionContext context, OperationResult globalResult) throws ScriptExecutionException {
String subtype = expressionHelper.getArgumentAsString(expression.getParameter(), PARAM_SUBTYPE, input, context, null, PARAM_SUBTYPE, globalResult);
EventHandlerType handler = expressionHelper.getSingleArgumentValue(expression.getParameter(), PARAM_HANDLER, false, false, PARAM_HANDLER, input, context, EventHandlerType.class, globalResult);
EventStatusType status = expressionHelper.getSingleArgumentValue(expression.getParameter(), PARAM_STATUS, false, false, PARAM_STATUS, input, context, EventStatusType.class, globalResult);
EventOperationType operation = expressionHelper.getSingleArgumentValue(expression.getParameter(), PARAM_OPERATION, false, false, PARAM_OPERATION, input, context, EventOperationType.class, globalResult);
boolean forWholeInput = expressionHelper.getArgumentAsBoolean(expression.getParameter(), PARAM_FOR_WHOLE_INPUT, input, context, false, PARAM_SUBTYPE, globalResult);
if (handler != null) {
// TODO explain that the reason is that handler is not null
checkRootAuthorization(globalResult, NAME);
}
if (status == null) {
status = EventStatusType.SUCCESS;
}
if (operation == null) {
operation = EventOperationType.ADD;
}
if (notificationManager == null) {
throw new IllegalStateException("Notification manager is unavailable");
}
int eventCount = 0;
if (forWholeInput) {
Event event = new CustomEvent(lightweightIdentifierGenerator, subtype, handler, input.getData(), operation, status, context.getChannel());
notificationManager.processEvent(event, context.getTask(), globalResult);
eventCount++;
} else {
for (PipelineItem item : input.getData()) {
PrismValue value = item.getValue();
OperationResult result = operationsHelper.createActionResult(item, this, context, globalResult);
context.checkTaskStop();
Event event = new CustomEvent(lightweightIdentifierGenerator, subtype, handler, value, operation, status, context.getChannel());
notificationManager.processEvent(event, context.getTask(), result);
eventCount++;
operationsHelper.trimAndCloneResult(result, globalResult, context);
}
}
context.println("Produced " + eventCount + " event(s)");
return input;
}
use of com.evolveum.midpoint.prism.PrismValue in project midpoint by Evolveum.
the class FilterContentEvaluator method evaluate.
public PipelineData evaluate(FilterContentExpressionType expression, PipelineData input, ExecutionContext context, OperationResult result) throws ScriptExecutionException {
List<ItemPath> keep = convert(expression.getKeep());
List<ItemPath> remove = convert(expression.getRemove());
if (keep.isEmpty() && remove.isEmpty()) {
// nothing to do here
return input;
}
for (PipelineItem pipelineItem : input.getData()) {
PrismValue value = pipelineItem.getValue();
if (!(value instanceof PrismContainerValue)) {
String message = "In 'select' commands in keep/remove mode, we can act only on prism container values, not on " + value;
if (context.isContinueOnAnyError()) {
LOGGER.error(message);
} else {
throw new ScriptExecutionException(message);
}
} else {
PrismContainerValue<?> pcv = (PrismContainerValue) value;
if (!keep.isEmpty()) {
pcv.keepPaths(keep);
} else {
pcv.removePaths(remove);
}
}
}
return input;
}
Aggregations