Skip to content

Commit

Permalink
Simplify writing composite correlators
Browse files Browse the repository at this point in the history
CorrelatorsType is now CompositeCorrelatorType, so any configuration
with multiple correlators is now the default correlator composition.
  • Loading branch information
mederly committed Feb 26, 2022
1 parent 559be8d commit 013fbec
Show file tree
Hide file tree
Showing 10 changed files with 361 additions and 380 deletions.
148 changes: 63 additions & 85 deletions infra/schema/src/main/resources/xml/ns/public/common/common-core-3.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -23520,7 +23520,7 @@
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="correlators" type="tns:CorrelatorsType" minOccurs="0">
<xsd:element name="correlators" type="tns:CompositeCorrelatorType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Definition of a correlator or correlators to be used.
Expand Down Expand Up @@ -23580,9 +23580,10 @@
</xsd:complexType>
<xsd:element name="correlationCasesDefinition" type="tns:CorrelationCasesDefinitionType"/>

<xsd:complexType name="CorrelatorsType">
<xsd:complexType name="CompositeCorrelatorType">
<xsd:annotation>
<xsd:documentation>
TODO
User-friendly way of defining a correlator or correlators.
</xsd:documentation>
<xsd:appinfo>
Expand All @@ -23592,62 +23593,65 @@
<a:elaborate>true</a:elaborate>
</xsd:appinfo>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="extension" type="tns:ExtensionType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Correlators not defined in the static schema. (E.g. dummy correlator used for testing,
or custom correlators.)
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="none" type="tns:NoOpCorrelatorType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
"No-op" correlation that always returns "certainly no owner" result.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="item" type="tns:ItemCorrelatorType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Correlation using a list of matching items.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="filter" type="tns:FilterCorrelatorType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Correlation using a query filter.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="expression" type="tns:ExpressionCorrelatorType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Correlation using a custom expression.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="idMatch" type="tns:IdMatchCorrelatorType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Correlation using ID Match service.
See https://spaces.at.internet2.edu/display/cifer/SOR-Registry+Strawman+ID+Match+API.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="composite" type="tns:CompositeCorrelatorType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
TODO
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:long"/>
<xsd:complexContent>
<xsd:extension base="tns:AbstractCorrelatorType">
<xsd:sequence>
<xsd:element name="extension" type="tns:ExtensionType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Correlators not defined in the static schema. (E.g. dummy correlator used for testing,
or custom correlators.)
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="none" type="tns:NoOpCorrelatorType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
"No-op" correlation that always returns "certainly no owner" result.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="item" type="tns:ItemCorrelatorType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Correlation using a list of matching items.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="filter" type="tns:FilterCorrelatorType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Correlation using a query filter.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="expression" type="tns:ExpressionCorrelatorType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Correlation using a custom expression.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="idMatch" type="tns:IdMatchCorrelatorType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
Correlation using ID Match service.
See https://spaces.at.internet2.edu/display/cifer/SOR-Registry+Strawman+ID+Match+API.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="composite" type="tns:CompositeCorrelatorType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
TODO
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="correlators" type="tns:CorrelatorsType"/>
<xsd:element name="compositeCorrelator" type="tns:CompositeCorrelatorType"/>

<xsd:complexType name="AbstractCorrelatorType">
<xsd:annotation>
Expand Down Expand Up @@ -24017,7 +24021,8 @@
</xsd:annotation>
</xsd:element>
<!-- TODO referenceId mapping -->
<xsd:element name="followOn" type="tns:CorrelatorsType" minOccurs="0">
<!-- TODO use something more strict than general composite correlator -->
<xsd:element name="followOn" type="tns:CompositeCorrelatorType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
The correlator that is applied to the resolved (or potentially-matching) reference identifier
Expand All @@ -24031,33 +24036,6 @@
</xsd:complexType>
<xsd:element name="idMatchCorrelator" type="tns:IdMatchCorrelatorType"/>

<xsd:complexType name="CompositeCorrelatorType">
<xsd:annotation>
<xsd:documentation>
TODO
</xsd:documentation>
<xsd:appinfo>
<a:since>4.5</a:since>
<a:container>true</a:container>
<a:experimental>true</a:experimental>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="tns:AbstractCorrelatorType">
<xsd:sequence>
<xsd:element name="components" type="tns:CorrelatorsType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Children correlators.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="compositeCorrelator" type="tns:CompositeCorrelatorType"/>

<xsd:complexType name="CorrelationPropertiesDefinitionType">
<xsd:annotation>
<xsd:documentation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import com.evolveum.midpoint.prism.Item;
import com.evolveum.midpoint.prism.PrismValue;
import com.evolveum.midpoint.util.annotation.Experimental;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CompositeCorrelatorType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CorrelatorAuthorityLevelType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CorrelatorsType;

import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -59,17 +59,33 @@ public String toString() {
*
* @throws IllegalArgumentException If there's not exactly one configuration there.
*/
public static @NotNull CorrelatorConfiguration getConfiguration(CorrelatorsType correlators) {
public static @NotNull CorrelatorConfiguration getConfiguration(CompositeCorrelatorType correlators) {
Collection<CorrelatorConfiguration> configurations = getConfigurations(correlators);
argCheck(!configurations.isEmpty(), "No correlator configurations in %s", correlators);
argCheck(configurations.size() == 1, "Multiple correlator configurations in %s", correlators);
return configurations.iterator().next();

if (configurations.size() == 1) {
CorrelatorConfiguration configuration = configurations.iterator().next();
if (canBeStandalone(configuration)) {
return configuration;
}
}

// This is the default composite correlator.
return new TypedCorrelationConfiguration(correlators);
}

/**
* Currently, a configuration that is not non-authoritative can be run as standalone - without wrapping
* in composite correlator.
*/
private static boolean canBeStandalone(CorrelatorConfiguration configuration) {
return configuration.getAuthority() != CorrelatorAuthorityLevelType.NON_AUTHORITATIVE;
}

/**
* Extracts {@link CorrelatorConfiguration} objects from given "correlators" structure (both typed and untyped).
*/
public static @NotNull Collection<CorrelatorConfiguration> getConfigurations(@NotNull CorrelatorsType correlatorsBean) {
public static @NotNull Collection<CorrelatorConfiguration> getConfigurations(@NotNull CompositeCorrelatorType correlatorsBean) {
List<CorrelatorConfiguration> configurations =
Stream.of(
correlatorsBean.getNone().stream(),
Expand Down Expand Up @@ -101,7 +117,7 @@ public String toString() {
return configurations;
}

public static List<CorrelatorConfiguration> getConfigurationsSorted(CorrelatorsType correlatorsBean) {
public static List<CorrelatorConfiguration> getConfigurationsSorted(CompositeCorrelatorType correlatorsBean) {
List<CorrelatorConfiguration> configurations = new ArrayList<>(getConfigurations(correlatorsBean));
configurations.sort(
Comparator.nullsLast(Comparator.comparing(CorrelatorConfiguration::getOrder))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.jetbrains.annotations.VisibleForTesting;

import com.evolveum.midpoint.xml.ns._public.common.common_3.AbstractCorrelatorType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CorrelatorsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CompositeCorrelatorType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSynchronizationType;

/**
Expand Down Expand Up @@ -48,7 +48,7 @@ public CorrelatorContext(
}

public static CorrelatorContext<?> create(
@NotNull CorrelatorsType correlators,
@NotNull CompositeCorrelatorType correlators,
@Nullable ObjectSynchronizationType objectSynchronizationBean) {
return new CorrelatorContext<>(
CorrelatorConfiguration.getConfiguration(correlators),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

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

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

import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.schema.processor.ResourceObjectTypeDefinition;
import com.evolveum.midpoint.util.annotation.Experimental;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CorrelatorsType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectSynchronizationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
Expand All @@ -31,14 +32,14 @@ public class FullCorrelationContext {
@NotNull public final ResourceType resource;
@NotNull public final ResourceObjectTypeDefinition typeDefinition;
@NotNull public final ObjectSynchronizationType synchronizationBean;
@NotNull public final CorrelatorsType correlators;
@NotNull public final CompositeCorrelatorType correlators;

public FullCorrelationContext(
@NotNull ShadowType shadow,
@NotNull ResourceType resource,
@NotNull ResourceObjectTypeDefinition typeDefinition,
@NotNull ObjectSynchronizationType synchronizationBean,
@NotNull CorrelatorsType correlators) {
@NotNull CompositeCorrelatorType correlators) {
this.shadow = shadow;
this.resource = resource;
this.typeDefinition = typeDefinition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import java.util.*;
import java.util.Objects;

import static com.evolveum.midpoint.util.MiscUtil.configCheck;

/**
* TODO
*
Expand Down Expand Up @@ -75,7 +73,7 @@ private class Correlation {

@NotNull private final CorrelationContext correlationContext;
@NotNull private final Task task;
@NotNull private final String contextDescription;
@NotNull private final String contextDescription; // TODO

@NotNull private final List<CorrelationResult> authoritativeResults = new ArrayList<>();
@NotNull private final List<CorrelationResult> nonAuthoritativeResults = new ArrayList<>();
Expand All @@ -94,12 +92,8 @@ public CorrelationResult execute(OperationResult result)
throws SchemaException, ExpressionEvaluationException, CommunicationException, SecurityViolationException,
ConfigurationException, ObjectNotFoundException {

configCheck(getConfiguration().getComponents() != null,
"The 'components' item is missing in %s", contextDescription);

List<CorrelatorConfiguration> childConfigurations =
CorrelatorConfiguration.getConfigurationsSorted(
getConfiguration().getComponents());
CorrelatorConfiguration.getConfigurationsSorted(getConfiguration());

checkIfAuthoritativeAfterNotAuthoritative(childConfigurations);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import javax.annotation.PostConstruct;
import javax.xml.namespace.QName;

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

import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
Expand All @@ -22,7 +24,6 @@
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.CompositeCorrelatorType;

/**
* Factory for {@link CompositeCorrelator} instances.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,16 @@ public ExpressionType getConfirmation() {
}

// TODO reconsider cloning here
public @NotNull CorrelatorsType getCorrelators() {
public @NotNull CompositeCorrelatorType getCorrelators() {
if (objectSynchronization.getCorrelationDefinition() != null && objectSynchronization.getCorrelationDefinition().getCorrelators() != null) {
return objectSynchronization.getCorrelationDefinition().getCorrelators().clone();
} else if (objectSynchronization.getCorrelation().isEmpty()) {
LOGGER.debug("No correlation information present. Will always find no owner. In: {}", this);
return new CorrelatorsType(PrismContext.get())
return new CompositeCorrelatorType(PrismContext.get())
.beginNone().end();
} else {
CorrelatorsType correlators =
new CorrelatorsType(PrismContext.get())
CompositeCorrelatorType correlators =
new CompositeCorrelatorType(PrismContext.get())
.beginFilter()
.confirmation(CloneUtil.clone(objectSynchronization.getConfirmation()))
.end();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private void breakServerAddress(Task task, OperationResult result) throws Common
synchronizationId,
ObjectSynchronizationType.F_CORRELATION_DEFINITION,
CorrelationDefinitionType.F_CORRELATORS,
CorrelatorsType.F_ID_MATCH,
CompositeCorrelatorType.F_ID_MATCH,
idMatchId);
}
}

0 comments on commit 013fbec

Please sign in to comment.