Search in sources :

Example 11 with Visitor

use of com.evolveum.midpoint.prism.Visitor 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 12 with Visitor

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

the class ObjectMerger method computeDefaultDeltas.

private <O extends ObjectType> void computeDefaultDeltas(final ObjectDelta<O> leftObjectDelta, final PrismObject<O> objectLeft, final PrismObject<O> objectRight, final List<ItemPath> processedPaths, MergeConfigurationType mergeConfiguration, final String mergeConfigurationName, final Task task, final OperationResult result) throws SchemaException, ConfigurationException, ExpressionEvaluationException, ObjectNotFoundException {
    final ItemMergeConfigurationType defaultItemMergeConfig = mergeConfiguration.getDefault();
    if (defaultItemMergeConfig != null) {
        try {
            Visitor visitor = new Visitor() {

                @Override
                public void visit(Visitable visitable) {
                    if (!(visitable instanceof Item)) {
                        return;
                    }
                    Item item = (Item) visitable;
                    ItemPath itemPath = item.getPath();
                    if (itemPath == null || itemPath.isEmpty()) {
                        return;
                    }
                    if (SchemaConstants.PATH_LINK_REF.equivalent(itemPath)) {
                        // Skip. There is a special processing for this.
                        return;
                    }
                    boolean found = false;
                    for (ItemPath processedPath : processedPaths) {
                        // Need to check for super-paths here.
                        // E.g. if we have already processed metadata, we do not want to process
                        // metadata/modifyTimestamp
                        CompareResult compareResult = processedPath.compareComplex(itemPath);
                        if (compareResult == CompareResult.EQUIVALENT || compareResult == CompareResult.SUBPATH) {
                            found = true;
                            break;
                        }
                    }
                    if (found) {
                        return;
                    }
                    processedPaths.add(itemPath);
                    if (item instanceof PrismContainer<?>) {
                        if (item.getDefinition().isSingleValue()) {
                            // we will handle every individual property there.
                            return;
                        } else {
                        // TODO: we may need special handling for multi-value containers
                        // such as assignment
                        }
                    }
                    ItemDelta itemDelta;
                    try {
                        itemDelta = mergeItem(objectLeft, objectRight, mergeConfigurationName, defaultItemMergeConfig, itemPath, task, result);
                    } catch (SchemaException | ConfigurationException | ExpressionEvaluationException | ObjectNotFoundException e) {
                        throw new TunnelException(e);
                    }
                    LOGGER.trace("Item {} delta (default): {}", itemPath, itemDelta);
                    if (itemDelta != null && !itemDelta.isEmpty()) {
                        leftObjectDelta.addModification(itemDelta);
                    }
                }
            };
            objectLeft.accept(visitor);
            objectRight.accept(visitor);
        } catch (TunnelException te) {
            if (te.getCause() instanceof SchemaException) {
                throw (SchemaException) te.getCause();
            } else if (te.getCause() instanceof ConfigurationException) {
                throw (ConfigurationException) te.getCause();
            } else if (te.getCause() instanceof ExpressionEvaluationException) {
                throw (ExpressionEvaluationException) te.getCause();
            } else if (te.getCause() instanceof ObjectNotFoundException) {
                throw (ObjectNotFoundException) te.getCause();
            } else {
                throw new SystemException("Unexpected exception: " + te, te);
            }
        }
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) Visitor(com.evolveum.midpoint.prism.Visitor) Visitable(com.evolveum.midpoint.prism.Visitable) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ItemMergeConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ItemMergeConfigurationType) CompareResult(com.evolveum.midpoint.prism.path.ItemPath.CompareResult) Item(com.evolveum.midpoint.prism.Item) TunnelException(com.evolveum.midpoint.util.exception.TunnelException) SystemException(com.evolveum.midpoint.util.exception.SystemException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) PrismContainer(com.evolveum.midpoint.prism.PrismContainer) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 13 with Visitor

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

the class ModelController method removeOperationalItems.

// TODO write in cleaner way
private <T extends ObjectType> void removeOperationalItems(PrismObject<T> object) {
    if (object == null) {
        return;
    }
    final List<ItemPath> operationalItems = new ArrayList<>();
    object.accept(new Visitor() {

        @Override
        public void visit(Visitable visitable) {
            if (visitable instanceof Item) {
                Item item = ((Item) visitable);
                if (item.getDefinition() != null && item.getDefinition().isOperational()) {
                    operationalItems.add(item.getPath());
                // it would be nice if we could stop visiting children here but that's not possible now
                }
            }
        }
    });
    LOGGER.trace("Operational items: {}", operationalItems);
    removeIgnoredItems(object, operationalItems);
}
Also used : Visitor(com.evolveum.midpoint.prism.Visitor) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

Visitor (com.evolveum.midpoint.prism.Visitor)13 Visitable (com.evolveum.midpoint.prism.Visitable)9 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)3 Item (com.evolveum.midpoint.prism.Item)2 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)2 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)2 SystemException (com.evolveum.midpoint.util.exception.SystemException)2 Collection (java.util.Collection)2 CryptoUtil (com.evolveum.midpoint.common.crypto.CryptoUtil)1 RefinedObjectClassDefinition (com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition)1 RefinedResourceSchema (com.evolveum.midpoint.common.refinery.RefinedResourceSchema)1 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)1 ScriptExpression (com.evolveum.midpoint.model.common.expression.script.ScriptExpression)1 ModelConstants (com.evolveum.midpoint.model.impl.ModelConstants)1 ExpressionEnvironment (com.evolveum.midpoint.model.impl.expr.ExpressionEnvironment)1