Class DefaultTrackableDomainMapperMemberSupport
- All Implemented Interfaces:
TrackableDomainMapperMemberSupport
- Author:
- Jeff Fischer
-
Field Summary
Fields inherited from interface com.broadleafcommerce.data.tracking.core.mapping.TrackableDomainMapperMemberSupport
REFLECTIVE_ERROR, SYSTEM
-
Constructor Summary
ConstructorDescriptionDefaultTrackableDomainMapperMemberSupport
(com.broadleafcommerce.common.extension.TypeFactory factory, TrackableBehaviorUtil behaviorUtil, com.fasterxml.jackson.databind.ObjectMapper fieldChangeMapper, org.modelmapper.ModelMapper cloneMapper, ContextStateBuilder contextStateBuilder, CatalogFinder<Catalog> catalogFinder) -
Method Summary
Modifier and TypeMethodDescriptionbuildChangeDetailAfter
(Object repositoryDomain, List<ChangeDetail> details) Populate the field values after mutation for a changed repository domain instance.buildChangeDetailBefore
(ContextInfo contextInfo, Trackable repositoryDomain, String propertyName, PropertyTypeInfo propertyTypeInfo, String businessPropertyName) Construct aChangeDetail
instance that represents the value of soon-to-be dirty field before the mutating change is applied.<P> void
buildContextState
(Trackable domain, P business, ContextInfo contextInfo, org.modelmapper.ModelMapper fromMeMapper) Add inContextState
information to the business domain that can be inspected for additional metadata around the entity in relation to the context of the requester.void
buildTracking
(ContextInfo contextInfo, Trackable domainInstance, List<ChangeDetail> details) Compile theTracking
information for a new changevoid
buildTracking
(Trackable domainInstance, List<ChangeDetail> details) Compile theTracking
information for a new change.compileDirty
(List<ChangeDetail> details, boolean shouldOptimizeDirtyEmbeddedCollections) Given a list of changes, determine which are actually dirty.protected TrackableBehaviorUtil
protected CatalogFinder<Catalog>
protected org.modelmapper.ModelMapper
protected ContextStateBuilder
protected String
getEmbeddedCollectionElementIdFieldName
(com.fasterxml.jackson.databind.JavaType collectionJavaType) Get the name of the ID field for the elements of the given collection type.protected com.broadleafcommerce.common.extension.TypeFactory
protected ChangeTransformerHelper
protected List<com.broadleafcommerce.common.messaging.notification.IgnoredNotificationStateRepository>
getIgnoredNotificationStateRepositories
(Object repository) protected List<com.broadleafcommerce.common.messaging.notification.IgnoredNotificationStateRepository>
protected com.fasterxml.jackson.core.type.TypeReference<javax.money.MonetaryAmount>
protected PolicyUtils
protected Object
getRepositoryForEntity
(Class<?> entityClass) protected RepositoryUtility
getSerializedType
(Type type) Convert aType
to aJavaType
and serialize as a Base64 encoded string for storage.handleDelete
(Trackable repositoryDomain, ContextInfo contextInfo) Perform a mapping operation that will either create a special delete sandbox state for a domain instance, or will archive an instance.protected void
OptimizeChangeDetail
for a dirty embedded collection by removing unchanged elements and fields.protected boolean
isDirty
(ChangeDetail detail) Method to allow us to determine if aChangeDetail
is dirty.protected boolean
isGenericObjectList
(com.fasterxml.jackson.databind.JavaType javaType) protected boolean
isGenericObjectMap
(com.fasterxml.jackson.databind.JavaType javaType) boolean
isMappingResetRequired
(Trackable domainInstance, ContextInfo contextInfo) Whether or not the id will be reset during modify or delete mapping.protected ChangeDetail
OptimizeChangeDetail
for a dirty embedded collection by removing unchanged elements and fields.protected void
optimizeDirtyEmbeddedComplexList
(ChangeDetail detail, com.fasterxml.jackson.databind.JavaType javaType) OptimizeChangeDetail
for a dirty embedded iterable by removing unchanged elements and fields.protected void
OptimizeChangeDetail
for a dirty embedded map of complex objects by removing unchanged entries and fields.protected void
optimizeDirtyEmbeddedList
(ChangeDetail detail, com.fasterxml.jackson.databind.JavaType javaType) OptimizeChangeDetail
for a dirty embedded iterable by removing unchanged elements and fields.protected void
optimizeDirtyEmbeddedListElementFields
(List<Map<String, Object>> before, List<Map<String, Object>> after, com.fasterxml.jackson.databind.JavaType collectionJavaType) Remove fields which were not changed betweenbefore
andafter
.protected void
optimizeDirtyEmbeddedMap
(ChangeDetail detail, com.fasterxml.jackson.databind.JavaType javaType) OptimizeChangeDetail
for a dirty embedded map by removing unchanged entries and fields.protected void
optimizeDirtyEmbeddedMapEntryFields
(Map<String, Map<String, Object>> before, Map<String, Map<String, Object>> after) Remove fields which were not changed betweenbefore
andafter
.protected void
optimizeDirtyEmbeddedOther
(ChangeDetail detail, com.fasterxml.jackson.databind.JavaType javaType) Extension point for optimizing an embedded collection of a type not supported by default.protected void
OptimizeChangeDetail
for a dirty embedded iterable by removing unchanged elements.protected void
OptimizeChangeDetail
for a dirty embedded map of simple objects by removing unchanged entries.protected void
removeUnchangedEmbeddedCollectionElementFields
(Map<String, Object> beforeElement, Map<String, Object> afterElement) Remove fields which were not changed betweenbeforeElement
andafterElement
.protected <T> void
removeUnchangedEmbeddedListElements
(List<T> before, List<T> after) Remove elements which were not changed betweenbefore
andafter
.protected <T> void
removeUnchangedEmbeddedMapEntries
(Map<String, T> before, Map<String, T> after) Remove entries which were not changed betweenbefore
andafter
.void
setIgnoredRepositories
(List<com.broadleafcommerce.common.messaging.notification.IgnoredNotificationStateRepository> ignoredRepositories) void
setPolicyUtils
(PolicyUtils policyUtils) void
setRepositoryUtility
(RepositoryUtility repositoryUtility) protected boolean
shouldBuildNotificationState
(Trackable entity, String eventType) Determines if a notification state should be created for the supplied entity.protected boolean
shouldCompileDetails
(Class<?> entityClass) Determines whether to compile change details for the given entity class.protected void
updateChangeSummaryState
(Trackable entity, Tracking tracking) protected void
updatePersistenceMessageState
(Trackable entity, Tracking tracking)
-
Constructor Details
-
DefaultTrackableDomainMapperMemberSupport
public DefaultTrackableDomainMapperMemberSupport(com.broadleafcommerce.common.extension.TypeFactory factory, TrackableBehaviorUtil behaviorUtil, com.fasterxml.jackson.databind.ObjectMapper fieldChangeMapper, org.modelmapper.ModelMapper cloneMapper, ContextStateBuilder contextStateBuilder, CatalogFinder<Catalog> catalogFinder)
-
-
Method Details
-
setPolicyUtils
-
setIgnoredRepositories
@Autowired public void setIgnoredRepositories(@Nullable List<com.broadleafcommerce.common.messaging.notification.IgnoredNotificationStateRepository> ignoredRepositories) -
setRepositoryUtility
-
handleDelete
Description copied from interface:TrackableDomainMapperMemberSupport
Perform a mapping operation that will either create a special delete sandbox state for a domain instance, or will archive an instance. SeeTrackableRepository
for more info on persistence behavior based on context. This generally results in a cloned entity to represent sandbox delete state.- Specified by:
handleDelete
in interfaceTrackableDomainMapperMemberSupport
- Parameters:
repositoryDomain
- The domain instance to inactivatecontextInfo
- The context information used to make tracking determinations relevant to sandboxing and multitenant concerns.- Returns:
- The domain state resulting from the operation (e.g. archived or sandbox delete state)
-
buildContextState
public <P> void buildContextState(Trackable domain, P business, @Nullable ContextInfo contextInfo, @Nullable org.modelmapper.ModelMapper fromMeMapper) Description copied from interface:TrackableDomainMapperMemberSupport
Add inContextState
information to the business domain that can be inspected for additional metadata around the entity in relation to the context of the requester. This information can be used to make determination around mutability, as well as details around the nature of field change state (if any).- Specified by:
buildContextState
in interfaceTrackableDomainMapperMemberSupport
- Type Parameters:
P
- The business domain type- Parameters:
domain
- The Trackable repository domainbusiness
- The business domain mapped from the repository domain. Iff the business domain implementsContextStateAware
, calculated ContextState will be added.contextInfo
- The context information used to determine sandbox and multitenant state in trackingfromMeMapper
- ifdomain
isModelMapperMappable
, this should contain the result ofModelMapperMappable.fromMe()
. This mapper is used to perform any necessary conversion from persisted instances to business instances. Ifdomain
is notModelMapperMappable
, then this should be left null.
-
compileDirty
public List<ChangeDetail> compileDirty(List<ChangeDetail> details, boolean shouldOptimizeDirtyEmbeddedCollections) Description copied from interface:TrackableDomainMapperMemberSupport
Given a list of changes, determine which are actually dirty.If we should
optimizeDirtyEmbeddedCollections
, then any details containing collections will be optimized to remove non-dirty elements, and non-dirty fields of elements.- Specified by:
compileDirty
in interfaceTrackableDomainMapperMemberSupport
- Parameters:
details
- unfiltered list of changesshouldOptimizeDirtyEmbeddedCollections
- whether to include only dirty elements and element fields of embedded collection details- Returns:
- filtered list of changes containing only dirty changes.
-
isDirty
Method to allow us to determine if aChangeDetail
is dirty. By default this compares the beforeValue and afterValue for equality. If they are not equal, then if theChangeDetail.getSerializedFieldType()
returns a classname that is a subclass or implementation ofNumber
orMonetaryAmount
then those instances are constructed and compared to ensure that leading or trailing zeros don't cause false positives.- Parameters:
detail
-- Returns:
-
buildTracking
public void buildTracking(ContextInfo contextInfo, Trackable domainInstance, List<ChangeDetail> details) Description copied from interface:TrackableDomainMapperMemberSupport
Compile theTracking
information for a new change- Specified by:
buildTracking
in interfaceTrackableDomainMapperMemberSupport
- Parameters:
contextInfo
- The context information used to determine sandbox and multitenant state in trackingdomainInstance
- The repository domain instancedetails
- The details of the current change
-
isMappingResetRequired
Description copied from interface:TrackableDomainMapperMemberSupport
Whether or not the id will be reset during modify or delete mapping.- Specified by:
isMappingResetRequired
in interfaceTrackableDomainMapperMemberSupport
- Parameters:
domainInstance
- The repository domain instance for which mapping will occurcontextInfo
- The context information used to determine sandbox and multitenant state in tracking- Returns:
- Whether or not the id will be reset during modify or delete mapping
-
buildTracking
Description copied from interface:TrackableDomainMapperMemberSupport
Compile theTracking
information for a new change. This method does not take into account any information harvested from aContextInfo
instance.- Specified by:
buildTracking
in interfaceTrackableDomainMapperMemberSupport
- Parameters:
domainInstance
- The repository domain instancedetails
- The details of the current change
-
buildChangeDetailAfter
public List<ChangeDetail> buildChangeDetailAfter(Object repositoryDomain, List<ChangeDetail> details) Description copied from interface:TrackableDomainMapperMemberSupport
Populate the field values after mutation for a changed repository domain instance.- Specified by:
buildChangeDetailAfter
in interfaceTrackableDomainMapperMemberSupport
- Parameters:
repositoryDomain
- persistence-based domain instance that is being changeddetails
- list of change details for the fields that were impacted- Returns:
- the updated change details with
ChangeDetail.setAfterValue(String)
modified with the result fromrepositoryDomain
-
buildChangeDetailBefore
public ChangeDetail buildChangeDetailBefore(ContextInfo contextInfo, Trackable repositoryDomain, String propertyName, PropertyTypeInfo propertyTypeInfo, String businessPropertyName) Description copied from interface:TrackableDomainMapperMemberSupport
Construct aChangeDetail
instance that represents the value of soon-to-be dirty field before the mutating change is applied.- Specified by:
buildChangeDetailBefore
in interfaceTrackableDomainMapperMemberSupport
- Parameters:
contextInfo
- The context information used to determine sandbox and multitenant state in trackingrepositoryDomain
- The persisted domain instancepropertyName
- The name of the property being changedpropertyTypeInfo
- aPropertyTypeInfo
describing the changed field's typebusinessPropertyName
- The name of the property on the business domain- Returns:
- The resulting change detail for the dirty field
-
getSerializedType
Description copied from interface:TrackableDomainMapperMemberSupport
Convert aType
to aJavaType
and serialize as a Base64 encoded string for storage. Used for subsequent resurrection of serialized objects.- Specified by:
getSerializedType
in interfaceTrackableDomainMapperMemberSupport
- Parameters:
type
- The java reflective type- Returns:
- Base64 encoded string result of serializing a
JavaType
instance
-
updateChangeSummaryState
-
updatePersistenceMessageState
-
shouldCompileDetails
Determines whether to compile change details for the given entity class.It looks at the
IgnoredNotificationStateRepository.isCompileChangeDetails()
associated with the given entity class, if any one of them is true, it will also look at theSuppressNotificationContext.isCompileChangeDetails()
if it's available.If all of the
IgnoredNotificationStateRepository.isCompileChangeDetails()
is false andSuppressNotificationContext
is available, the result fromIgnoredNotificationStateRepository
only takes precedence if it also hasIgnoredNotificationStateRepository.getMessageType()
defined, otherwise the result fromSuppressNotificationContext
is used. -
getIgnoredNotificationStateRepositories
-
getRepositoryForEntity
-
shouldBuildNotificationState
Determines if a notification state should be created for the supplied entity.- Parameters:
entity
- The entity to checkeventType
- The event type- Returns:
- true if notification state should be created for the supplied event type, else false.
-
optimizeDirtyEmbeddedCollection
OptimizeChangeDetail
for a dirty embedded collection by removing unchanged elements and fields.- Parameters:
detail
- the dirty change detail to optimize- Returns:
- the optimized dirty change detail
-
internalOptimizeDirtyEmbeddedCollection
OptimizeChangeDetail
for a dirty embedded collection by removing unchanged elements and fields.- Parameters:
detail
- the dirty change detail to optimize
-
optimizeDirtyEmbeddedList
protected void optimizeDirtyEmbeddedList(ChangeDetail detail, com.fasterxml.jackson.databind.JavaType javaType) OptimizeChangeDetail
for a dirty embedded iterable by removing unchanged elements and fields.Note that the optimizations performed here will not retain re-ordering changes. The relative order of dirty elements will be respected. However, unchanged elements are removed, so there are no guarantees on their relative ordering.
- Parameters:
detail
- the dirty embedded iterable change detail to optimizejavaType
- the type of the embedded iterable
-
isGenericObjectList
protected boolean isGenericObjectList(com.fasterxml.jackson.databind.JavaType javaType) -
optimizeDirtyEmbeddedComplexList
protected void optimizeDirtyEmbeddedComplexList(ChangeDetail detail, com.fasterxml.jackson.databind.JavaType javaType) OptimizeChangeDetail
for a dirty embedded iterable by removing unchanged elements and fields.Note that the optimizations performed here will not retain re-ordering changes. The relative order of dirty elements will be respected. However, unchanged elements are removed, so there are no guarantees on their relative ordering.
- Parameters:
detail
- the dirty embedded iterable change detail to optimizejavaType
- the type of the embedded iterable
-
optimizeDirtyEmbeddedSimpleList
OptimizeChangeDetail
for a dirty embedded iterable by removing unchanged elements.Note that the optimizations performed here will not retain re-ordering changes. The relative order of dirty elements will be respected. However, unchanged elements are removed, so there are no guarantees on their relative ordering.
- Parameters:
detail
- the dirty embedded iterable change detail to optimize
-
removeUnchangedEmbeddedListElements
Remove elements which were not changed betweenbefore
andafter
.- Type Parameters:
T
- the type of element- Parameters:
before
- the list of elements before the changeafter
- the list of elements after the change
-
optimizeDirtyEmbeddedListElementFields
protected void optimizeDirtyEmbeddedListElementFields(List<Map<String, Object>> before, List<Map<String, Object>> after, com.fasterxml.jackson.databind.JavaType collectionJavaType) Remove fields which were not changed betweenbefore
andafter
.In order to determine which
after
element is the changed version of abefore
element, we must match them by their ID. If the ID field on the element type cannot be found, then unchanged fields will not be removed.- Parameters:
before
- the list of elements before the changeafter
- the list of elements after the changecollectionJavaType
- the type of the embedded iterable- Throws:
IllegalArgumentException
- if unable to find an id field
-
getEmbeddedCollectionElementIdFieldName
@NonNull protected String getEmbeddedCollectionElementIdFieldName(com.fasterxml.jackson.databind.JavaType collectionJavaType) Get the name of the ID field for the elements of the given collection type.- Parameters:
collectionJavaType
- the type of the embedded iterable- Returns:
- the name of the element id field
- Throws:
IllegalArgumentException
- if unable to find an id field
-
removeUnchangedEmbeddedCollectionElementFields
protected void removeUnchangedEmbeddedCollectionElementFields(Map<String, Object> beforeElement, Map<String, Object> afterElement) Remove fields which were not changed betweenbeforeElement
andafterElement
.- Parameters:
beforeElement
- the element before the changeafterElement
- the element after the change
-
optimizeDirtyEmbeddedMap
protected void optimizeDirtyEmbeddedMap(ChangeDetail detail, com.fasterxml.jackson.databind.JavaType javaType) OptimizeChangeDetail
for a dirty embedded map by removing unchanged entries and fields.- Parameters:
detail
- the dirty embedded map change detail to optimizejavaType
- the type of the embedded map
-
isGenericObjectMap
protected boolean isGenericObjectMap(com.fasterxml.jackson.databind.JavaType javaType) -
optimizeDirtyEmbeddedComplexMap
OptimizeChangeDetail
for a dirty embedded map of complex objects by removing unchanged entries and fields.- Parameters:
detail
- the dirty embedded map change detail to optimize
-
optimizeDirtyEmbeddedSimpleMap
OptimizeChangeDetail
for a dirty embedded map of simple objects by removing unchanged entries.- Parameters:
detail
- the dirty embedded map change detail to optimize
-
removeUnchangedEmbeddedMapEntries
Remove entries which were not changed betweenbefore
andafter
.- Type Parameters:
T
- the type of the map value- Parameters:
before
- the map before the changeafter
- the map after the change
-
optimizeDirtyEmbeddedMapEntryFields
protected void optimizeDirtyEmbeddedMapEntryFields(Map<String, Map<String, Object>> before, Map<String, Map<String, Object>> after) Remove fields which were not changed betweenbefore
andafter
.- Parameters:
before
- the map before the changeafter
- the map after the change
-
optimizeDirtyEmbeddedOther
protected void optimizeDirtyEmbeddedOther(ChangeDetail detail, com.fasterxml.jackson.databind.JavaType javaType) Extension point for optimizing an embedded collection of a type not supported by default. Default supported collections areIterable
,Map
, and arrays.Note that the optimizations performed here will not retain re-ordering changes. The relative order of dirty elements will be respected. However, unchanged elements are removed, so there are no guarantees on their relative ordering.
- Parameters:
detail
- the dirty embedded other collection change detail to optimizejavaType
- the type of the embedded other collection
-
getMonetaryAmountTypeReference
protected com.fasterxml.jackson.core.type.TypeReference<javax.money.MonetaryAmount> getMonetaryAmountTypeReference() -
getFactory
protected com.broadleafcommerce.common.extension.TypeFactory getFactory() -
getBehaviorUtil
-
getCloneMapper
protected org.modelmapper.ModelMapper getCloneMapper() -
getContextStateBuilder
-
getCatalogFinder
-
getIgnoredRepositories
protected List<com.broadleafcommerce.common.messaging.notification.IgnoredNotificationStateRepository> getIgnoredRepositories() -
getRepositoryUtility
-
getPolicyUtils
-
getHelper
-