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
public class ModelMapperDomainMapperMember extends Object implements DomainMapperMember
ThisDomainMapperMember
implementation utilizes theModelMapper
library as the method of mapping between repository domain and business domain. The approach for informing the mapping is taken fromModelMapperMappable
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 theTrackable
interface. In the absence of the Trackable interface, no maintenance of tracking information will be performed.- Author:
- Jeff Fischer
-
-
Constructor Summary
Constructors Constructor Description ModelMapperDomainMapperMember(TrackableDomainMapperMemberSupport trackableSupport, TrackableBehaviorUtil trackableBehaviorUtil)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <D extends Trackable>
List<ChangeDetail>buildDetailsBefore(D repositoryDomain, ContextInfo contextInfo, org.modelmapper.TypeMap<?,?> repositoryTypeMap)
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.<D> D
deleteMap(D repositoryDomain, ContextInfo contextInfo)
In cases where deletion actually results in a modified state to persist (e.g.org.modelmapper.ModelMapper
fabricateFromMe(Object projection, Object entity)
Derive aModelMapper
based on the starting entity and target projection instances.org.modelmapper.ModelMapper
fabricateToMe(Object projection, Object entity, boolean allowNull)
Derive aModelMapper
based on the starting projection and target entity instances.<D> D
fromBusinessDomain(Object businessDomain, D repositoryDomain, ContextInfo contextInfo)
Map and return a populated repository domain instance, based on information provided in a business domain.<P> P
fromRepositoryDomain(Object repositoryDomain, P businessDomain, ContextInfo contextInfo)
Map and return a populated business domain instance, based on information provided in a repository domain instance.String
getDataRoutePartition()
Map<String,org.modelmapper.ModelMapper>
getMappers()
org.modelmapper.Converter
getPostToMeConverter()
void
init()
protected <D extends Trackable>
booleanisCatalogOrSandboxTrackable(D repositoryDomain)
protected boolean
isCollectionType(Class<?> fieldType)
Determines whether the givenfieldType
from aPropertyMapping
is a known type of collection field.protected boolean
isModelMapperAutoConfigurationDisabled(Object repositoryDomain)
protected <D,P>
DmapToRepositoryDomain(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 compileChangeDetail
instances to include in theTracking
state.<D,P>
DmodifyMap(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 void
populateFromMeReferredTypeOverrides(org.modelmapper.ModelMapper from)
protected void
populateToMeReferredTypeOverrides(org.modelmapper.ModelMapper to)
void
setEm(javax.persistence.EntityManager em)
void
setOverrides(List<com.broadleafcommerce.common.extension.mapping.ProjectionReferredTypeOverride> overrides)
void
setPostToMeConverter(org.modelmapper.Converter postToMeConverter)
protected void
setupFromMeInheritance(Object projection, Object entity, org.modelmapper.ModelMapper from, org.modelmapper.TypeMap fromMap)
protected void
setupToMeInheritance(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, wait
-
Methods inherited from interface com.broadleafcommerce.data.tracking.core.mapping.DomainMapper
getBusinessDomainType
-
Methods inherited from interface com.broadleafcommerce.data.tracking.core.mapping.DomainMapperMember
getOrder
-
-
-
-
Constructor Detail
-
ModelMapperDomainMapperMember
public ModelMapperDomainMapperMember(TrackableDomainMapperMemberSupport trackableSupport, TrackableBehaviorUtil trackableBehaviorUtil)
-
-
Method Detail
-
init
@PostConstruct public void init()
-
getDataRoutePartition
public String getDataRoutePartition()
- Specified by:
getDataRoutePartition
in interfacecom.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 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. SeeTrackableRepository
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 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. SeeTrackableRepository
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 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. SeeTrackableRepository
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 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
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 aModelMapper
based on the starting projection and target entity instances. Take into account entity extensions that do not implementModelMapperMappable
with 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
public org.modelmapper.ModelMapper fabricateFromMe(Object projection, Object entity)
Derive aModelMapper
based on the starting entity and target projection instances. Take into account entity extensions that do not implementModelMapperMappable
with 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 compileChangeDetail
instances to include in theTracking
state.- 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
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 forcontextInfo
- 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)
-
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
protected boolean isCollectionType(Class<?> fieldType)
Determines whether the givenfieldType
from aPropertyMapping
is a known type of collection field. The default known types are array,Iterable
, andMap
.- Parameters:
fieldType
- TheClass
of 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
protected void setupFromMeInheritance(Object projection, Object entity, org.modelmapper.ModelMapper from, org.modelmapper.TypeMap fromMap)
-
setupToMeInheritance
protected void setupToMeInheritance(Object projection, Object entity, org.modelmapper.ModelMapper to, org.modelmapper.TypeMap toMap)
-
setOverrides
@Autowired public void setOverrides(@Nullable List<com.broadleafcommerce.common.extension.mapping.ProjectionReferredTypeOverride> overrides)
-
setEm
@Autowired public void setEm(@Nullable javax.persistence.EntityManager em)
-
getPostToMeConverter
public org.modelmapper.Converter getPostToMeConverter()
-
setPostToMeConverter
public void setPostToMeConverter(org.modelmapper.Converter postToMeConverter)
-
-