From 3057a90e43f562b216da7f56407497b26a586c64 Mon Sep 17 00:00:00 2001 From: Radovan Semancik Date: Thu, 27 Oct 2016 19:56:00 +0200 Subject: [PATCH] Fixing projection handling in object merge (MID-3460) --- .../model/impl/controller/ObjectMerger.java | 33 +++++++++++-------- .../midpoint/model/intest/TestMerge.java | 4 +-- .../resources/common/system-configuration.xml | 5 +-- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/controller/ObjectMerger.java b/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/controller/ObjectMerger.java index d966a2770c6..8299d4b3ba7 100644 --- a/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/controller/ObjectMerger.java +++ b/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/controller/ObjectMerger.java @@ -411,25 +411,30 @@ private List getProjections(PrismObject ob private void takeProjections(MergeStategyType strategy, List mergedProjections, List matchedProjections, List candidateProjections, ShadowDiscriminatorType discriminatorType) { - if (strategy == MergeStategyType.TAKE) { - - LOGGER.trace("TAKE: Evaluating discriminator: {}", discriminatorType); - - for (ShadowType candidateProjection: candidateProjections) { - if (ShadowUtil.matchesPattern(candidateProjection, discriminatorType)) { - LOGGER.trace("Discriminator matches {}", candidateProjection); + + LOGGER.trace("TAKE: Evaluating discriminator: {}", discriminatorType); + + for (ShadowType candidateProjection: candidateProjections) { + if (ShadowUtil.matchesPattern(candidateProjection, discriminatorType)) { + LOGGER.trace("Discriminator matches {}", candidateProjection); + matchedProjections.add(candidateProjection); + + if (strategy == MergeStategyType.TAKE) { mergedProjections.add(candidateProjection); - matchedProjections.add(candidateProjection); + + } else if (strategy == null || strategy == MergeStategyType.IGNORE) { + // Nothing to do here + } else { - LOGGER.trace("Discriminator does NOT match {}", candidateProjection); + throw new UnsupportedOperationException("Merge strategy "+strategy+" is not supported"); } + + } else { + LOGGER.trace("Discriminator does NOT match {}", candidateProjection); } - - } else if (strategy == null || strategy == MergeStategyType.IGNORE) { - return; - } else { - throw new UnsupportedOperationException("Merge strategy "+strategy+" is not supported"); } + + } private void takeUnmatchedProjections(MergeStategyType strategy, List mergedProjections, diff --git a/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/TestMerge.java b/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/TestMerge.java index 5a4f9f5e69a..715659a0a52 100644 --- a/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/TestMerge.java +++ b/model/model-intest/src/test/java/com/evolveum/midpoint/model/intest/TestMerge.java @@ -274,10 +274,10 @@ public void test110MergeGuybrushJackPreviewDelta() throws Exception { PrismAsserts.assertNoItemDelta(delta, UserType.F_LINK_REF); ObjectDelta leftLinkDelta = deltas.getLeftLinkDelta(); - PrismAsserts.assertEmpty("leftLinkDelta", leftLinkDelta); + PrismAsserts.assertReferenceAdd(leftLinkDelta, UserType.F_LINK_REF, jackDummyAccountRedOid); ObjectDelta rightLinkDelta = deltas.getRightLinkDelta(); - PrismAsserts.assertEmpty("rightLinkDelta", rightLinkDelta); + PrismAsserts.assertReferenceDelete(rightLinkDelta, UserType.F_LINK_REF, jackDummyAccountRedOid); } /** diff --git a/model/model-intest/src/test/resources/common/system-configuration.xml b/model/model-intest/src/test/resources/common/system-configuration.xml index 22bf8a8a66c..8e43e39bd12 100644 --- a/model/model-intest/src/test/resources/common/system-configuration.xml +++ b/model/model-intest/src/test/resources/common/system-configuration.xml @@ -227,13 +227,14 @@ take - take + take - + take + take take