Skip to content

Commit

Permalink
Clean-up code related to value normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
mederly committed Aug 22, 2022
1 parent cb15ff6 commit 97073fc
Show file tree
Hide file tree
Showing 19 changed files with 144 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public enum Match {
/**
* A partial match.
*
* The default meaning is that any normalization of any primary or secondary value exactly matches
* The "baseline" meaning is that any normalization of any primary or secondary value exactly matches
* the same normalization of the source value.
*
* For items mentioned by "items" correlator(s) the partial match is also if at least one filter defined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public interface Correlator {
*/
@NotNull CorrelationExplanation explain(
@NotNull CorrelationContext correlationContext,
@NotNull FocusType candidateOwner,
@NotNull FocusType candidate,
@NotNull OperationResult result)
throws SchemaException, ExpressionEvaluationException, CommunicationException, SecurityViolationException,
ConfigurationException, ObjectNotFoundException;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2010-2022 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.model.api.indexing;

import com.evolveum.midpoint.xml.ns._public.common.common_3.IndexedItemNormalizationDefinitionType;

import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.prism.PrismPropertyDefinition;
import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.prism.path.ItemPath;

/**
* A {@link ValueNormalizer} configured for an indexed item.
*
* Terminological note: From the point of view of configuration, one may call this object a _normalization_.
* It is used to do the actual normalization of values, hence the name of _normalizer_.
*
* @see IndexedItemNormalizationDefinitionType
*/
public interface IndexedItemValueNormalizer extends ValueNormalizer {

/** Returns the name of the normalizer (normalization). */
@NotNull String getName();

/** Is this normalizer (normalization) the default one configured for the given item? */
boolean isDefault();

/** Returns the qualified name of the indexed version of the item, corresponding to this normalizer (normalization). */
ItemName getIndexItemName();

/** Returns the full path to the indexed version of the item. */
ItemPath getIndexItemPath();

/**
* Returns the definition of the indexed version of the item.
*
* Currently, it is always a definition of a string. Later this may be changed.
*/
@NotNull PrismPropertyDefinition<?> getIndexItemDefinition();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public interface IndexingItemConfiguration {

@NotNull ItemPath getPath();

@NotNull Collection<Normalization> getNormalizations();
@NotNull Collection<IndexedItemValueNormalizer> getNormalizers();

Normalization findNormalization(@Nullable String index) throws ConfigurationException;
IndexedItemValueNormalizer findNormalizer(@Nullable String index) throws ConfigurationException;

Normalization getDefaultNormalization() throws ConfigurationException;
IndexedItemValueNormalizer getDefaultNormalizer() throws ConfigurationException;
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

import org.jetbrains.annotations.NotNull;

/**
* Normalizes a (string) value for the purpose of custom property indexing.
*/
public interface ValueNormalizer {

@NotNull String normalize(@NotNull String input, Task task, OperationResult result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import com.evolveum.midpoint.model.impl.correlation.CorrelationCaseManager;
import com.evolveum.midpoint.model.impl.lens.*;
import com.evolveum.midpoint.model.impl.lens.identities.IdentitiesManager;
import com.evolveum.midpoint.model.impl.lens.identities.IndexingManager;
import com.evolveum.midpoint.model.impl.lens.indexing.IndexingManager;
import com.evolveum.midpoint.model.impl.lens.projector.Projector;
import com.evolveum.midpoint.model.impl.lens.projector.credentials.CredentialsProcessor;
import com.evolveum.midpoint.model.impl.lens.projector.focus.AutoAssignMappingCollector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import com.evolveum.midpoint.model.api.indexing.ValueNormalizer;
import com.evolveum.midpoint.model.impl.ModelBeans;
import com.evolveum.midpoint.model.impl.correlator.items.CorrelationItem;
import com.evolveum.midpoint.model.impl.lens.identities.IndexingManager;
import com.evolveum.midpoint.model.impl.lens.indexing.IndexingManager;
import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismProperty;
Expand Down Expand Up @@ -267,7 +267,7 @@ CorrelationCaseDescription.Match determine(Task task, OperationResult result)
return NOT_APPLICABLE;
}
ValueNormalizer defaultValueNormalizer = indexing != null ?
indexing.getDefaultNormalization() : IndexingManager.getDefaultNormalizer();
indexing.getDefaultNormalizer() : IndexingManager.getDefaultNormalizer();
String preFocusNormalized = IndexingManager.normalizeValue(preFocusRealValue, defaultValueNormalizer, task, result);

for (PrismValue primaryValue : primaryValues) {
Expand Down Expand Up @@ -312,7 +312,7 @@ CorrelationCaseDescription.Match determine(Task task, OperationResult result)
}

Collection<? extends ValueNormalizer> normalizers = indexing != null ?
indexing.getNormalizations() : Set.of(IndexingManager.getDefaultNormalizer());
indexing.getNormalizers() : Set.of(IndexingManager.getDefaultNormalizer());
LOGGER.trace("Trying to find a match using applicable normalizers (count: {})", normalizers.size());

for (PrismValue anyValue : allValues) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.evolveum.midpoint.model.api.indexing.IndexingConfiguration;

import com.evolveum.midpoint.model.impl.lens.identities.IdentityManagementConfigurationImpl;
import com.evolveum.midpoint.model.impl.lens.identities.IndexingConfigurationImpl;
import com.evolveum.midpoint.model.impl.lens.indexing.IndexingConfigurationImpl;
import com.evolveum.midpoint.prism.path.PathKeyedMap;

import com.evolveum.midpoint.util.MiscUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,19 @@ protected BaseCorrelator(
@Override
public @NotNull CorrelationExplanation explain(
@NotNull CorrelationContext correlationContext,
@NotNull FocusType candidateOwner,
@NotNull FocusType candidate,
@NotNull OperationResult parentResult)
throws SchemaException, ExpressionEvaluationException, CommunicationException, SecurityViolationException,
ConfigurationException, ObjectNotFoundException {

OperationResult result = parentResult.subresult(getClass().getName() + OP_EXPLAIN_SUFFIX)
.build();
try {
logger.trace("Explaining candidate owner:\n{}\nin context:\n{}",
candidateOwner.debugDumpLazily(1),
logger.trace("Explaining candidate:\n{}\nin context:\n{}",
candidate.debugDumpLazily(1),
correlationContext.debugDumpLazily(1));

CorrelationExplanation explanation = explainInternal(correlationContext, candidateOwner, result);
CorrelationExplanation explanation = explainInternal(correlationContext, candidate, result);

logger.trace("Determined candidate owner explanation:\n{}", explanation.debugDumpLazily(1));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import javax.xml.namespace.QName;

import com.evolveum.midpoint.model.api.indexing.IndexingItemConfiguration;
import com.evolveum.midpoint.model.api.indexing.Normalization;
import com.evolveum.midpoint.model.api.indexing.IndexedItemValueNormalizer;
import com.evolveum.midpoint.model.impl.ModelBeans;
import com.evolveum.midpoint.model.impl.lens.identities.IndexingManager;
import com.evolveum.midpoint.model.impl.lens.indexing.IndexingManager;

import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.query.FuzzyStringMatchFilter;
Expand Down Expand Up @@ -68,12 +68,12 @@ public class CorrelationItem implements DebugDumpable {
@NotNull private final ItemPath itemPath;

/** Null iff {@link #indexingItemConfiguration} is null. */
@Nullable private final Normalization normalization;
@Nullable private final IndexedItemValueNormalizer valueNormalizer;

// TODO
@Nullable private final IndexingItemConfiguration indexingItemConfiguration;

/** Note we ignore "index" from this configuration. It is already processed into {@link #normalization} field. */
/** Note we ignore "index" from this configuration. It is already processed into {@link #valueNormalizer} field. */
@NotNull private final ItemSearchDefinitionType searchDefinitionBean;

// TODO
Expand All @@ -82,13 +82,13 @@ public class CorrelationItem implements DebugDumpable {
private CorrelationItem(
@NotNull String name,
@NotNull ItemPath itemPath,
@Nullable Normalization normalization,
@Nullable IndexedItemValueNormalizer valueNormalizer,
@Nullable ItemSearchDefinitionType searchDefinitionBean,
@Nullable IndexingItemConfiguration indexingItemConfiguration,
@NotNull List<? extends PrismValue> prismValues) {
this.name = name;
this.itemPath = itemPath;
this.normalization = normalization;
this.valueNormalizer = valueNormalizer;
this.searchDefinitionBean = searchDefinitionBean != null ? searchDefinitionBean : new ItemSearchDefinitionType();
this.indexingItemConfiguration = indexingItemConfiguration;
this.prismValues = prismValues;
Expand All @@ -106,7 +106,7 @@ public static CorrelationItem create(
return new CorrelationItem(
getName(itemBean),
path,
getNormalization(indexingConfig, explicitIndexName, path),
getValueNormalizer(indexingConfig, explicitIndexName, path),
searchDef,
indexingConfig,
getPrismValues(preFocus, path));
Expand Down Expand Up @@ -145,7 +145,8 @@ private static ItemSearchDefinitionType getSearch(
return inTemplateDef != null ? inTemplateDef.getSearch() : null;
}

private static Normalization getNormalization(IndexingItemConfiguration indexingConfig, String index, ItemPath path)
private static IndexedItemValueNormalizer getValueNormalizer(
IndexingItemConfiguration indexingConfig, String index, ItemPath path)
throws ConfigurationException {
if (indexingConfig == null) {
if (index != null) {
Expand All @@ -156,7 +157,7 @@ private static Normalization getNormalization(IndexingItemConfiguration indexing
return null;
} else {
return MiscUtil.requireNonNull(
indexingConfig.findNormalization(index),
indexingConfig.findNormalizer(index),
() -> new ConfigurationException(
String.format("Index '%s' was not found in indexing configuration for '%s'", index, path)));
}
Expand Down Expand Up @@ -229,11 +230,11 @@ private SearchSpec createSearchSpec(Task task, OperationResult result)
throws SchemaException, ExpressionEvaluationException, CommunicationException, SecurityViolationException,
ConfigurationException, ObjectNotFoundException {
if (indexingItemConfiguration != null) {
assert normalization != null;
assert valueNormalizer != null;
return new SearchSpec(
normalization.getIndexItemPath(),
normalization.getIndexItemDefinition(),
IndexingManager.normalizeValue(getValueToFind(), normalization, task, result));
valueNormalizer.getIndexItemPath(),
valueNormalizer.getIndexItemDefinition(),
IndexingManager.normalizeValue(getValueToFind(), valueNormalizer, task, result));
} else {
return new SearchSpec(
itemPath,
Expand Down Expand Up @@ -398,7 +399,7 @@ public String toString() {
return "CorrelationItem{" +
"name=" + name +
", itemPath=" + itemPath +
", normalization=" + normalization +
", valueNormalizer=" + valueNormalizer +
", indexing=" + indexingItemConfiguration +
'}';
}
Expand All @@ -408,7 +409,7 @@ public String debugDump(int indent) {
StringBuilder sb = DebugUtil.createTitleStringBuilderLn(getClass(), indent);
DebugUtil.debugDumpWithLabelLn(sb, "name", name, indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "itemPath", String.valueOf(itemPath), indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "normalization", String.valueOf(normalization), indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "valueNormalizer", String.valueOf(valueNormalizer), indent + 1);
DebugUtil.debugDumpWithLabelLn(
sb, "indexingItemConfiguration", String.valueOf(indexingItemConfiguration), indent + 1);
DebugUtil.debugDumpWithLabel(sb, "values", prismValues, indent + 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import com.evolveum.midpoint.model.api.indexing.IndexingConfiguration;
import com.evolveum.midpoint.model.common.LinkManager;
import com.evolveum.midpoint.model.impl.lens.identities.IdentitiesManager;
import com.evolveum.midpoint.model.impl.lens.identities.IndexingConfigurationImpl;
import com.evolveum.midpoint.model.impl.lens.indexing.IndexingConfigurationImpl;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.delta.ItemDelta;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.model.impl.lens.identities;
package com.evolveum.midpoint.model.impl.lens.indexing;

import com.evolveum.midpoint.model.api.indexing.Normalization;
import com.evolveum.midpoint.model.impl.ModelBeans;
import com.evolveum.midpoint.model.api.indexing.IndexedItemValueNormalizer;
import com.evolveum.midpoint.prism.MutablePrismPropertyDefinition;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismPropertyDefinition;
Expand All @@ -26,14 +25,14 @@
import java.util.Collection;
import java.util.stream.Collectors;

public class NormalizationImpl implements Normalization {
public class IndexedItemValueNormalizerImpl implements IndexedItemValueNormalizer {

@NotNull private final String name;
@NotNull private final String normalizedItemLocalName;
@NotNull private final IndexedItemNormalizationDefinitionType bean;
@NotNull private final Collection<NormalizationStep<?>> steps;

private NormalizationImpl(
private IndexedItemValueNormalizerImpl(
@NotNull String name,
@NotNull String normalizedItemLocalName,
@NotNull IndexedItemNormalizationDefinitionType bean,
Expand All @@ -44,14 +43,14 @@ private NormalizationImpl(
this.steps = steps;
}

public static Normalization create(
public static IndexedItemValueNormalizer create(
@NotNull String indexedItemName,
@NotNull IndexedItemNormalizationDefinitionType normalizationBean) {
Collection<NormalizationStep<?>> parsedSteps = NormalizationStep.parse(normalizationBean.getSteps());
String normalizationName = getNormalizationName(normalizationBean, parsedSteps);
String normalizedItemLocalName =
getNormalizedItemLocalName(indexedItemName, normalizationName, normalizationBean);
return new NormalizationImpl(normalizationName, normalizedItemLocalName, normalizationBean, parsedSteps);
return new IndexedItemValueNormalizerImpl(normalizationName, normalizedItemLocalName, normalizationBean, parsedSteps);
}

private static @NotNull String getNormalizationName(
Expand Down Expand Up @@ -102,8 +101,7 @@ public ItemPath getIndexItemPath() {
}

@Override
public @NotNull PrismPropertyDefinition<String> getIndexItemDefinition() {
// FIXME (not always String)
public @NotNull PrismPropertyDefinition<?> getIndexItemDefinition() {
MutablePrismPropertyDefinition<String> definition = PrismContext.get().definitionFactory()
.createPropertyDefinition(getIndexItemName(), DOMUtil.XSD_STRING);
definition.setMinOccurs(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
* and European Union Public License. See LICENSE file for details.
*/

package com.evolveum.midpoint.model.impl.lens.identities;
package com.evolveum.midpoint.model.impl.lens.indexing;

import com.evolveum.midpoint.model.api.indexing.IndexingConfiguration;
import com.evolveum.midpoint.model.api.indexing.IndexingItemConfiguration;
import com.evolveum.midpoint.model.impl.ModelBeans;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.path.PathKeyedMap;
import com.evolveum.midpoint.util.exception.ConfigurationException;
Expand Down

0 comments on commit 97073fc

Please sign in to comment.