Skip to content

Commit

Permalink
MID-8842 ninja - more type specific mergers, improved search for such…
Browse files Browse the repository at this point in the history
… merger
  • Loading branch information
1azyman committed Sep 12, 2023
1 parent 5a2352e commit 15436b9
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,33 @@ private ItemMerger determineChildMerger(ItemName itemName, PrismContainerValue<?
return byItemName;
}

// Then let's have a look at the type. Currently we use definitions to determine it,
// Then let's have a look at the type. Currently, we use definitions to determine it,
// but maybe we could go with the real values (if this would not work).
ComplexTypeDefinition ctd = sourcePcv.getComplexTypeDefinition();
stateCheck(ctd != null, "No complex type definition of %s", sourcePcv);
ItemDefinition<?> childDef = ctd.findItemDefinition(itemName);
stateCheck(childDef != null, "No definition of %s in %s", itemName, ctd);
Class<?> valueClass = childDef.getTypeClass();
if (valueClass != null) {
Map.Entry<Class<?>, Supplier<ItemMerger>> entryFound = null;
for (Map.Entry<Class<?>, Supplier<ItemMerger>> entry : typeSpecificMergers.entrySet()) {
if (entry.getKey().isAssignableFrom(valueClass)) {
ItemMerger byTypeName = entry.getValue().get();
LOGGER.trace("Type-specific merger for {} (type {}) was found: {}", itemName, valueClass, byTypeName);
return byTypeName;
if (entryFound == null) {
entryFound = entry;
} else {
// we're looking for the most concrete supplier
if (entryFound.getKey().isAssignableFrom(entry.getKey())) {
entryFound = entry;
}
}
}
}

if (entryFound != null) {
ItemMerger byTypeName = entryFound.getValue().get();
LOGGER.trace("Type-specific merger for {} (type {}) was found: {}", itemName, valueClass, byTypeName);
return byTypeName;
}
}

// Finally, let's go with the default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@

package com.evolveum.midpoint.schema.merger;

import static java.util.Map.entry;

import java.util.Map;
import java.util.function.Supplier;

import org.jetbrains.annotations.Nullable;

import com.evolveum.midpoint.schema.merger.assignment.AssignmentMerger;
import com.evolveum.midpoint.schema.merger.key.DefaultNaturalKeyImpl;
import com.evolveum.midpoint.schema.merger.key.ItemPathNaturalKeyImpl;
import com.evolveum.midpoint.schema.merger.objdef.LimitationsMerger;
import com.evolveum.midpoint.schema.merger.resource.ObjectTypeDefinitionMerger;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import org.jetbrains.annotations.Nullable;

import java.util.Map;
import java.util.function.Supplier;

import static java.util.Map.entry;

/**
* Separate class to hold the configuration of type-specific item mergers.
*
Expand Down Expand Up @@ -72,7 +72,7 @@ static Map<Class<?>, Supplier<ItemMerger>> createStandardTypeSpecificMergersMap(
() -> new GenericItemMerger(marker, DefaultNaturalKeyImpl.of(AbstractAuthenticationModuleType.F_IDENTIFIER))),
entry(
AuthenticationSequenceType.class,
() -> new GenericItemMerger(marker, DefaultNaturalKeyImpl.of(AuthenticationSequenceType.F_IDENTIFIER))),
() -> new GenericItemMerger(marker, DefaultNaturalKeyImpl.of(AuthenticationSequenceType.F_IDENTIFIER))),
entry(
ClassLoggerConfigurationType.class,
() -> new GenericItemMerger(marker, DefaultNaturalKeyImpl.of(ClassLoggerConfigurationType.F_PACKAGE))),
Expand All @@ -84,7 +84,9 @@ static Map<Class<?>, Supplier<ItemMerger>> createStandardTypeSpecificMergersMap(
() -> new GenericItemMerger(marker, DefaultNaturalKeyImpl.of(TracingProfileType.F_NAME))),
entry(
HomePageType.class,
() -> new GenericItemMerger(marker, DefaultNaturalKeyImpl.of(HomePageType.F_IDENTIFIER))),
() -> new GenericItemMerger(marker, DefaultNaturalKeyImpl.of(
HomePageType.F_IDENTIFIER,
HomePageType.F_TYPE))),
entry(
PreviewContainerPanelConfigurationType.class,
() -> new GenericItemMerger(marker, DefaultNaturalKeyImpl.of(PreviewContainerPanelConfigurationType.F_IDENTIFIER))),
Expand All @@ -107,9 +109,9 @@ static Map<Class<?>, Supplier<ItemMerger>> createStandardTypeSpecificMergersMap(
DefaultNaturalKeyImpl.of(VirtualContainerItemSpecificationType.F_PATH))),
entry(
GuiResourceDetailsPageType.class,
() -> new GenericItemMerger(
marker,
DefaultNaturalKeyImpl.of(GuiResourceDetailsPageType.F_CONNECTOR_REF))),
() -> new GenericItemMerger(marker, DefaultNaturalKeyImpl.of(
GuiResourceDetailsPageType.F_TYPE,
GuiResourceDetailsPageType.F_CONNECTOR_REF))),
entry(
RoleCollectionViewType.class,
() -> new GenericItemMerger(marker, DefaultNaturalKeyImpl.of(RoleCollectionViewType.F_IDENTIFIER))),
Expand Down Expand Up @@ -209,7 +211,42 @@ static Map<Class<?>, Supplier<ItemMerger>> createStandardTypeSpecificMergersMap(
marker,
DefaultNaturalKeyImpl.of(
ModificationPolicyConstraintType.F_NAME,
ModificationPolicyConstraintType.F_OPERATION)))
);
ModificationPolicyConstraintType.F_OPERATION))),
entry(
AuthenticationSequenceModuleType.class,
() -> new GenericItemMerger(marker, DefaultNaturalKeyImpl.of(AuthenticationSequenceModuleType.F_IDENTIFIER))),
entry(
CredentialPolicyType.class,
() -> new GenericItemMerger(marker, DefaultNaturalKeyImpl.of(CredentialPolicyType.F_NAME))),
entry(
SecurityQuestionDefinitionType.class,
() -> new GenericItemMerger(marker, DefaultNaturalKeyImpl.of(SecurityQuestionDefinitionType.F_IDENTIFIER))),
entry(
SubSystemLoggerConfigurationType.class,
() -> new GenericItemMerger(marker, DefaultNaturalKeyImpl.of(SubSystemLoggerConfigurationType.F_COMPONENT))),
entry(
GuiObjectListViewType.class,
() -> new GenericItemMerger(marker, DefaultNaturalKeyImpl.of(
GuiObjectListViewType.F_IDENTIFIER,
GuiObjectListViewType.F_TYPE))),
entry(
GuiShadowListViewType.class,
() -> new GenericItemMerger(marker, DefaultNaturalKeyImpl.of(
GuiShadowListViewType.F_IDENTIFIER,
GuiShadowListViewType.F_TYPE,
GuiShadowListViewType.F_RESOURCE_REF,
GuiShadowListViewType.F_KIND,
GuiShadowListViewType.F_INTENT))),
entry(
AbstractObjectTypeConfigurationType.class,
() -> new GenericItemMerger(marker, DefaultNaturalKeyImpl.of(AbstractObjectTypeConfigurationType.F_TYPE))),
entry(
GuiShadowDetailsPageType.class,
() -> new GenericItemMerger(marker, DefaultNaturalKeyImpl.of(
GuiShadowDetailsPageType.F_TYPE,
GuiShadowDetailsPageType.F_RESOURCE_REF,
GuiShadowDetailsPageType.F_KIND,
GuiShadowDetailsPageType.F_INTENT))));

}
}

0 comments on commit 15436b9

Please sign in to comment.