Skip to content

Commit

Permalink
ItemDelta: After applying Add operation, capture real values used.
Browse files Browse the repository at this point in the history
This is useful for repository, which needs to know real applied value
instead of submitted value for computing partial full objects.
  • Loading branch information
tonydamage committed Jun 6, 2024
1 parent bcd665a commit 89c9200
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import java.util.function.Supplier;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.util.MiscUtil;

import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.prism.*;
Expand Down Expand Up @@ -418,4 +416,11 @@ ItemDelta<V, D> narrow(PrismObject<? extends Objectable> object,
default boolean isMetadataRelated() {
return getPath().isMetadataRelated();
}

/**
* Returns set of values to add, or actual values from object when delta was applied to it.
*
* @return
*/
Collection<?> getAppliedValuesToAdd();
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public abstract class ItemDeltaImpl<V extends PrismValue, D extends ItemDefiniti
protected Collection<V> valuesToDelete = null;
private Collection<V> estimatedOldValues = null;

protected transient Collection<V> finalValuesAdded = null;

ItemDeltaImpl(D itemDefinition) {
if (itemDefinition == null) {
throw new IllegalArgumentException("Attempt to create item delta without a definition");
Expand Down Expand Up @@ -1353,10 +1355,12 @@ private void applyValuesToAdd(Item item) throws SchemaException {
item.clear();
}
}

finalValuesAdded = new ArrayList<>(valuesToAdd.size());
for (V valueToAdd : valuesToAdd) {
//noinspection unchecked
item.addRespectingMetadataAndCloning(valueToAdd, FOR_DELTA_ADD_APPLICATION, getProvenanceEquivalenceStrategy());
var applied = (V) item.addRespectingMetadataAndCloning(valueToAdd, FOR_DELTA_ADD_APPLICATION, getProvenanceEquivalenceStrategy());
finalValuesAdded.add(applied);
// Should we use userData to
}
}
}
Expand Down Expand Up @@ -2149,4 +2153,14 @@ public void setOriginTypeRecursive(final OriginType originType) {
}
});
}


@Override
public Collection<?> getAppliedValuesToAdd() {
if (finalValuesAdded != null) {
return finalValuesAdded.stream().map(v -> v.getRealValue()).toList();
} else {
return getRealValuesToAdd();
}
}
}

0 comments on commit 89c9200

Please sign in to comment.