Skip to content

Commit

Permalink
Add custom (scripted) normalization
Browse files Browse the repository at this point in the history
We can now use custom scripts to compute normalized values.

Work in progress.
  • Loading branch information
mederly committed Aug 8, 2022
1 parent a75240d commit 6cb231d
Show file tree
Hide file tree
Showing 34 changed files with 706 additions and 257 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
import java.util.HashMap;
import java.util.Map;

import com.evolveum.midpoint.model.api.identities.IdentityManagementConfiguration;

import com.evolveum.midpoint.model.api.indexing.IndexingConfiguration;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import com.evolveum.midpoint.model.api.identities.IdentityManagementConfiguration;
import com.evolveum.midpoint.model.api.identities.IndexingConfiguration;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.util.DebugDumpable;
import com.evolveum.midpoint.util.DebugUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,71 +10,19 @@
import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.prism.path.ItemPath;

import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.IdentityItemDefinitionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ItemRefinedDefinitionType;

import org.jetbrains.annotations.NotNull;

import javax.xml.namespace.QName;
import java.io.Serializable;

public class IdentityItemConfiguration implements Serializable {

/** Beware, the name may be unqualified! */
@NotNull private final QName name;

/** Beware, the path segments may be unqualified! */
@NotNull private final ItemPath path;

private IdentityItemConfiguration(@NotNull QName name, @NotNull ItemPath path) {
this.name = name;
this.path = path;
}

@NotNull public static IdentityItemConfiguration of(
@NotNull ItemRefinedDefinitionType itemDefBean,
@NotNull IdentityItemDefinitionType identityDefBean) throws ConfigurationException {
ItemPath path = MiscUtil.configNonNull(
itemDefBean.getRef(),
() -> "No 'ref' in " + itemDefBean)
.getItemPath();
QName explicitName = identityDefBean.getName();
QName name = explicitName != null ? explicitName : deriveName(path, itemDefBean);
return new IdentityItemConfiguration(name, path);
}

private static @NotNull QName deriveName(ItemPath path, ItemRefinedDefinitionType itemDefBean)
throws ConfigurationException {
return MiscUtil.configNonNull(
path.lastName(),
() -> "No name in path '" + path + "' in " + itemDefBean);
}
public interface IdentityItemConfiguration {

public @NotNull QName getName() {
return name;
}
@NotNull QName getName();

@SuppressWarnings("WeakerAccess")
public @NotNull String getLocalName() {
return name.getLocalPart();
}

public @NotNull ItemName getDefaultSearchItemName() {
return new ItemName(SchemaConstants.NS_IDENTITY, getLocalName());
}
@NotNull String getLocalName();

public @NotNull ItemPath getPath() {
return path;
}
@NotNull ItemName getDefaultSearchItemName();

@Override
public String toString() {
return "IdentityItemConfiguration{" +
"name='" + name + '\'' +
", path=" + path +
'}';
}
@NotNull ItemPath getPath();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,15 @@
package com.evolveum.midpoint.model.api.identities;

import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.path.PathKeyedMap;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.IdentityItemDefinitionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateItemDefinitionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;

/**
* Wraps all the configuration related to management of `identities` container, correlation, and so on.
*
* PRELIMINARY VERSION - e.g. no support for object template inclusion, etc
*/
public class IdentityManagementConfiguration {

@NotNull private final ObjectTemplateType objectTemplate;
@NotNull private final PathKeyedMap<IdentityItemConfiguration> itemsMap;

private IdentityManagementConfiguration(ObjectTemplateType objectTemplate) throws ConfigurationException {
this.objectTemplate = objectTemplate != null ? objectTemplate : new ObjectTemplateType();
this.itemsMap = extractItemsConfiguration(this.objectTemplate);
}

private static PathKeyedMap<IdentityItemConfiguration> extractItemsConfiguration(@NotNull ObjectTemplateType objectTemplate)
throws ConfigurationException {
PathKeyedMap<IdentityItemConfiguration> itemConfigurationMap = new PathKeyedMap<>();
for (ObjectTemplateItemDefinitionType itemDefBean : objectTemplate.getItem()) {
IdentityItemDefinitionType identityDefBean = itemDefBean.getIdentity();
if (identityDefBean != null) {
IdentityItemConfiguration configuration = IdentityItemConfiguration.of(itemDefBean, identityDefBean);
itemConfigurationMap.put(configuration.getPath(), configuration);
}
}
return itemConfigurationMap;
}

public static @NotNull IdentityManagementConfiguration of(@Nullable ObjectTemplateType objectTemplate)
throws ConfigurationException {
return new IdentityManagementConfiguration(objectTemplate);
}

public @NotNull Collection<IdentityItemConfiguration> getItems() {
return itemsMap.values();
}
public interface IdentityManagementConfiguration {

public @Nullable IdentityItemConfiguration getForPath(@NotNull ItemPath path) {
return itemsMap.get(path);
}
@NotNull Collection<? extends IdentityItemConfiguration> getItems();

@Override
public String toString() {
return getClass().getSimpleName() + "{" +
"objectTemplate=" + objectTemplate +
", items: " + itemsMap.size() +
'}';
}
@Nullable IdentityItemConfiguration getForPath(@NotNull ItemPath path);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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.prism.path.ItemPath;
import com.evolveum.midpoint.util.exception.ConfigurationException;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;

public interface IndexingConfiguration {

@NotNull Collection<IndexingItemConfiguration> getItems() throws ConfigurationException;

@Nullable IndexingItemConfiguration getForPath(@NotNull ItemPath path);

boolean hasNoItems();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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 java.util.Collection;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.util.exception.ConfigurationException;

public interface IndexingItemConfiguration {

@NotNull String getName();

@NotNull ItemName getQualifiedName();

@NotNull ItemPath getPath();

@NotNull Collection<Normalization> getNormalizations();

Normalization findNormalization(@Nullable String index) throws ConfigurationException;

Normalization getDefaultNormalization() throws ConfigurationException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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.prism.PrismPropertyDefinition;
import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.prism.path.ItemPath;

import com.evolveum.midpoint.schema.result.OperationResult;

import com.evolveum.midpoint.task.api.Task;

import com.evolveum.midpoint.util.exception.*;

import org.jetbrains.annotations.NotNull;

public interface Normalization {

@NotNull String getName();

boolean isDefault();

ItemName getIndexItemName();

ItemPath getIndexItemPath();

@NotNull PrismPropertyDefinition<String> getIndexItemDefinition();

@NotNull String normalize(@NotNull String input, Task task, OperationResult result) throws SchemaException, ExpressionEvaluationException, CommunicationException, SecurityViolationException, ConfigurationException, ObjectNotFoundException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class CorrelationServiceImpl implements CorrelationService {
throws SchemaException, ExpressionEvaluationException, CommunicationException, SecurityViolationException,
ConfigurationException, ObjectNotFoundException {
FullCorrelationContext fullContext = getFullCorrelationContext(shadowedResourceObject, task, result);
CorrelatorContext<?> correlatorContext = CorrelatorContextCreator.createRootContext(fullContext);
CorrelatorContext<?> correlatorContext = CorrelatorContextCreator.createRootContext(fullContext, beans);
CorrelationContext correlationContext = createCorrelationContext(fullContext, preFocus, task, result);
return correlatorFactoryRegistry
.instantiateCorrelator(correlatorContext, task, result)
Expand Down Expand Up @@ -116,7 +116,7 @@ public boolean checkCandidateOwner(
synchronizationPolicy,
determineObjectTemplate(synchronizationPolicy, preFocus, result),
asObjectable(systemObjectCache.getSystemConfiguration(result)));
CorrelatorContext<?> correlatorContext = CorrelatorContextCreator.createRootContext(fullContext);
CorrelatorContext<?> correlatorContext = CorrelatorContextCreator.createRootContext(fullContext, beans);
CorrelationContext correlationContext = createCorrelationContext(fullContext, preFocus, task, result);
return correlatorFactoryRegistry
.instantiateCorrelator(correlatorContext, task, result)
Expand Down Expand Up @@ -197,7 +197,7 @@ public Correlator instantiateCorrelator(
throws SchemaException, ConfigurationException, ExpressionEvaluationException, CommunicationException,
SecurityViolationException, ObjectNotFoundException {
FullCorrelationContext fullContext = getFullCorrelationContext(aCase, task, result);
CorrelatorContext<?> correlatorContext = CorrelatorContextCreator.createRootContext(fullContext);
CorrelatorContext<?> correlatorContext = CorrelatorContextCreator.createRootContext(fullContext, beans);
return correlatorFactoryRegistry.instantiateCorrelator(correlatorContext, task, result);
}

Expand Down Expand Up @@ -237,7 +237,7 @@ public Collection<CorrelationProperty> getCorrelationProperties(
throws SchemaException, ConfigurationException, ExpressionEvaluationException, CommunicationException,
SecurityViolationException, ObjectNotFoundException {
FullCorrelationContext fullCorrelationContext = getFullCorrelationContext(aCase, task, result);
CorrelatorContext<?> correlatorContext = CorrelatorContextCreator.createRootContext(fullCorrelationContext);
CorrelatorContext<?> correlatorContext = CorrelatorContextCreator.createRootContext(fullCorrelationContext, beans);
return new CorrelationPropertiesCreator(correlatorContext, fullCorrelationContext, aCase)
.createProperties();
}
Expand All @@ -250,7 +250,8 @@ public Collection<CorrelationProperty> getCorrelationProperties(
return CorrelatorContextCreator.createRootContext(
synchronizationPolicy.getCorrelationDefinition(),
objectTemplate,
systemConfiguration);
systemConfiguration,
beans);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@
import java.util.stream.Collectors;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.model.api.identities.IdentityManagementConfiguration;

import com.evolveum.midpoint.model.api.indexing.IndexingConfiguration;
import com.evolveum.midpoint.model.impl.ModelBeans;
import com.evolveum.midpoint.model.impl.lens.identities.IdentitiesManager;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import com.evolveum.midpoint.model.api.correlator.CorrelatorConfiguration;
import com.evolveum.midpoint.model.api.correlator.CorrelatorContext;
import com.evolveum.midpoint.model.api.identities.IdentityManagementConfiguration;
import com.evolveum.midpoint.model.api.identities.IndexingConfiguration;
import com.evolveum.midpoint.model.impl.lens.identities.IndexingConfigurationImpl;
import com.evolveum.midpoint.model.impl.correlator.FullCorrelationContext;
import com.evolveum.midpoint.prism.Item;
import com.evolveum.midpoint.prism.PrismContainerValue;
Expand Down Expand Up @@ -100,18 +105,20 @@ private CorrelatorContextCreator(
this.systemConfiguration = systemConfiguration;
}

static CorrelatorContext<?> createRootContext(@NotNull FullCorrelationContext fullContext)
static CorrelatorContext<?> createRootContext(@NotNull FullCorrelationContext fullContext, ModelBeans beans)
throws ConfigurationException, SchemaException {
return createRootContext(
fullContext.getCorrelationDefinitionBean(),
fullContext.objectTemplate,
fullContext.systemConfiguration);
fullContext.systemConfiguration,
beans);
}

static CorrelatorContext<?> createRootContext(
@NotNull CorrelationDefinitionType correlationDefinitionBean,
@Nullable ObjectTemplateType objectTemplate,
@Nullable SystemConfigurationType systemConfiguration)
@Nullable SystemConfigurationType systemConfiguration,
@NotNull ModelBeans beans)
throws ConfigurationException, SchemaException {
CompositeCorrelatorType correlators;
CompositeCorrelatorType specificCorrelators = correlationDefinitionBean.getCorrelators();
Expand All @@ -123,8 +130,8 @@ static CorrelatorContext<?> createRootContext(
return new CorrelatorContextCreator(
getConfiguration(correlators),
correlationDefinitionBean,
IdentityManagementConfiguration.of(objectTemplate),
IndexingConfiguration.of(objectTemplate),
IdentitiesManager.createIdentityConfiguration(objectTemplate),
IndexingConfigurationImpl.of(objectTemplate, beans),
systemConfiguration)
.create();
}
Expand Down

0 comments on commit 6cb231d

Please sign in to comment.