Search in sources :

Example 6 with Visitable

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

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

the class CryptoUtil method checkEncrypted.

// Checks that everything is encrypted
public static <T extends ObjectType> void checkEncrypted(final PrismObject<T> object) {
    Visitor visitor = new Visitor() {

        @Override
        public void visit(Visitable visitable) {
            if (!(visitable instanceof PrismPropertyValue)) {
                return;
            }
            PrismPropertyValue<?> pval = (PrismPropertyValue<?>) visitable;
            checkEncrypted(pval);
        }
    };
    try {
        object.accept(visitor);
    } catch (IllegalStateException e) {
        throw new IllegalStateException(e.getMessage() + " in " + object, e);
    }
}
Also used : Visitor(com.evolveum.midpoint.prism.Visitor) Visitable(com.evolveum.midpoint.prism.Visitable) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 8 with Visitable

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

the class CryptoUtil method checkEncrypted.

// Checks that everything is encrypted
public static <T extends ObjectType> void checkEncrypted(final ObjectDelta<T> delta) {
    Visitor visitor = new Visitor() {

        @Override
        public void visit(Visitable visitable) {
            if (!(visitable instanceof PrismPropertyValue)) {
                return;
            }
            PrismPropertyValue<?> pval = (PrismPropertyValue<?>) visitable;
            checkEncrypted(pval);
        }
    };
    try {
        delta.accept(visitor);
    } catch (IllegalStateException e) {
        throw new IllegalStateException(e.getMessage() + " in delta " + delta, e);
    }
}
Also used : Visitor(com.evolveum.midpoint.prism.Visitor) Visitable(com.evolveum.midpoint.prism.Visitable) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Example 9 with Visitable

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

the class CryptoUtil method checkEncrypted.

public static void checkEncrypted(Collection<? extends ItemDelta> modifications) {
    Visitor visitor = new Visitor() {

        @Override
        public void visit(Visitable visitable) {
            if (!(visitable instanceof PrismPropertyValue)) {
                return;
            }
            PrismPropertyValue<?> pval = (PrismPropertyValue<?>) visitable;
            checkEncrypted(pval);
        }
    };
    for (ItemDelta<?, ?> delta : modifications) {
        try {
            delta.accept(visitor);
        } catch (IllegalStateException e) {
            throw new IllegalStateException(e.getMessage() + " in modification " + delta, e);
        }
    }
}
Also used : Visitor(com.evolveum.midpoint.prism.Visitor) Visitable(com.evolveum.midpoint.prism.Visitable) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Aggregations

Visitable (com.evolveum.midpoint.prism.Visitable)9 Visitor (com.evolveum.midpoint.prism.Visitor)9 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)3 Item (com.evolveum.midpoint.prism.Item)2 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)2 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)2 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)2 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)1 Objectable (com.evolveum.midpoint.prism.Objectable)1 OriginType (com.evolveum.midpoint.prism.OriginType)1 PrismContainer (com.evolveum.midpoint.prism.PrismContainer)1 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)1 PrismValue (com.evolveum.midpoint.prism.PrismValue)1 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)1 CompareResult (com.evolveum.midpoint.prism.path.ItemPath.CompareResult)1 PrimitiveXNode (com.evolveum.midpoint.prism.xnode.PrimitiveXNode)1 GetOperationOptions (com.evolveum.midpoint.schema.GetOperationOptions)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 HttpConnectionInformation (com.evolveum.midpoint.security.api.HttpConnectionInformation)1