Class ModelMapperDomainMapperMember

  • All Implemented Interfaces:
    com.broadleafcommerce.common.extension.data.DataRoutePartitionAware, DomainMapper, DomainMapperMember, org.springframework.core.Ordered

    public class ModelMapperDomainMapperMember
    extends Object
    implements DomainMapperMember
    This DomainMapperMember implementation utilizes the ModelMapper library as the method of mapping between repository domain and business domain. The approach for informing the mapping is taken from ModelMapperMappable implementing entities. As such, repositoryDomain instances that do not implement ModelMapperMappable will not be transformed by this class. The expectation would be that another DomainMapperMember instance would be registered and responsible for transformation. Additionally, this class will also maintain tracking information for repository domain implementing the Trackable interface. In the absence of the Trackable interface, no maintenance of tracking information will be performed.
    Author:
    Jeff Fischer
    • Method Detail

      • getDataRoutePartition

        public String getDataRoutePartition()
        Specified by:
        getDataRoutePartition in interface com.broadleafcommerce.common.extension.data.DataRoutePartitionAware
      • fromBusinessDomain

        public <D> D fromBusinessDomain​(Object businessDomain,
                                        D repositoryDomain,
                                        ContextInfo contextInfo)
        Description copied from interface: DomainMapperMember
        Map and return a populated repository domain instance, based on information provided in a business domain. The passed repositoryDomain parameter is generally transformed and returned.
        Specified by:
        fromBusinessDomain in interface DomainMapperMember
        Type Parameters:
        D - The repository domain type
        Parameters:
        businessDomain - The business instance containing the relevant property information
        repositoryDomain - The repository specific instance to affect and return
        contextInfo - The context information used to make tracking determinations relevant to sandboxing and multitenant concerns. See TrackableRepository for more info on persistence behavior based on context.
        Returns:
        The populated repository domain instance. Should return null if no action taken.
      • fromRepositoryDomain

        public <P> P fromRepositoryDomain​(Object repositoryDomain,
                                          P businessDomain,
                                          ContextInfo contextInfo)
        Description copied from interface: DomainMapperMember
        Map and return a populated business domain instance, based on information provided in a repository domain instance. The passed businessDomain parameter is generally transformed and returned.
        Specified by:
        fromRepositoryDomain in interface DomainMapperMember
        Type Parameters:
        P - The business domain type
        Parameters:
        repositoryDomain - The repository domain instance containing the relevant property information
        businessDomain - The business domain instance to affect and return
        contextInfo - The context information used to make tracking determinations relevant to sandboxing and multitenant concerns. See TrackableRepository for more info on persistence behavior based on context.
        Returns:
        The populated business domain instance. Should return null if no action taken.
      • modifyMap

        public <D,​P> D modifyMap​(D repositoryDomain,
                                       P businessDomain,
                                       ContextInfo contextInfo,
                                       boolean allowNull)
        Description copied from interface: DomainMapper
        Perform a mapping operation from business domain instance to persistence specific instance, presumably modifying the state of the persistence specific instance.
        Specified by:
        modifyMap in interface DomainMapper
        Type Parameters:
        D - The repository domain type
        P - The business domain type
        Parameters:
        repositoryDomain - The persistence domain instance to modify
        businessDomain - The business instance containing changes to map to the repository domain
        contextInfo - The context information used to make tracking determinations relevant to sandboxing and multitenant concerns. See TrackableRepository for more info on persistence behavior based on context.
        allowNull - Whether or not null values in properties in the payload instance should be ignored during the mapping operation.
        Returns:
        The modified repository domain instance. Return null if no action taken.
      • deleteMap

        public <D> D deleteMap​(D repositoryDomain,
                               ContextInfo contextInfo)
        Description copied from interface: DomainMapper
        In cases where deletion actually results in a modified state to persist (e.g. archived soft delete), this method will modify the state appropriately toward that end.
        Specified by:
        deleteMap in interface DomainMapper
        Type Parameters:
        D - The repository domain type
        Parameters:
        repositoryDomain - The persistence domain instance to inactivate
        contextInfo - The context information used to make tracking determinations relevant to sandboxing and multitenant concerns.
        Returns:
        The repository domain state resulting from the delete operation. Return null if no action taken.
      • isModelMapperAutoConfigurationDisabled

        protected boolean isModelMapperAutoConfigurationDisabled​(Object repositoryDomain)
      • mapToRepositoryDomain

        protected <D,​P> D mapToRepositoryDomain​(D repositoryDomain,
                                                      P businessDomain,
                                                      ContextInfo contextInfo,
                                                      org.modelmapper.ModelMapper mapper)
      • fabricateToMe

        public org.modelmapper.ModelMapper fabricateToMe​(Object projection,
                                                         Object entity,
                                                         boolean allowNull)
        Derive a ModelMapper based on the starting projection and target entity instances. Take into account entity extensions that do not implement ModelMapperMappable with calculated mapping.
        Parameters:
        projection - The projection instance from which to pull information
        entity - The starting entity instance to map to
        allowNull - Whether or not to allow null mapping
        Returns:
        The configured model mapper instance
      • fabricateFromMe

        public org.modelmapper.ModelMapper fabricateFromMe​(Object projection,
                                                           Object entity)
        Derive a ModelMapper based on the starting entity and target projection instances. Take into account entity extensions that do not implement ModelMapperMappable with calculated mapping.
        Parameters:
        projection - The projection instance to map to
        entity - The starting entity instance from which to pull information
        Returns:
        The configured model mapper instance
      • mapWithTracking

        protected <D extends Trackable,​P> boolean mapWithTracking​(D repositoryDomain,
                                                                        P modifications,
                                                                        ContextInfo contextInfo,
                                                                        org.modelmapper.ModelMapper mapper)
        During the mapping operation for properties between the payload and the domain, this will examine the before and after state and compile ChangeDetail instances to include in the Tracking state.
        Type Parameters:
        D - The domain type
        P - The payload type
        Parameters:
        repositoryDomain - The persistence-based domain instance that is being changed
        modifications - The payload instance
        contextInfo - The context information used to determine sandbox and multitenant state in tracking
        mapper - The mapping engine used to transfer values between payload and domain
        Returns:
        whether or not the given repositoryDomain was modified
      • shouldBuildChangeDetails

        protected <D extends Trackable> boolean shouldBuildChangeDetails​(D repositoryDomain,
                                                                         ContextInfo contextInfo)
        Determine if dirty change details should be built for this domain.

        This must be performed after mapping, since information to determine the trackable behavior of the domain may not be available prior to mapping.

        Type Parameters:
        D - the type of the domain
        Parameters:
        repositoryDomain - the domain to possibly build dirty change details for
        contextInfo - The context information used to determine sandbox and multitenant state in tracking
        Returns:
        whether dirty change details should be built
      • isCatalogOrSandboxTrackable

        protected <D extends Trackable> boolean isCatalogOrSandboxTrackable​(D repositoryDomain)
      • buildNameToTypeMap

        protected void buildNameToTypeMap​(Map<org.springframework.data.util.Pair<String,​String>,​PropertyTypeInfo> repositoryNameToType,
                                          Map.Entry<String,​?> entry)
        Build up the repositoryNameToType structure mapping destination and source property name, combined with the destination property type.
        Parameters:
        repositoryNameToType - The structure to build up. The key consists of a Pair, whose first value is the destination property name and whose second value is the source property name. The value of the map is the destination property type.
        entry - The mapping information harvested from the TypeMap.
      • isCollectionType

        protected boolean isCollectionType​(Class<?> fieldType)
        Determines whether the given fieldType from a PropertyMapping is a known type of collection field. The default known types are array, Iterable, and Map.
        Parameters:
        fieldType - The Class of a field specified by a PropertyMapping
        Returns:
        Whether the fieldType is a know type of collection field.
      • getMappers

        public Map<String,​org.modelmapper.ModelMapper> getMappers()