java.lang.Object
com.evolveum.midpoint.gui.impl.page.admin.resource.component.wizard.schemaHandling.MappingUtils

public class MappingUtils extends Object
Utility methods for working with mapping wrappers in the resource schema handling wizard.

Provides helpers to:

  • Create new virtual MappingType values and their UI wrappers.
  • Assemble synthetic containers of mappings for table components.
  • Insert hidden virtual ref properties to support UI editing.
  • Clone and initialize attribute definitions with inbound mappings if required.
  • Extract ref values from various attribute container types.
These utilities are intended to keep the UI model in sync with the underlying Prism structures while providing a consistent user experience in forms and tables.
  • Constructor Details

    • MappingUtils

      public MappingUtils()
  • Method Details

    • createNewVirtualMappingValue

      @Nullable public static <P extends Containerable, AD extends Containerable> @Nullable PrismContainerValueWrapper<MappingType> createNewVirtualMappingValue(@Nullable @Nullable PrismContainerValue<MappingType> value, @NotNull @NotNull org.apache.wicket.model.IModel<PrismContainerValueWrapper<P>> valueModel, @NotNull @NotNull MappingDirection mappingDirection, @NotNull @NotNull ItemName itemNameOfContainerWithMappings, @NotNull @NotNull ItemName itemNameOfRefAttribute, @NotNull @NotNull PageBase pageBase, org.apache.wicket.ajax.AjaxRequestTarget target)
      Creates a new virtual MappingType value for the given container model.

      A new attribute mapping container value is created, wrapped for UI, marked with the specified MappingDirection, and initialized with a strong mapping strength. A hidden virtual ref property is also created so that the UI can properly display the mapping.

      Parameters:
      value - optional mapping value to reuse, otherwise a new one is created
      valueModel - model of the parent container value wrapper
      mappingDirection - direction of the mapping (e.g. inbound/outbound)
      itemNameOfContainerWithMappings - item name of the container holding mappings
      itemNameOfRefAttribute - item name of the reference attribute
      pageBase - current page context
      target - Ajax target for UI updates
      Returns:
      created mapping value wrapper, or null if creation failed
    • createVirtualMappingContainerModel

      @NotNull public static <P extends Containerable, AD extends Containerable> @NotNull org.apache.wicket.model.IModel<PrismContainerWrapper<MappingType>> createVirtualMappingContainerModel(@NotNull @NotNull PageBase pageBase, @NotNull @NotNull org.apache.wicket.model.IModel<PrismContainerValueWrapper<P>> valueModel, @NotNull @NotNull ItemName itemNameOfContainerWithMappings, @NotNull @NotNull ItemName itemNameOfRefAttribute, @NotNull @NotNull MappingDirection mappingDirection)
      Builds a virtual container model for MappingType values.

      The returned model collects all mappings of the specified direction from the given parent value, ensures each one has a hidden virtual ref property, and presents them as a synthetic container suitable for use in tables or forms.

      Parameters:
      pageBase - current page context
      valueModel - model of the parent container value wrapper
      itemNameOfContainerWithMappings - item name of the container holding mappings
      itemNameOfRefAttribute - item name of the reference attribute
      mappingDirection - direction of mappings to collect
      Returns:
      model of a virtual mapping container
    • createVirtualItemInMapping

      public static <AD extends Containerable> void createVirtualItemInMapping(@NotNull @NotNull PrismContainerValueWrapper<MappingType> mapping, @Nullable @Nullable PrismContainerValueWrapper<AD> value, @NotNull @NotNull PrismPropertyDefinition<Object> propertyDef, @NotNull @NotNull PageBase pageBase, @NotNull @NotNull ItemName itemNameOfRefAttribute, @NotNull @NotNull MappingDirection mappingDirection)
      Creates a virtual ref property inside the given mapping, if it does not already exist.

      The virtual item is initialized from the provided attribute value (if present), wrapped for UI, hidden from the user, and inserted into the mapping container to ensure consistent editing in forms and tables.

      Parameters:
      mapping - mapping container value wrapper where the virtual item is created
      value - optional parent attribute value to initialize the ref from
      propertyDef - definition of the reference property
      pageBase - current page context
      itemNameOfRefAttribute - item name of the reference attribute
      mappingDirection - mapping direction (used for display name and context)
    • createDirectRefVirtualItemInMapping

      public static void createDirectRefVirtualItemInMapping(@NotNull @NotNull PrismContainerValueWrapper<MappingType> mapping, @Nullable @Nullable ItemPathType attributeRefAttributeValue, @NotNull @NotNull PrismPropertyDefinition<Object> propertyDef, @NotNull @NotNull PageBase pageBase, @NotNull @NotNull ItemName itemNameOfRefAttribute, @NotNull @NotNull MappingDirection mappingDirection)
    • getAttributeRefAttributeValue

      @Nullable public static <AD extends Containerable> @Nullable ItemPathType getAttributeRefAttributeValue(@Nullable @Nullable PrismContainerValueWrapper<AD> value)
      Extracts the ref value from the given attribute container wrapper.

      Supports multiple container types (e.g. ResourceAttributeDefinitionType, AttributeInboundMappingsDefinitionType, AttributeOutboundMappingsDefinitionType, ShadowAssociationDefinitionType). Returns null if the value is missing or not of a supported type.

      Type Parameters:
      AD - concrete attribute container type
      Parameters:
      value - wrapper of an attribute container
      Returns:
      extracted ItemPathType reference, or null if unavailable
    • getPathBaseOnMappingType

      public static ItemName getPathBaseOnMappingType(MappingDirection mappingDirection)
      Resolves the container item name corresponding to the given mapping direction.
      Parameters:
      mappingDirection - direction of the mapping (may be null)
      Returns:
      item name of the container for this direction, or null if direction is not provided
    • createMappingsValueIfRequired

      public static void createMappingsValueIfRequired(@NotNull @NotNull PageBase pageBase, @NotNull @NotNull org.apache.wicket.model.IModel<PrismContainerValueWrapper<ResourceObjectTypeDefinitionType>> resourceObjectTypeDefinition, @Nullable @Nullable List<ResourceAttributeDefinitionType> candidateAttributes, @NotNull @NotNull ResourceDetailsModel assignmentHolderDetailsModel)
      Ensures that inbound mapping values exist for the given candidate attributes.

      Each provided ResourceAttributeDefinitionType is cloned, added into the attribute container of the given resource object type definition, wrapped for UI, and initialized with a hidden virtual ref property. The visible ref is cleared so the user can edit it in the form.

      Parameters:
      pageBase - current page context
      resourceObjectTypeDefinition - model of the resource object type definition wrapper
      candidateAttributes - attributes to be added (may-be null or empty)
      assignmentHolderDetailsModel - context used when creating wrappers
    • addNewMappingValue

      public static <P extends Containerable> void addNewMappingValue(@NotNull @NotNull PageBase pageBase, @NotNull @NotNull org.apache.wicket.model.IModel<PrismContainerValueWrapper<P>> resourceObjectTypeDefinition, @NotNull @NotNull ResourceDetailsModel assignmentHolderDetailsModel, @NotNull @NotNull ResourceAttributeDefinitionType newAttribute) throws SchemaException
      Throws:
      SchemaException
    • excludeUnwantedMappings

      public static void excludeUnwantedMappings(@NotNull @NotNull List<PrismContainerValueWrapper<MappingType>> list, MappingUsedFor usedFor)
      Filters the given list in place, keeping only mappings matching the specified usage type. Mappings whose use value differs from usedFor are removed.
    • isExcludedMapping

      public static boolean isExcludedMapping(MappingUsedFor usedFor, @NotNull @NotNull PrismContainerValueWrapper<MappingType> valueWrapper)