Skip to content

Commit

Permalink
Add inbound mapping "use" property
Browse files Browse the repository at this point in the history
This is a simple way of marking a mapping to be used for correlation,
data transfer (~ clockwork), or both.
  • Loading branch information
mederly committed May 3, 2023
1 parent 13646f3 commit 330f9aa
Show file tree
Hide file tree
Showing 17 changed files with 144 additions and 181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.annotation.Experimental;

import java.util.function.Supplier;

import static com.evolveum.midpoint.util.QNameUtil.getLocalPart;

/**
Expand All @@ -37,6 +39,30 @@
@Experimental
public class ConfigErrorReporter {

public static Object lazy(Supplier<Object> supplier) {
return new Object() {
@Override
public String toString() {
return String.valueOf(supplier.get());
}
};
}

public static String describe(@NotNull InboundMappingType inboundMapping) {
PrismContainerValue<?> pcv = inboundMapping.asPrismContainerValue();
var itemDef = PrismValueUtil.getNearestValueOfType(pcv, ResourceItemDefinitionType.class);
if (itemDef != null) {
return describeLocally(inboundMapping) + " in " + describe(itemDef);
} else {
return describeLocally(inboundMapping);
}
}

private static String describeLocally(@NotNull InboundMappingType mapping) {
String name = mapping.getName();
return name != null ? "inbound mapping '" + name + "'" : "inbound mapping";
}

public static String describe(@NotNull ItemRefinedDefinitionType itemRefinedDefinition) {
PrismContainerValue<?> pcv = itemRefinedDefinition.asPrismContainerValue();
Objectable top = PrismValueUtil.getRootObject(pcv);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9099,17 +9099,33 @@
<xsd:complexContent>
<xsd:extension base="tns:MappingType">
<xsd:sequence>
<xsd:element name="evaluationPhases" type="tns:InboundMappingEvaluationPhasesType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Phase or phases in which the mapping should be evaluated.
(Default evaluation phases for given object type are taken into account as well.)
</xsd:documentation>
<xsd:appinfo>
<a:displayName>InboundMappingType.evaluationPhases</a:displayName>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:choice>
<xsd:element name="evaluationPhases" type="tns:InboundMappingEvaluationPhasesType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Phase or phases in which the mapping should be evaluated.
(Default evaluation phases for given object type are taken into account as well.)
Mutually exclusive with "use" item.
</xsd:documentation>
<xsd:appinfo>
<a:displayName>InboundMappingType.evaluationPhases</a:displayName>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="use" type="tns:InboundMappingUseType" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
What purpose or purposes does the inbound mapping serve?
This is a simplified version of "evaluationPhases" item and is mutually exclusive with it.
If present, it overrides any default evaluation phases.
</xsd:documentation>
<xsd:appinfo>
<a:displayName>InboundMappingType.use</a:displayName>
<a:since>4.8</a:since>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:choice>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
Expand Down Expand Up @@ -9197,6 +9213,39 @@
</xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="InboundMappingUseType">
<xsd:annotation>
<xsd:documentation>
What purpose or purposes does the inbound mapping serve?
</xsd:documentation>
<xsd:appinfo>
<a:since>4.8</a:since>
</xsd:appinfo>
</xsd:annotation>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="dataTransfer">
<xsd:annotation>
<xsd:documentation>
The mapping is used for the data transfer.
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="DATA_TRANSFER"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="correlation">
<xsd:annotation>
<xsd:documentation>
The mapping is used for the correlation.
</xsd:documentation>
<xsd:appinfo>
<jaxb:typesafeEnumMember name="CORRELATION"/>
</xsd:appinfo>
</xsd:annotation>
</xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>

<xsd:complexType name="OrgType">
<xsd:annotation>
<xsd:documentation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@

package com.evolveum.midpoint.model.impl.lens.projector.focus.inbounds.prep;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;

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

import com.evolveum.midpoint.schema.error.ConfigErrorReporter;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
Expand All @@ -23,6 +25,8 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static com.evolveum.midpoint.schema.error.ConfigErrorReporter.lazy;
import static com.evolveum.midpoint.util.MiscUtil.configCheck;
import static com.evolveum.midpoint.xml.ns._public.common.common_3.InboundMappingEvaluationPhaseType.BEFORE_CORRELATION;

/**
Expand Down Expand Up @@ -58,20 +62,38 @@ class ApplicabilityEvaluator {
this.correlationItemPaths = correlationItemPaths;
}

List<InboundMappingType> filterApplicableMappingBeans(List<InboundMappingType> beans) {
return beans.stream()
.filter(this::isApplicable)
.collect(Collectors.toList());
List<InboundMappingType> filterApplicableMappingBeans(List<InboundMappingType> beans) throws ConfigurationException {
List<InboundMappingType> applicableBeans = new ArrayList<>();
for (InboundMappingType bean : beans) {
if (isApplicable(bean)) {
applicableBeans.add(bean);
}
}
return applicableBeans;
}

private boolean isApplicable(@NotNull InboundMappingType mappingBean) {
private boolean isApplicable(@NotNull InboundMappingType mappingBean) throws ConfigurationException {
InboundMappingEvaluationPhasesType mappingPhases = mappingBean.getEvaluationPhases();
List<InboundMappingUseType> uses = mappingBean.getUse();
configCheck(mappingPhases == null || uses.isEmpty(),
"Both 'evaluationPhases' and 'use' items present in %s",
lazy(() -> ConfigErrorReporter.describe(mappingBean)));
if (mappingPhases != null) {
if (mappingPhases.getExclude().contains(currentPhase)) {
return false;
} else if (mappingPhases.getInclude().contains(currentPhase)) {
return true;
}
} else if (!uses.isEmpty()) {
// The "use" information is definite, if present. Default phases nor correlation usage are not taken into account.
switch (currentPhase) {
case BEFORE_CORRELATION:
return uses.contains(InboundMappingUseType.CORRELATION);
case CLOCKWORK:
return uses.contains(InboundMappingUseType.DATA_TRANSFER);
default:
throw new AssertionError(currentPhase);
}
}

if (defaultPhases.contains(currentPhase)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ abstract <V extends PrismValue, D extends ItemDefinition<?>> InboundMappingInCon
@NotNull List<InboundMappingType> selectMappingBeansForEvaluationPhase(
@NotNull List<InboundMappingType> beans,
boolean resourceItemLocalCorrelatorDefined,
@NotNull Collection<ItemPath> correlationItemPaths) {
@NotNull Collection<ItemPath> correlationItemPaths) throws ConfigurationException {
InboundMappingEvaluationPhaseType currentPhase = getCurrentEvaluationPhase();
List<InboundMappingType> filtered =
new ApplicabilityEvaluator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@
<target>
<path>name</path>
</target>
<evaluationPhases>
<include>beforeCorrelation</include>
</evaluationPhases>
</inbound>
</attribute>
<attribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@
<icfi:instanceId>multi</icfi:instanceId>
</icfc:configurationProperties>

<icfc:resultsHandlerConfiguration>
<icfc:enableNormalizingResultsHandler>false</icfc:enableNormalizingResultsHandler>
<icfc:enableFilteredResultsHandler>false</icfc:enableFilteredResultsHandler>
<icfc:enableAttributesToGetSearchResultsHandler>false</icfc:enableAttributesToGetSearchResultsHandler>
</icfc:resultsHandlerConfiguration>

</connectorConfiguration>

<schemaHandling>
Expand Down Expand Up @@ -88,9 +82,6 @@
<target>
<path>extension/personalNumber</path>
</target>
<evaluationPhases>
<include>beforeCorrelation</include>
</evaluationPhases>
</inbound>
</attribute>
<correlation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,8 @@
</code>
</script>
</expression>
<evaluationPhases>
<include>beforeCorrelation</include>
</evaluationPhases>
</inbound>
</attribute>

<correlation>
<correlators>
<items>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@
<target>
<path>extension/personalNumber</path>
</target>
<evaluationPhases>
<include>beforeCorrelation</include>
</evaluationPhases>
</inbound>
</attribute>
<correlation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@
<target>
<path>employeeNumber</path>
</target>
<evaluationPhases>
<include>beforeCorrelation</include>
</evaluationPhases>
</inbound>
</attribute>
<correlation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,7 @@
<target>
<path>employeeNumber</path>
</target>
<!-- This is a kind of hack. We want to correlate on this attribute by a simple mapping but do not want
to use it to really modify the focus. This may happen for correlation attributes on non-authoritative
resources (e.g. target ones, or "auxiliary" source ones). -->
<evaluationPhases>
<include>beforeCorrelation</include>
<exclude>clockwork</exclude>
</evaluationPhases>
<use>correlation</use>
</inbound>
</attribute>
<synchronization/> <!-- no reactions, just the correlation -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,7 @@
<target>
<path>employeeNumber</path>
</target>
<!-- This is a kind of hack. We want to correlate on this attribute by a simple mapping but do not want
to use it to really modify the focus. This may happen for correlation attributes on non-authoritative
resources (e.g. target ones, or "auxiliary" source ones). Repeated for other attributes. -->
<evaluationPhases>
<include>beforeCorrelation</include>
<exclude>clockwork</exclude>
</evaluationPhases>
<use>correlation</use>
</inbound>
</attribute>
<!-- TODO We want to make sure this information is (eventually) consistent with the one in midPoint and HR. -->
Expand All @@ -57,10 +51,7 @@
<target>
<path>emailAddress</path>
</target>
<evaluationPhases>
<include>beforeCorrelation</include>
<exclude>clockwork</exclude>
</evaluationPhases>
<use>correlation</use>
</inbound>
</attribute>
<attribute>
Expand All @@ -69,10 +60,7 @@
<target>
<path>givenName</path>
</target>
<evaluationPhases>
<include>beforeCorrelation</include>
<exclude>clockwork</exclude>
</evaluationPhases>
<use>correlation</use>
</inbound>
</attribute>
<attribute>
Expand All @@ -81,10 +69,7 @@
<target>
<path>familyName</path>
</target>
<evaluationPhases>
<include>beforeCorrelation</include>
<exclude>clockwork</exclude>
</evaluationPhases>
<use>correlation</use>
</inbound>
</attribute>
<correlation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,7 @@
<target>
<path>employeeNumber</path>
</target>
<!-- This is a kind of hack. We want to correlate on this attribute by a simple mapping but do not want
to use it to really modify the focus. This may happen for correlation attributes on non-authoritative
resources (e.g. target ones, or "auxiliary" source ones). Repeated for other attributes. -->
<evaluationPhases>
<include>beforeCorrelation</include>
<exclude>clockwork</exclude>
</evaluationPhases>
<use>correlation</use>
</inbound>
</attribute>
<!-- TODO We want to make sure this information is (eventually) consistent with the one in midPoint and HR. -->
Expand All @@ -61,10 +55,7 @@
<target>
<path>emailAddress</path>
</target>
<evaluationPhases>
<include>beforeCorrelation</include>
<exclude>clockwork</exclude>
</evaluationPhases>
<use>correlation</use>
</inbound>
</attribute>
<attribute>
Expand All @@ -73,10 +64,7 @@
<target>
<path>givenName</path>
</target>
<evaluationPhases>
<include>beforeCorrelation</include>
<exclude>clockwork</exclude>
</evaluationPhases>
<use>correlation</use>
</inbound>
</attribute>
<attribute>
Expand All @@ -85,10 +73,7 @@
<target>
<path>familyName</path>
</target>
<evaluationPhases>
<include>beforeCorrelation</include>
<exclude>clockwork</exclude>
</evaluationPhases>
<use>correlation</use>
</inbound>
</attribute>
<attribute>
Expand Down

0 comments on commit 330f9aa

Please sign in to comment.