Skip to content

Commit

Permalink
Remove "Adding value that already exists" warning
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Jan 16, 2024
1 parent 08f9bed commit e207b1b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@

package com.evolveum.midpoint.model.impl.correlator.items;

import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
import javax.xml.namespace.QName;

Expand Down Expand Up @@ -330,7 +327,7 @@ private ExpressionType createConfidenceExpression(String code) {
.code(code)));
}

/** Returns the values of given metric (e.g. Levenshtein distance) for given candidate for this item. */
/** Returns the values of given metric (e.g. Levenshtein distance) for given candidate for this item. No nulls on return. */
private @NotNull List<Double> computeMatchMetricValues(ObjectType candidate, Task task, OperationResult result)
throws SchemaException, ExpressionEvaluationException, CommunicationException, SecurityViolationException,
ConfigurationException, ObjectNotFoundException {
Expand Down Expand Up @@ -367,6 +364,7 @@ private MatchMetricValueComputer getMatchMetricValueComputer() throws Configurat
};
}

/** No nulls in returned list. */
private @NotNull List<Double> convertMetricToConfidence(
List<Double> matchMetricValues, ExpressionType expression, Task task, OperationResult result)
throws SchemaException, ExpressionEvaluationException, ObjectNotFoundException, CommunicationException,
Expand All @@ -379,7 +377,8 @@ private MatchMetricValueComputer getMatchMetricValueComputer() throws Configurat
PrismContext.get().definitionFactory().createPropertyDefinition(
ExpressionConstants.OUTPUT_ELEMENT_NAME, DOMUtil.XSD_DOUBLE);
PrismProperty<Double> inputProperty = inputPropertyDef.instantiate();
matchMetricValues.forEach(inputProperty::addRealValue);
new HashSet<>(matchMetricValues) // To avoid "Adding value to property input that already exists (overwriting)" warnings
.forEach(inputProperty::addRealValue);
Source<PrismPropertyValue<Double>, PrismPropertyDefinition<Double>> inputSource =
new Source<>(
inputProperty, null, inputProperty, inputProperty.getElementName(), inputPropertyDef);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

/**
* Normalizes a given item using provided {@link IndexedItemValueNormalizer}.
Expand Down Expand Up @@ -48,15 +50,20 @@ class ItemNormalizer {
prismContext.itemFactory().createProperty(
valueNormalizer.getIndexItemName(),
(PrismPropertyDefinition<String>) valueNormalizer.getIndexItemDefinition());

// This intermediate set is here to avoid "Adding value to property XXX that already exists" warnings.
Set<String> normalizedValues = new HashSet<>();
for (PrismValue originalValue : originalValues) {
Object originalRealValue = originalValue.getRealValue();
if (originalRealValue != null) {
normalizedItem.addRealValue(
normalizedValues.add(
valueNormalizer.normalize(originalRealValue, task, result));
} else {
LOGGER.warn("No real value in {} in {}", originalValue, originalItemDef);
}
}

normalizedValues.forEach(normalizedItem::addRealValue);
return normalizedItem;
}
}

0 comments on commit e207b1b

Please sign in to comment.