Skip to content

Commit

Permalink
MID-8147: fix for removing value of container in resource type
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Oct 10, 2022
1 parent e37332c commit d348de2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ public static boolean isValueFromResourceTemplate(PrismValue valueFromDelta, Pri
}

private static boolean hasValueMetadata(PrismValue value) {
if (value == null) {
return false;
}

if (value.hasValueMetadata()) {
List<PrismContainerValue<Containerable>> metadataValues = value.getValueMetadata().getValues();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import com.google.common.collect.ImmutableMap;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;

import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -116,7 +116,7 @@ private Collection<ItemDelta<PrismValue, ItemDefinition>> processModifyDeltas(
List<PrismValue> valuesFromTemplate = new ArrayList<>();
delta.getValuesToDelete().forEach(v -> {
if (WebPrismUtil.isValueFromResourceTemplate(v, getItem())
|| WebPrismUtil.isValueFromResourceTemplate(v.getParentContainerValue(), getItem())) {
|| WebPrismUtil.isValueFromResourceTemplate(getParentContainerValue(v), getItem())) {
LOGGER.warn("Couldn't remove value, because is merged from resource template, value: " + v);
valuesFromTemplate.add(v);
}
Expand Down Expand Up @@ -195,7 +195,7 @@ private ItemDelta<PrismValue, ItemDefinition> processAddOrModifyDelta(

private PrismContainerValue<?> createParentValueForAddDelta(
PrismContainerValue<?> origParentValue, Item newChildItem, PrismContainerValue<?> valueOfExistingDelta) throws SchemaException {
PrismContainerValue<?> parentValue = origParentValue.getParentContainerValue();
PrismContainerValue<?> parentValue = getParentContainerValue(origParentValue);

PrismContainer newContainer = null;
PrismContainerValue newValue = null;
Expand Down Expand Up @@ -331,4 +331,19 @@ public Collection<ItemDelta> getDeltas() throws SchemaException {
}
return deltas;
}

private PrismContainerValue getParentContainerValue(PrismValue v) {
PrismContainerValue<?> valueContainer = v.getParentContainerValue();
if (valueContainer != null) {
return valueContainer;
}
if (v.getParent() instanceof ItemDelta) {
@NotNull ItemPath path = ((ItemDelta) v.getParent()).getPath();
Item prismParent = getObject().findItem(path);
if (prismParent != null) {
return prismParent.getParent();
}
}
return null;
}
}

0 comments on commit d348de2

Please sign in to comment.