Class ModelMapperDomainMapperMember
java.lang.Object
com.broadleafcommerce.data.tracking.core.mapping.ModelMapperDomainMapperMember
- All Implemented Interfaces:
com.broadleafcommerce.common.extension.data.DataRoutePartitionAware,DomainMapper,DomainMapperMember,org.springframework.core.Ordered
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
-
Field Summary
Fields inherited from interface com.broadleafcommerce.common.extension.data.DataRoutePartitionAware
ALL_MATCHFields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionModelMapperDomainMapperMember(TrackableDomainMapperMemberSupport trackableSupport, TrackableBehaviorUtil trackableBehaviorUtil) -
Method Summary
Modifier and TypeMethodDescriptionprotected <D extends Trackable>
List<ChangeDetail>buildDetailsBefore(D repositoryDomain, ContextInfo contextInfo, org.modelmapper.TypeMap<?, ?> repositoryTypeMap) protected voidbuildNameToTypeMap(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.<D> DdeleteMap(D repositoryDomain, ContextInfo contextInfo) In cases where deletion actually results in a modified state to persist (e.g.org.modelmapper.ModelMapperfabricateFromMe(Object projection, Object entity) Derive aModelMapperbased on the starting entity and target projection instances.org.modelmapper.ModelMapperfabricateToMe(Object projection, Object entity, boolean allowNull) Derive aModelMapperbased on the starting projection and target entity instances.<D> DfromBusinessDomain(Object businessDomain, D repositoryDomain, ContextInfo contextInfo) Map and return a populated repository domain instance, based on information provided in a business domain.<P> PfromRepositoryDomain(Object repositoryDomain, P businessDomain, ContextInfo contextInfo) Map and return a populated business domain instance, based on information provided in a repository domain instance.org.modelmapper.Convertervoidinit()protected <D extends Trackable>
booleanisCatalogOrSandboxTrackable(D repositoryDomain) protected booleanisCollectionType(Class<?> fieldType) Determines whether the givenfieldTypefrom aPropertyMappingis a known type of collection field.protected booleanisModelMapperAutoConfigurationDisabled(Object repositoryDomain) protected <D,P> D mapToRepositoryDomain(D repositoryDomain, P businessDomain, ContextInfo contextInfo, org.modelmapper.ModelMapper mapper) protected <D extends Trackable,P>
booleanmapWithTracking(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 compileChangeDetailinstances to include in theTrackingstate.<D,P> D modifyMap(D repositoryDomain, P businessDomain, ContextInfo contextInfo, boolean allowNull) Perform a mapping operation from business domain instance to persistence specific instance, presumably modifying the state of the persistence specific instance.protected voidpopulateFromMeReferredTypeOverrides(org.modelmapper.ModelMapper from) protected voidpopulateToMeReferredTypeOverrides(org.modelmapper.ModelMapper to) voidsetEm(jakarta.persistence.EntityManager em) voidsetOverrides(List<com.broadleafcommerce.common.extension.mapping.ProjectionReferredTypeOverride> overrides) voidsetPostToMeConverter(org.modelmapper.Converter postToMeConverter) protected voidsetupFromMeInheritance(Object projection, Object entity, org.modelmapper.ModelMapper from, org.modelmapper.TypeMap fromMap) protected voidsetupToMeInheritance(Object projection, Object entity, org.modelmapper.ModelMapper to, org.modelmapper.TypeMap toMap) protected <D extends Trackable>
booleanshouldBuildChangeDetails(D repositoryDomain, ContextInfo contextInfo) Determine if dirty change details should be built for this domain.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.broadleafcommerce.data.tracking.core.mapping.DomainMapper
getBusinessDomainTypeMethods inherited from interface com.broadleafcommerce.data.tracking.core.mapping.DomainMapperMember
getOrder
-
Constructor Details
-
ModelMapperDomainMapperMember
public ModelMapperDomainMapperMember(TrackableDomainMapperMemberSupport trackableSupport, TrackableBehaviorUtil trackableBehaviorUtil)
-
-
Method Details
-
init
@PostConstruct public void init() -
getDataRoutePartition
- Specified by:
getDataRoutePartitionin interfacecom.broadleafcommerce.common.extension.data.DataRoutePartitionAware
-
fromBusinessDomain
Description copied from interface:DomainMapperMemberMap 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:
fromBusinessDomainin interfaceDomainMapperMember- Type Parameters:
D- The repository domain type- Parameters:
businessDomain- The business instance containing the relevant property informationrepositoryDomain- The repository specific instance to affect and returncontextInfo- The context information used to make tracking determinations relevant to sandboxing and multitenant concerns. SeeTrackableRepositoryfor 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:DomainMapperMemberMap 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:
fromRepositoryDomainin interfaceDomainMapperMember- Type Parameters:
P- The business domain type- Parameters:
repositoryDomain- The repository domain instance containing the relevant property informationbusinessDomain- The business domain instance to affect and returncontextInfo- The context information used to make tracking determinations relevant to sandboxing and multitenant concerns. SeeTrackableRepositoryfor 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:DomainMapperPerform a mapping operation from business domain instance to persistence specific instance, presumably modifying the state of the persistence specific instance.- Specified by:
modifyMapin interfaceDomainMapper- Type Parameters:
D- The repository domain typeP- The business domain type- Parameters:
repositoryDomain- The persistence domain instance to modifybusinessDomain- The business instance containing changes to map to the repository domaincontextInfo- The context information used to make tracking determinations relevant to sandboxing and multitenant concerns. SeeTrackableRepositoryfor 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
Description copied from interface:DomainMapperIn 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:
deleteMapin interfaceDomainMapper- Type Parameters:
D- The repository domain type- Parameters:
repositoryDomain- The persistence domain instance to inactivatecontextInfo- 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
-
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 aModelMapperbased on the starting projection and target entity instances. Take into account entity extensions that do not implementModelMapperMappablewith calculated mapping.- Parameters:
projection- The projection instance from which to pull informationentity- The starting entity instance to map toallowNull- Whether or not to allow null mapping- Returns:
- The configured model mapper instance
-
fabricateFromMe
Derive aModelMapperbased on the starting entity and target projection instances. Take into account entity extensions that do not implementModelMapperMappablewith calculated mapping.- Parameters:
projection- The projection instance to map toentity- 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 compileChangeDetailinstances to include in theTrackingstate.- Type Parameters:
D- The domain typeP- The payload type- Parameters:
repositoryDomain- The persistence-based domain instance that is being changedmodifications- The payload instancecontextInfo- The context information used to determine sandbox and multitenant state in trackingmapper- The mapping engine used to transfer values between payload and domain- Returns:
- whether or not the given
repositoryDomainwas 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 forcontextInfo- The context information used to determine sandbox and multitenant state in tracking- Returns:
- whether dirty change details should be built
-
isCatalogOrSandboxTrackable
-
buildDetailsBefore
protected <D extends Trackable> List<ChangeDetail> buildDetailsBefore(D repositoryDomain, ContextInfo contextInfo, org.modelmapper.TypeMap<?, ?> repositoryTypeMap) throws IllegalAccessException- Throws:
IllegalAccessException
-
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 theTypeMap.
-
isCollectionType
Determines whether the givenfieldTypefrom aPropertyMappingis a known type of collection field. The default known types are array,Iterable, andMap.- Parameters:
fieldType- TheClassof a field specified by aPropertyMapping- Returns:
- Whether the fieldType is a know type of collection field.
-
populateToMeReferredTypeOverrides
protected void populateToMeReferredTypeOverrides(org.modelmapper.ModelMapper to) -
populateFromMeReferredTypeOverrides
protected void populateFromMeReferredTypeOverrides(org.modelmapper.ModelMapper from) -
setupFromMeInheritance
-
setupToMeInheritance
-
getMappers
-
setOverrides
@Autowired public void setOverrides(@Nullable List<com.broadleafcommerce.common.extension.mapping.ProjectionReferredTypeOverride> overrides) -
setEm
@Autowired public void setEm(@Nullable jakarta.persistence.EntityManager em) -
getPostToMeConverter
public org.modelmapper.Converter getPostToMeConverter() -
setPostToMeConverter
public void setPostToMeConverter(org.modelmapper.Converter postToMeConverter)
-