Skip to content

Commit

Permalink
Fix attribute-based correlation
Browse files Browse the repository at this point in the history
This commit splits "correlation" item (on resource attributes) into two:
"correlator" that provides single-item correlator targeting respective
attribute/focus-item pair, and "correlation" that declares defaults
for item correlators using this focus item.

Work in progress. E.g., "correlator" on focus items is currently not
supported.

Other changes:
- Confidence expression can be provided for any correlation item
(not only fuzzy ones).
- The Match determination for given correlation property was fixed.
  • Loading branch information
mederly committed Aug 17, 2022
1 parent ad0125c commit 4a9c8e4
Show file tree
Hide file tree
Showing 37 changed files with 443 additions and 350 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,8 @@ public boolean isDisplayNameAttribute() {
}

@Override
public @Nullable ItemCorrelationDefinitionType getCorrelationDefinitionBean() {
return getRefinedAttributeDefinition().getCorrelationDefinitionBean();
public @Nullable ItemCorrelatorDefinitionType getCorrelatorDefinition() {
return getRefinedAttributeDefinition().getCorrelatorDefinition();
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,6 @@ default boolean hasOutboundMapping() {
*/
boolean isDisplayNameAttribute();

/** @see ItemRefinedDefinitionType#getCorrelation() */
@Nullable ItemCorrelationDefinitionType getCorrelationDefinitionBean();
/** @see ItemRefinedDefinitionType#getCorrelator() () */
@Nullable ItemCorrelatorDefinitionType getCorrelatorDefinition();
}
Original file line number Diff line number Diff line change
Expand Up @@ -857,8 +857,8 @@ public boolean isDisplayNameAttribute() {
}

@Override
public @Nullable ItemCorrelationDefinitionType getCorrelationDefinitionBean() {
return customizationBean.getCorrelation();
public @Nullable ItemCorrelatorDefinitionType getCorrelatorDefinition() {
return customizationBean.getCorrelator();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package com.evolveum.midpoint.schema.processor;

import static com.evolveum.midpoint.schema.util.CorrelationItemDefinitionUtil.addSingleItemCorrelator;
import static com.evolveum.midpoint.schema.util.ResourceTypeUtil.fillDefault;
import static com.evolveum.midpoint.util.MiscUtil.configCheck;
import static com.evolveum.midpoint.xml.ns._public.common.common_3.SynchronizationSituationType.DISPUTED;
Expand Down Expand Up @@ -260,63 +261,47 @@ private static CorrelationDefinitionType addCorrelationDefinitionsFromAttributes
@NotNull ResourceType resource) throws ConfigurationException {
CorrelationDefinitionType cloned = null;
for (ResourceAttributeDefinition<?> attributeDefinition : typeDef.getAttributeDefinitions()) {
ItemCorrelationDefinitionType correlationDefBean = attributeDefinition.getCorrelationDefinitionBean();
if (correlationDefBean != null) {
ItemCorrelatorDefinitionType correlatorDefBean = attributeDefinition.getCorrelatorDefinition();
if (correlatorDefBean != null) {
if (cloned == null) {
cloned = explicitDefinition.clone();
}
addCorrelationDefinitionFromAttribute(cloned, attributeDefinition, correlationDefBean, typeDef, resource);
addCorrelatorFromAttribute(cloned, attributeDefinition, correlatorDefBean, typeDef, resource);
}
}
return cloned != null ? cloned : explicitDefinition;
}

private static void addCorrelationDefinitionFromAttribute(
private static void addCorrelatorFromAttribute(
@NotNull CorrelationDefinitionType overallCorrelationDefBean,
@NotNull ResourceAttributeDefinition<?> attributeDefinition,
@NotNull ItemCorrelationDefinitionType attributeCorrelationDefBean,
@NotNull ItemCorrelatorDefinitionType attributeCorrelatorDefBean,
@NotNull ResourceObjectTypeDefinition typeDef,
@NotNull ResourceType resource) throws ConfigurationException {
List<InboundMappingType> inboundMappingBeans = attributeDefinition.getInboundMappingBeans();
configCheck(!inboundMappingBeans.isEmpty(),
"Attribute-level correlation requires an inbound mapping; for %s in %s (%s)",
attributeDefinition, typeDef, resource);
ItemPathType itemPathBean = determineItemPathBean(attributeDefinition, attributeCorrelationDefBean);
configCheck(itemPathBean != null,
ItemPath focusItemPath = determineFocusItemPath(attributeDefinition, attributeCorrelatorDefBean);
configCheck(focusItemPath != null,
"Item corresponding to correlation attribute %s couldn't be determined in %s (%s). You must specify"
+ " it either explicitly, or provide exactly one inbound mapping with a proper target",
attributeDefinition, typeDef, resource);
if (!attributeCorrelationDefBean.getRules().isEmpty()) {
throw new UnsupportedOperationException(
String.format("Explicit specification of rules is not supported yet: in %s in %s (%s)",
attributeDefinition, typeDef, resource));
}
CompositeCorrelatorType correlators = overallCorrelationDefBean.getCorrelators();
if (correlators == null) {
correlators = new CompositeCorrelatorType();
overallCorrelationDefBean.setCorrelators(correlators);
}
correlators.getItems().add(
new ItemsSubCorrelatorType()
.confidence(CloneUtil.clone(attributeCorrelationDefBean.getConfidence()))
.item(new ItemCorrelationType()
.ref(itemPathBean.clone())));
addSingleItemCorrelator(overallCorrelationDefBean, focusItemPath, attributeCorrelatorDefBean);
}

private static ItemPathType determineItemPathBean(
ResourceAttributeDefinition<?> attributeDefinition, ItemCorrelationDefinitionType attributeCorrelationDefBean) {
ItemPathType explicitItemPath = attributeCorrelationDefBean.getItem();
private static ItemPath determineFocusItemPath(
ResourceAttributeDefinition<?> attributeDefinition, @NotNull ItemCorrelatorDefinitionType attributeCorrelatorDefBean) {
ItemPathType explicitItemPath = attributeCorrelatorDefBean.getFocusItem();
if (explicitItemPath != null) {
return explicitItemPath;
return explicitItemPath.getItemPath();
} else {
return guessCorrelationItemPath(attributeDefinition);
return guessFocusItemPath(attributeDefinition);
}
}

/**
* Tries to determine correlation item path from the inbound mapping target.
*/
private static ItemPathType guessCorrelationItemPath(ResourceAttributeDefinition<?> attributeDefinition) {
/** Tries to determine correlation (focus) item path from the inbound mapping target. */
private static ItemPath guessFocusItemPath(ResourceAttributeDefinition<?> attributeDefinition) {
List<InboundMappingType> inboundMappingBeans = attributeDefinition.getInboundMappingBeans();
if (inboundMappingBeans.size() != 1) {
return null;
Expand All @@ -329,12 +314,12 @@ private static ItemPathType guessCorrelationItemPath(ResourceAttributeDefinition
ItemPath itemPath = itemPathType.getItemPath();
QName variableName = itemPath.firstToVariableNameOrNull();
if (variableName == null) {
return itemPathType;
return itemPath;
}
String localPart = variableName.getLocalPart();
if (ExpressionConstants.VAR_FOCUS.equals(localPart)
|| ExpressionConstants.VAR_USER.equals(localPart)) {
return new ItemPathType(itemPath.rest());
return itemPath.rest();
} else {
LOGGER.warn("Mapping target variable name '{}' is not supported for determination of correlation item path in {}",
variableName, attributeDefinition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,8 @@ default boolean isDisplayNameAttribute() {
}

@Override
@Nullable
default ItemCorrelationDefinitionType getCorrelationDefinitionBean() {
return delegate().getCorrelationDefinitionBean();
default @Nullable ItemCorrelatorDefinitionType getCorrelatorDefinition() {
return delegate().getCorrelatorDefinition();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,8 @@ default boolean isDisplayNameAttribute() {
}

@Override
@Nullable
default ItemCorrelationDefinitionType getCorrelationDefinitionBean() {
return delegate().getCorrelationDefinitionBean();
default @Nullable ItemCorrelatorDefinitionType getCorrelatorDefinition() {
return delegate().getCorrelatorDefinition();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

package com.evolveum.midpoint.schema.util;

import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.util.CloneUtil;
import com.evolveum.midpoint.util.DebugUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

Expand All @@ -27,7 +29,7 @@ public class CorrelationItemDefinitionUtil {
/**
* Returns the name under which we will reference this item definition (using "ref" elements).
*/
public static @NotNull String getName(@NotNull ItemCorrelationType definitionBean) {
public static @NotNull String getName(@NotNull CorrelationItemType definitionBean) {
if (definitionBean.getName() != null) {
return definitionBean.getName();
}
Expand Down Expand Up @@ -124,4 +126,22 @@ public static String identify(@Nullable AbstractCorrelatorType configBean) {
return null;
}
}

public static void addSingleItemCorrelator(
@NotNull CorrelationDefinitionType overallCorrelationDefBean,
@NotNull ItemPath focusItemPath,
@NotNull ItemCorrelatorDefinitionType attributeCorrelatorDefBean) {
CompositeCorrelatorType correlators = overallCorrelationDefBean.getCorrelators();
if (correlators == null) {
correlators = new CompositeCorrelatorType();
overallCorrelationDefBean.setCorrelators(correlators);
}
correlators.getItems().add(
new ItemsSubCorrelatorType()
.item(new CorrelationItemType()
.ref(
new ItemPathType(focusItemPath))
.search(
CloneUtil.clone(attributeCorrelatorDefBean.getSearch()))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3995,19 +3995,18 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="correlation" type="tns:ItemCorrelationDefinitionType" minOccurs="0">
<xsd:element name="correlator" type="tns:ItemCorrelatorDefinitionType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Specifies the correlation for this item. Currently, it is supported only for definitions
of resource attributes. But later we plan to extend the support also to focal item definitions.
Creates a single-item correlator for this item.

For attributes this automatically employs "beforeCorrelation" mapping evaluation phase.
For attributes this automatically turns on "beforeCorrelation" mapping evaluation phase.
(If not explicitly forbidden in the attribute definition.)
</xsd:documentation>
<xsd:appinfo>
<a:since>4.6</a:since>
<a:experimental>true</a:experimental>
<a:displayName>ItemRefinedDefinitionType.correlation</a:displayName>
<a:displayName>ItemRefinedDefinitionType.correlator</a:displayName>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
Expand Down Expand Up @@ -8508,6 +8507,19 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="correlation" type="tns:ItemCorrelationDefinitionType" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
Specifies the correlation-related aspects of this item, for example, the search method to be used
by default.
</xsd:documentation>
<xsd:appinfo>
<a:since>4.6</a:since>
<a:experimental>true</a:experimental>
<a:displayName>ItemRefinedDefinitionType.correlation</a:displayName>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
Expand Down

0 comments on commit 4a9c8e4

Please sign in to comment.