Skip to content

Commit

Permalink
Fixed incompatibilies uncovered by Midpoint tests
Browse files Browse the repository at this point in the history
Signed-off-by: Tony Tkáčik <tonydamage@gmail.com>
  • Loading branch information
tonydamage committed Mar 27, 2024
1 parent 1c95c16 commit a29fcd5
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.util.*;
import java.util.function.Function;
import java.util.function.Supplier;
import javax.xml.namespace.QName;

Expand Down Expand Up @@ -977,4 +978,16 @@ public void transformDefinition(ComplexTypeDefinition parent, ItemDefinitionTran
}
}
}

@Override
public void filterValues(Function<V, Boolean> function) {
// FIXME: Consider moving filter inside storage?
Iterator<V> iterator = values.iterator();
while (iterator.hasNext()) {
Boolean keep = function.apply(iterator.next());
if (keep == null || !keep) {
iterator.remove();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.*;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.prism.impl.storage.ExactValueExistsException;
import com.evolveum.midpoint.util.exception.SystemException;

import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -213,17 +214,21 @@ public void addValue(PrismPropertyValue<T> pValueToAdd) {

public void addValue(PrismPropertyValue<T> pValueToAdd, boolean checkUniqueness) {
checkMutable();

((PrismPropertyValueImpl<T>) pValueToAdd).checkValue();
var strategy = checkUniqueness ? EquivalenceStrategy.REAL_VALUE : null;
try {
addInternal(pValueToAdd, checkUniqueness, strategy);
values = values.add(this, pValueToAdd, strategy);
pValueToAdd.setParent(this);
pValueToAdd.recompute();
addInternalExecution(pValueToAdd);
} catch (ExactValueExistsException e) {
// NOOP
} catch (SchemaException e) {
throw new SystemException(e);
}
pValueToAdd.recompute();
addInternalExecution(pValueToAdd);
}


@Override
public void addRealValue(T valueToAdd) {
addValue(new PrismPropertyValueImpl<>(valueToAdd));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.evolveum.midpoint.prism.Itemable;
import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.prism.equivalence.EquivalenceStrategy;
import com.evolveum.midpoint.prism.equivalence.ParameterizedEquivalenceStrategy;
import com.evolveum.midpoint.util.exception.SchemaException;

import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -94,6 +95,15 @@ public Long extractKey(V value) {
protected KeyedStorage<Long, V> createDowngraded() {
return new Downgraded(this);
}

@Override
protected boolean ignoringExactKeys(EquivalenceStrategy strategy) {
if (strategy instanceof ParameterizedEquivalenceStrategy param) {
return !param.isConsideringContainerIds();
}

return false;
}
}

static class EmptySingle<V extends PrismContainerValue<?>> extends EmptyStorage.Keyed<Long, V> implements ContainerValueStorage<V> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,32 @@ public KeyedStorage<K, V> add(@NotNull Itemable owner, @NotNull V newValue, @Nul
}
if (strategy != null) {
// Only if strategy allows for different keys


iterateAndRemoveEquivalentValues(owner, newValue, strategy);
if (ignoringExactKeys(strategy)) {
iterateAndRemoveEquivalentValues(owner, newValue, strategy);
} else {
V maybe = storage.get(extractKey(newValue));
if (maybe != null && exactEquals(maybe, newValue)) {
throw ExactValueExistsException.INSTANCE;
}
}
}
checkKeyUnique(owner, newValue);
return addForced(newValue);
}

protected boolean ignoringExactKeys(EquivalenceStrategy strategy) {
return false;
}

@Override
protected void checkKeyUnique(@NotNull Itemable owner, V value) {
super.checkKeyUnique(owner, value);
protected void checkKeyUnique(@NotNull Itemable owner, V newValue) {
var newKey = extractKey(newValue);
if (newKey != null) {
var maybeValue = storage.get(newKey);
if (storage.get(newKey) != null) {
throw new IllegalStateException("Attempt to add a value with an key that already exists: " + newKey);
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,9 @@ public boolean addAll(Collection<? extends T> ts) {
public boolean isEmpty() {
return size() == 0;
}

@Override
public void clear() {
container.clear();
}
}

0 comments on commit a29fcd5

Please sign in to comment.