Search in sources :

Example 21 with PrismValue

use of com.evolveum.midpoint.prism.PrismValue in project midpoint by Evolveum.

the class GeneralNotifier method appendModifications.

protected void appendModifications(StringBuilder body, ObjectDelta<? extends ObjectType> delta, List<ItemPath> hiddenPaths, Boolean showValuesBoolean) {
    boolean showValues = !Boolean.FALSE.equals(showValuesBoolean);
    for (ItemDelta<?, ?> itemDelta : delta.getModifications()) {
        if (NotificationFunctionsImpl.isAmongHiddenPaths(itemDelta.getPath(), hiddenPaths)) {
            continue;
        }
        body.append(" - ");
        body.append(formatPath(itemDelta));
        if (showValues) {
            body.append(":\n");
            if (itemDelta.isAdd()) {
                for (PrismValue prismValue : itemDelta.getValuesToAdd()) {
                    body.append(" --- ADD: ");
                    body.append(prismValue.debugDump(2));
                    body.append("\n");
                }
            }
            if (itemDelta.isDelete()) {
                for (PrismValue prismValue : itemDelta.getValuesToDelete()) {
                    body.append(" --- DELETE: ");
                    body.append(prismValue.debugDump(2));
                    body.append("\n");
                }
            }
            if (itemDelta.isReplace()) {
                for (PrismValue prismValue : itemDelta.getValuesToReplace()) {
                    body.append(" --- REPLACE: ");
                    body.append(prismValue.debugDump(2));
                    body.append("\n");
                }
            }
        } else {
            body.append("\n");
        }
    }
}
Also used : PrismValue(com.evolveum.midpoint.prism.PrismValue)

Example 22 with PrismValue

use of com.evolveum.midpoint.prism.PrismValue in project midpoint by Evolveum.

the class PrismValueDeltaSetTriple method checkConsistence.

public void checkConsistence() {
    Visitor visitor = visitable -> {
        if (visitable instanceof PrismValue) {
            if (((PrismValue) visitable).isEmpty()) {
                throw new IllegalStateException("Empty value " + visitable + " in triple " + PrismValueDeltaSetTriple.this);
            }
        }
    };
    accept(visitor);
    Processor<V> processor = pval -> {
        if (pval.getParent() != null) {
            throw new IllegalStateException("Value " + pval + " in triple " + PrismValueDeltaSetTriple.this + " has parent, looks like it was not cloned properly");
        }
    };
    foreach(processor);
}
Also used : PrismValue(com.evolveum.midpoint.prism.PrismValue) Iterator(java.util.Iterator) Objectable(com.evolveum.midpoint.prism.Objectable) Collection(java.util.Collection) Visitable(com.evolveum.midpoint.prism.Visitable) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) Cloner(com.evolveum.midpoint.util.Cloner) Visitor(com.evolveum.midpoint.prism.Visitor) Processor(com.evolveum.midpoint.util.Processor) OriginType(com.evolveum.midpoint.prism.OriginType) DebugDumpable(com.evolveum.midpoint.util.DebugDumpable) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) Visitor(com.evolveum.midpoint.prism.Visitor) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Example 23 with PrismValue

use of com.evolveum.midpoint.prism.PrismValue in project midpoint by Evolveum.

the class WrapperTestUtil method assertPropertyWrapperValues.

public static <C extends Containerable, T> void assertPropertyWrapperValues(String desc, List<ValueWrapper> valueWrappers, T... expectedValues) {
    if (expectedValues == null) {
        expectedValues = (T[]) new Object[] { null };
    }
    assertEquals("Wrong number of values in " + desc + "; was: " + valueWrappers + ", expected: " + Arrays.toString(expectedValues), expectedValues.length, valueWrappers.size());
    if (expectedValues.length == 0) {
        return;
    }
    for (ValueWrapper vw : valueWrappers) {
        PrismValue actualPval = vw.getValue();
        if (actualPval instanceof PrismPropertyValue<?>) {
            T actualValue = ((PrismPropertyValue<T>) actualPval).getValue();
            boolean found = false;
            for (T expectedValue : expectedValues) {
                if (MiscUtil.equals(expectedValue, actualValue)) {
                    found = true;
                }
            }
            if (!found) {
                AssertJUnit.fail("Unexpected value " + actualValue + " in value wrapper in " + desc + "; was: " + valueWrappers + ", expected: " + Arrays.toString(expectedValues));
            }
        } else {
            AssertJUnit.fail("expected PrismPropertyValue in value wrapper in " + desc + ", but got " + actualPval.getClass());
        }
    }
}
Also used : ValueWrapper(com.evolveum.midpoint.web.component.prism.ValueWrapper) PrismObject(com.evolveum.midpoint.prism.PrismObject) PrismValue(com.evolveum.midpoint.prism.PrismValue) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 24 with PrismValue

use of com.evolveum.midpoint.prism.PrismValue in project midpoint by Evolveum.

the class AbstractValueTransformationExpressionEvaluator method evaluateRelativeExpression.

private PrismValueDeltaSetTriple<V> evaluateRelativeExpression(final List<SourceTriple<?, ?>> sourceTriples, final ExpressionVariables variables, final boolean skipEvaluationMinus, final boolean skipEvaluationPlus, final Boolean includeNulls, final ExpressionEvaluationContext evaluationContext, final String contextDescription, final Task task, final OperationResult result) throws ExpressionEvaluationException, ObjectNotFoundException, SchemaException {
    List<Collection<? extends PrismValue>> valueCollections = new ArrayList<>(sourceTriples.size());
    for (SourceTriple<?, ?> sourceTriple : sourceTriples) {
        Collection<? extends PrismValue> values = sourceTriple.union();
        if (values.isEmpty()) {
            // No values for this source. Add null instead. It will make sure that the expression will
            // be evaluate at least once.
            values.add(null);
        }
        valueCollections.add(values);
    }
    final PrismValueDeltaSetTriple<V> outputTriple = new PrismValueDeltaSetTriple<>();
    Processor<Collection<? extends PrismValue>> processor = pvalues -> {
        if (includeNulls != null && !includeNulls && MiscUtil.isAllNull(pvalues)) {
            return;
        }
        Map<QName, Object> sourceVariables = new HashMap<>();
        Iterator<SourceTriple<PrismValue, ?>> sourceTriplesIterator = (Iterator) sourceTriples.iterator();
        boolean hasMinus = false;
        boolean hasZero = false;
        boolean hasPlus = false;
        for (PrismValue pval : pvalues) {
            SourceTriple<PrismValue, ?> sourceTriple = sourceTriplesIterator.next();
            QName name = sourceTriple.getName();
            sourceVariables.put(name, getRealContent(pval, sourceTriple.getResidualPath()));
            if (sourceTriple.presentInPlusSet(pval)) {
                hasPlus = true;
            } else if (sourceTriple.presentInZeroSet(pval)) {
                hasZero = true;
            } else if (sourceTriple.presentInMinusSet(pval)) {
                hasMinus = true;
            }
        }
        if (!hasPlus && !hasMinus && !hasZero && !MiscUtil.isAllNull(pvalues)) {
            throw new IllegalStateException("Internal error! The impossible has happened! pvalues=" + pvalues + "; source triples: " + sourceTriples + "; in " + contextDescription);
        }
        if (hasPlus && hasMinus) {
            return;
        }
        if (hasPlus && skipEvaluationPlus) {
            return;
        } else if (hasMinus && skipEvaluationMinus) {
            return;
        }
        ExpressionVariables scriptVariables = new ExpressionVariables();
        scriptVariables.addVariableDefinitions(sourceVariables);
        PlusMinusZero valueDestination = null;
        boolean useNew = false;
        if (hasPlus) {
            scriptVariables.addVariableDefinitionsNew(variables);
            valueDestination = PlusMinusZero.PLUS;
            useNew = true;
        } else if (hasMinus) {
            scriptVariables.addVariableDefinitionsOld(variables);
            valueDestination = PlusMinusZero.MINUS;
        } else {
            scriptVariables.addVariableDefinitionsNew(variables);
            valueDestination = PlusMinusZero.ZERO;
            useNew = true;
        }
        List<V> scriptResults;
        try {
            scriptResults = transformSingleValue(scriptVariables, valueDestination, useNew, evaluationContext, contextDescription, task, result);
        } catch (ExpressionEvaluationException e) {
            throw new TunnelException(new ExpressionEvaluationException(e.getMessage() + "(" + dumpSourceValues(sourceVariables) + ") in " + contextDescription, e));
        } catch (ObjectNotFoundException e) {
            throw new TunnelException(new ObjectNotFoundException(e.getMessage() + "(" + dumpSourceValues(sourceVariables) + ") in " + contextDescription, e));
        } catch (SchemaException e) {
            throw new TunnelException(new SchemaException(e.getMessage() + "(" + dumpSourceValues(sourceVariables) + ") in " + contextDescription, e));
        } catch (RuntimeException e) {
            throw new TunnelException(new RuntimeException(e.getMessage() + "(" + dumpSourceValues(sourceVariables) + ") in " + contextDescription, e));
        }
        outputTriple.addAllToSet(valueDestination, scriptResults);
    };
    try {
        MiscUtil.carthesian((Collection) valueCollections, (Processor) processor);
    } catch (TunnelException e) {
        Throwable originalException = e.getCause();
        if (originalException instanceof ExpressionEvaluationException) {
            throw (ExpressionEvaluationException) originalException;
        } else if (originalException instanceof ObjectNotFoundException) {
            throw (ObjectNotFoundException) originalException;
        } else if (originalException instanceof SchemaException) {
            throw (SchemaException) originalException;
        } else if (originalException instanceof RuntimeException) {
            throw (RuntimeException) originalException;
        } else {
            throw new IllegalStateException("Unexpected exception: " + e + ": " + e.getMessage(), e);
        }
    }
    cleanupTriple(outputTriple);
    return outputTriple;
}
Also used : PrismValue(com.evolveum.midpoint.prism.PrismValue) ObjectDeltaObject(com.evolveum.midpoint.repo.common.expression.ObjectDeltaObject) SourceTriple(com.evolveum.midpoint.repo.common.expression.SourceTriple) java.util(java.util) Item(com.evolveum.midpoint.prism.Item) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) SecurityEnforcer(com.evolveum.midpoint.security.api.SecurityEnforcer) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) TransformExpressionEvaluatorType(com.evolveum.midpoint.xml.ns._public.common.common_3.TransformExpressionEvaluatorType) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue) Trace(com.evolveum.midpoint.util.logging.Trace) PrettyPrinter(com.evolveum.midpoint.util.PrettyPrinter) ExpressionConstants(com.evolveum.midpoint.schema.constants.ExpressionConstants) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) TransformExpressionRelativityModeType(com.evolveum.midpoint.xml.ns._public.common.common_3.TransformExpressionRelativityModeType) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ExpressionEvaluator(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluator) DeltaSetTriple(com.evolveum.midpoint.prism.delta.DeltaSetTriple) ExpressionSyntaxException(com.evolveum.midpoint.repo.common.expression.ExpressionSyntaxException) PrismValueDeltaSetTriple(com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ItemDeltaItem(com.evolveum.midpoint.repo.common.expression.ItemDeltaItem) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ExpressionEvaluationContext(com.evolveum.midpoint.repo.common.expression.ExpressionEvaluationContext) MiscUtil(com.evolveum.midpoint.util.MiscUtil) Task(com.evolveum.midpoint.task.api.Task) TunnelException(com.evolveum.midpoint.util.exception.TunnelException) ItemPath(com.evolveum.midpoint.prism.path.ItemPath) PlusMinusZero(com.evolveum.midpoint.prism.delta.PlusMinusZero) ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) Processor(com.evolveum.midpoint.util.Processor) Entry(java.util.Map.Entry) Source(com.evolveum.midpoint.repo.common.expression.Source) QName(javax.xml.namespace.QName) TraceManager(com.evolveum.midpoint.util.logging.TraceManager) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) PrismValue(com.evolveum.midpoint.prism.PrismValue) TunnelException(com.evolveum.midpoint.util.exception.TunnelException) ExpressionVariables(com.evolveum.midpoint.repo.common.expression.ExpressionVariables) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismValueDeltaSetTriple(com.evolveum.midpoint.prism.delta.PrismValueDeltaSetTriple) QName(javax.xml.namespace.QName) PlusMinusZero(com.evolveum.midpoint.prism.delta.PlusMinusZero) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) SourceTriple(com.evolveum.midpoint.repo.common.expression.SourceTriple)

Example 25 with PrismValue

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;
            }
        }
    }
}
Also used : ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) MergeStategyType(com.evolveum.midpoint.xml.ns._public.common.common_3.MergeStategyType) ExpressionType(com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType) PrismValue(com.evolveum.midpoint.prism.PrismValue)

Aggregations

PrismValue (com.evolveum.midpoint.prism.PrismValue)31 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)12 PipelineItem (com.evolveum.midpoint.model.api.PipelineItem)8 ScriptExecutionException (com.evolveum.midpoint.model.api.ScriptExecutionException)8 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)8 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)8 Item (com.evolveum.midpoint.prism.Item)6 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)6 ArrayList (java.util.ArrayList)6 PrismObjectValue (com.evolveum.midpoint.prism.PrismObjectValue)5 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)5 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)5 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)5 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)5 QName (javax.xml.namespace.QName)5 PrismObject (com.evolveum.midpoint.prism.PrismObject)4 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)4 PipelineData (com.evolveum.midpoint.model.impl.scripting.PipelineData)2 Objectable (com.evolveum.midpoint.prism.Objectable)2 PrismContainerValue (com.evolveum.midpoint.prism.PrismContainerValue)2