Search in sources :

Example 1 with ProjectionMergeConfigurationType

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

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

the class ObjectMerger method takeProjections.

private void takeProjections(MergeStategyType strategy, List<ShadowType> mergedProjections, List<ShadowType> matchedProjections, List<ShadowType> candidateProjections, List<ShadowType> projectionsLeft, List<ShadowType> projectionsRight, ProjectionMergeConfigurationType projectionMergeConfig) {
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("TAKE: Evaluating situation {}, discriminator: {}", projectionMergeConfig.getSituation(), projectionMergeConfig.getProjectionDiscriminator());
    }
    for (ShadowType candidateProjection : candidateProjections) {
        if (projectionMatches(candidateProjection, projectionsLeft, projectionsRight, projectionMergeConfig)) {
            LOGGER.trace("Projection matches {}", candidateProjection);
            matchedProjections.add(candidateProjection);
            if (strategy == MergeStategyType.TAKE) {
                mergedProjections.add(candidateProjection);
            } else if (strategy == null || strategy == MergeStategyType.IGNORE) {
            // Nothing to do here
            } else {
                throw new UnsupportedOperationException("Merge strategy " + strategy + " is not supported");
            }
        } else {
            LOGGER.trace("Discriminator does NOT match {}", candidateProjection);
        }
    }
}
Also used : ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)

Example 3 with ProjectionMergeConfigurationType

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

the class ObjectMerger method projectionMatches.

private boolean projectionMatches(ShadowType candidateProjection, List<ShadowType> projectionsLeft, List<ShadowType> projectionsRight, ProjectionMergeConfigurationType projectionMergeConfig) {
    ShadowDiscriminatorType discriminatorType = projectionMergeConfig.getProjectionDiscriminator();
    if (discriminatorType != null && !ShadowUtil.matchesPattern(candidateProjection, discriminatorType)) {
        return false;
    }
    ProjectionMergeSituationType situationPattern = projectionMergeConfig.getSituation();
    if (situationPattern != null) {
        ProjectionMergeSituationType projectionSituation = determineSituation(candidateProjection, projectionsLeft, projectionsRight);
        if (situationPattern != projectionSituation) {
            return false;
        }
    }
    return true;
}
Also used : ProjectionMergeSituationType(com.evolveum.midpoint.xml.ns._public.common.common_3.ProjectionMergeSituationType) ShadowDiscriminatorType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowDiscriminatorType)

Aggregations

ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)2 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)1 ProjectionMergeConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ProjectionMergeConfigurationType)1 ProjectionMergeSituationType (com.evolveum.midpoint.xml.ns._public.common.common_3.ProjectionMergeSituationType)1 ShadowDiscriminatorType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowDiscriminatorType)1 ArrayList (java.util.ArrayList)1