Search in sources :

Example 1 with MergeConfigurationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.MergeConfigurationType in project midpoint by Evolveum.

the class ObjectMerger method computeProjectionDeltas.

private <O extends ObjectType> void computeProjectionDeltas(final ObjectDelta<O> leftLinkDelta, ObjectDelta<O> rightLinkDelta, final PrismObject<O> objectLeft, final PrismObject<O> objectRight, MergeConfigurationType mergeConfiguration, final String mergeConfigurationName, final Task task, final OperationResult result) throws SchemaException, ConfigurationException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException, SecurityViolationException {
    List<ShadowType> projectionsLeft = getProjections(objectLeft, task, result);
    List<ShadowType> projectionsRight = getProjections(objectRight, task, result);
    List<ShadowType> mergedProjections = new ArrayList<>();
    List<ShadowType> matchedProjections = new ArrayList<>();
    ProjectionMergeConfigurationType defaultProjectionMergeConfig = null;
    for (ProjectionMergeConfigurationType projectionMergeConfig : mergeConfiguration.getProjection()) {
        if (projectionMergeConfig.getProjectionDiscriminator() == null && projectionMergeConfig.getSituation() == null) {
            defaultProjectionMergeConfig = projectionMergeConfig;
        } else {
            takeProjections(projectionMergeConfig.getLeft(), mergedProjections, matchedProjections, projectionsLeft, projectionsLeft, projectionsRight, projectionMergeConfig);
            takeProjections(projectionMergeConfig.getRight(), mergedProjections, matchedProjections, projectionsRight, projectionsLeft, projectionsRight, projectionMergeConfig);
        }
    }
    LOGGER.trace("Merged projections (before default): {}", mergedProjections);
    LOGGER.trace("Matched projections (before default): {}", matchedProjections);
    if (defaultProjectionMergeConfig != null) {
        takeUnmatchedProjections(defaultProjectionMergeConfig.getLeft(), mergedProjections, matchedProjections, projectionsLeft);
        takeUnmatchedProjections(defaultProjectionMergeConfig.getRight(), mergedProjections, matchedProjections, projectionsRight);
    }
    LOGGER.trace("Merged projections: {}", mergedProjections);
    checkConflict(mergedProjections);
    for (ShadowType mergedProjection : mergedProjections) {
        PrismReferenceValue leftLinkRef = findLinkRef(objectLeft, mergedProjection);
        if (leftLinkRef == null) {
            PrismReferenceValue linkRefRight = findLinkRef(objectRight, mergedProjection);
            LOGGER.trace("Moving projection right->left: {}", mergedProjection);
            addUnlinkDelta(rightLinkDelta, linkRefRight);
            addLinkDelta(leftLinkDelta, linkRefRight);
        } else {
            LOGGER.trace("Projection already at the left: {}", mergedProjection);
        }
    }
    for (PrismReferenceValue leftLinkRef : getLinkRefs(objectLeft)) {
        if (!hasProjection(mergedProjections, leftLinkRef)) {
            LOGGER.trace("Removing left projection: {}", leftLinkRef);
            addUnlinkDelta(leftLinkDelta, leftLinkRef);
        } else {
            LOGGER.trace("Left projection stays: {}", leftLinkRef);
        }
    }
}
Also used : ProjectionMergeConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ProjectionMergeConfigurationType) PrismReferenceValue(com.evolveum.midpoint.prism.PrismReferenceValue) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList)

Example 2 with MergeConfigurationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.MergeConfigurationType in project midpoint by Evolveum.

the class ObjectMerger method computeItemDeltas.

private <O extends ObjectType> void computeItemDeltas(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 {
    for (ItemRefMergeConfigurationType itemMergeConfig : mergeConfiguration.getItem()) {
        ItemPath itemPath = itemMergeConfig.getRef().getItemPath();
        processedPaths.add(itemPath);
        ItemDelta itemDelta = mergeItem(objectLeft, objectRight, mergeConfigurationName, itemMergeConfig, itemPath, task, result);
        LOGGER.trace("Item {} delta: {}", itemPath, itemDelta);
        if (itemDelta != null && !itemDelta.isEmpty()) {
            leftObjectDelta.addModification(itemDelta);
        }
    }
}
Also used : ItemRefMergeConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ItemRefMergeConfigurationType) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 3 with MergeConfigurationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.MergeConfigurationType in project midpoint by Evolveum.

the class MergeObjectsPanel method getMergeTypeNames.

private List<String> getMergeTypeNames() {
    List<String> mergeTypeNamesList = new ArrayList<>();
    Task task = pageBase.createAnonymousTask(OPERATION_LOAD_MERGE_TYPE_NAMES);
    OperationResult result = task.getResult();
    PrismObject<SystemConfigurationType> config;
    try {
        config = pageBase.getModelService().getObject(SystemConfigurationType.class, SystemObjectsType.SYSTEM_CONFIGURATION.value(), null, task, result);
    } catch (ObjectNotFoundException | SchemaException | SecurityViolationException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
        LOGGER.error("Error getting system configuration: {}", e.getMessage(), e);
        return null;
    }
    if (config != null && config.asObjectable() != null) {
        List<MergeConfigurationType> list = config.asObjectable().getMergeConfiguration();
        if (list != null) {
            for (MergeConfigurationType mergeType : list) {
                mergeTypeNamesList.add(mergeType.getName());
            }
            if (mergeTypeNamesList.size() > 0) {
                currentMergeType = mergeTypeNamesList.get(0);
            }
        }
    }
    return mergeTypeNamesList;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) MergeConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.MergeConfigurationType) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)

Example 4 with MergeConfigurationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.MergeConfigurationType in project midpoint by Evolveum.

the class ObjectMerger method computeMergeDeltas.

public <O extends ObjectType> MergeDeltas<O> computeMergeDeltas(Class<O> type, String leftOid, String rightOid, final String mergeConfigurationName, final Task task, final OperationResult result) throws ObjectNotFoundException, SchemaException, ConfigurationException, ExpressionEvaluationException, CommunicationException, SecurityViolationException {
    final PrismObject<O> objectLeft = (PrismObject<O>) objectResolver.getObjectSimple(type, leftOid, null, task, result).asPrismObject();
    final PrismObject<O> objectRight = (PrismObject<O>) objectResolver.getObjectSimple(type, rightOid, null, task, result).asPrismObject();
    PrismObject<SystemConfigurationType> systemConfiguration = systemObjectCache.getSystemConfiguration(result);
    MergeConfigurationType mergeConfiguration = selectConfiguration(systemConfiguration, mergeConfigurationName);
    if (mergeConfiguration == null) {
        throw new ConfigurationException("No merge configuration defined");
    }
    // The "left" object is always the one that will be the result. We will use its OID.
    final ObjectDelta<O> leftObjectDelta = objectLeft.createModifyDelta();
    final ObjectDelta<O> leftLinkDelta = objectLeft.createModifyDelta();
    final ObjectDelta<O> rightLinkDelta = objectRight.createModifyDelta();
    final List<ItemPath> processedPaths = new ArrayList<>();
    computeItemDeltas(leftObjectDelta, objectLeft, objectRight, processedPaths, mergeConfiguration, mergeConfigurationName, task, result);
    computeDefaultDeltas(leftObjectDelta, objectLeft, objectRight, processedPaths, mergeConfiguration, mergeConfigurationName, task, result);
    computeProjectionDeltas(leftLinkDelta, rightLinkDelta, objectLeft, objectRight, mergeConfiguration, mergeConfigurationName, task, result);
    return new MergeDeltas<>(leftObjectDelta, leftLinkDelta, rightLinkDelta);
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) MergeDeltas(com.evolveum.midpoint.model.api.util.MergeDeltas) ProjectionMergeConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ProjectionMergeConfigurationType) ItemRefMergeConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ItemRefMergeConfigurationType) MergeConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.MergeConfigurationType) ItemMergeConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ItemMergeConfigurationType) ArrayList(java.util.ArrayList) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 5 with MergeConfigurationType

use of com.evolveum.midpoint.xml.ns._public.common.common_3.MergeConfigurationType 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)

Aggregations

ItemPath (com.evolveum.midpoint.prism.path.ItemPath)3 ArrayList (java.util.ArrayList)3 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)2 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)2 ItemMergeConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ItemMergeConfigurationType)2 ItemRefMergeConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ItemRefMergeConfigurationType)2 MergeConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.MergeConfigurationType)2 ProjectionMergeConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ProjectionMergeConfigurationType)2 SystemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)2 MergeDeltas (com.evolveum.midpoint.model.api.util.MergeDeltas)1 Item (com.evolveum.midpoint.prism.Item)1 PrismContainer (com.evolveum.midpoint.prism.PrismContainer)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)1 Visitable (com.evolveum.midpoint.prism.Visitable)1 Visitor (com.evolveum.midpoint.prism.Visitor)1 CompareResult (com.evolveum.midpoint.prism.path.ItemPath.CompareResult)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 Task (com.evolveum.midpoint.task.api.Task)1 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)1