Class DefaultTrackableDomainMapperMemberSupport
- java.lang.Object
-
- com.broadleafcommerce.data.tracking.core.mapping.DefaultTrackableDomainMapperMemberSupport
-
- All Implemented Interfaces:
TrackableDomainMapperMemberSupport
public class DefaultTrackableDomainMapperMemberSupport extends Object implements TrackableDomainMapperMemberSupport
- Author:
- Jeff Fischer
-
-
Field Summary
-
Fields inherited from interface com.broadleafcommerce.data.tracking.core.mapping.TrackableDomainMapperMemberSupport
REFLECTIVE_ERROR, SYSTEM
-
-
Constructor Summary
Constructors Constructor Description 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 Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description List<ChangeDetail>buildChangeDetailAfter(Object repositoryDomain, List<ChangeDetail> details)Populate the field values after mutation for a changed repository domain instance.ChangeDetailbuildChangeDetailBefore(ContextInfo contextInfo, Trackable repositoryDomain, String propertyName, PropertyTypeInfo propertyTypeInfo, String businessPropertyName)Construct aChangeDetailinstance that represents the value of soon-to-be dirty field before the mutating change is applied.<P> voidbuildContextState(Trackable domain, P business, ContextInfo contextInfo, org.modelmapper.ModelMapper fromMeMapper)Add inContextStateinformation to the business domain that can be inspected for additional metadata around the entity in relation to the context of the requester.voidbuildTracking(ContextInfo contextInfo, Trackable domainInstance, List<ChangeDetail> details)Compile theTrackinginformation for a new changevoidbuildTracking(Trackable domainInstance, List<ChangeDetail> details)Compile theTrackinginformation for a new change.List<ChangeDetail>compileDirty(List<ChangeDetail> details, boolean shouldOptimizeDirtyEmbeddedCollections)Given a list of changes, determine which are actually dirty.protected TrackableBehaviorUtilgetBehaviorUtil()protected CatalogFinder<Catalog>getCatalogFinder()protected org.modelmapper.ModelMappergetCloneMapper()protected ContextStateBuildergetContextStateBuilder()protected StringgetEmbeddedCollectionElementIdFieldName(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.TypeFactorygetFactory()protected ChangeTransformerHelpergetHelper()protected List<com.broadleafcommerce.common.messaging.notification.IgnoredNotificationStateRepository>getIgnoredRepositories()protected com.fasterxml.jackson.core.type.TypeReference<javax.money.MonetaryAmount>getMonetaryAmountTypeReference()protected PolicyUtilsgetPolicyUtils()protected RepositoryUtilitygetRepositoryUtility()StringgetSerializedType(Type type)Convert aTypeto aJavaTypeand serialize as a Base64 encoded string for storage.TrackablehandleDelete(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 voidinternalOptimizeDirtyEmbeddedCollection(ChangeDetail detail)OptimizeChangeDetailfor a dirty embedded collection by removing unchanged elements and fields.protected booleanisDirty(ChangeDetail detail)Method to allow us to determine if aChangeDetailis dirty.protected booleanisGenericObjectList(com.fasterxml.jackson.databind.JavaType javaType)protected booleanisGenericObjectMap(com.fasterxml.jackson.databind.JavaType javaType)protected ChangeDetailoptimizeDirtyEmbeddedCollection(ChangeDetail detail)OptimizeChangeDetailfor a dirty embedded collection by removing unchanged elements and fields.protected voidoptimizeDirtyEmbeddedComplexList(ChangeDetail detail, com.fasterxml.jackson.databind.JavaType javaType)OptimizeChangeDetailfor a dirty embedded iterable by removing unchanged elements and fields.protected voidoptimizeDirtyEmbeddedComplexMap(ChangeDetail detail)OptimizeChangeDetailfor a dirty embedded map of complex objects by removing unchanged entries and fields.protected voidoptimizeDirtyEmbeddedList(ChangeDetail detail, com.fasterxml.jackson.databind.JavaType javaType)OptimizeChangeDetailfor a dirty embedded iterable by removing unchanged elements and fields.protected voidoptimizeDirtyEmbeddedListElementFields(List<Map<String,Object>> before, List<Map<String,Object>> after, com.fasterxml.jackson.databind.JavaType collectionJavaType)Remove fields which were not changed betweenbeforeandafter.protected voidoptimizeDirtyEmbeddedMap(ChangeDetail detail, com.fasterxml.jackson.databind.JavaType javaType)OptimizeChangeDetailfor a dirty embedded map by removing unchanged entries and fields.protected voidoptimizeDirtyEmbeddedMapEntryFields(Map<String,Map<String,Object>> before, Map<String,Map<String,Object>> after)Remove fields which were not changed betweenbeforeandafter.protected voidoptimizeDirtyEmbeddedOther(ChangeDetail detail, com.fasterxml.jackson.databind.JavaType javaType)Extension point for optimizing an embedded collection of a type not supported by default.protected voidoptimizeDirtyEmbeddedSimpleList(ChangeDetail detail)OptimizeChangeDetailfor a dirty embedded iterable by removing unchanged elements.protected voidoptimizeDirtyEmbeddedSimpleMap(ChangeDetail detail)OptimizeChangeDetailfor a dirty embedded map of simple objects by removing unchanged entries.protected voidremoveUnchangedEmbeddedCollectionElementFields(Map<String,Object> beforeElement, Map<String,Object> afterElement)Remove fields which were not changed betweenbeforeElementandafterElement.protected <T> voidremoveUnchangedEmbeddedListElements(List<T> before, List<T> after)Remove elements which were not changed betweenbeforeandafter.protected <T> voidremoveUnchangedEmbeddedMapEntries(Map<String,T> before, Map<String,T> after)Remove entries which were not changed betweenbeforeandafter.voidsetIgnoredRepositories(List<com.broadleafcommerce.common.messaging.notification.IgnoredNotificationStateRepository> ignoredRepositories)voidsetPolicyUtils(PolicyUtils policyUtils)voidsetRepositoryUtility(RepositoryUtility repositoryUtility)protected booleanshouldCompileDetails(Class<?> entityClass)protected voidupdateChangeSummaryState(Trackable entity, Tracking tracking)protected voidupdatePersistenceMessageState(Trackable entity, Tracking tracking)
-
-
-
Constructor Detail
-
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 Detail
-
setPolicyUtils
@Autowired public void setPolicyUtils(@Nullable PolicyUtils policyUtils)
-
setIgnoredRepositories
@Autowired public void setIgnoredRepositories(@Nullable List<com.broadleafcommerce.common.messaging.notification.IgnoredNotificationStateRepository> ignoredRepositories)
-
setRepositoryUtility
@Autowired public void setRepositoryUtility(@Nullable @Lazy RepositoryUtility repositoryUtility)
-
handleDelete
public Trackable handleDelete(Trackable repositoryDomain, ContextInfo contextInfo)
Description copied from interface:TrackableDomainMapperMemberSupportPerform a mapping operation that will either create a special delete sandbox state for a domain instance, or will archive an instance. SeeTrackableRepositoryfor more info on persistence behavior based on context. This generally results in a cloned entity to represent sandbox delete state.- Specified by:
handleDeletein 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:TrackableDomainMapperMemberSupportAdd inContextStateinformation 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:
buildContextStatein 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- ifdomainisModelMapperMappable, this should contain the result ofModelMapperMappable.fromMe(). This mapper is used to perform any necessary conversion from persisted instances to business instances. Ifdomainis notModelMapperMappable, then this should be left null.
-
compileDirty
public List<ChangeDetail> compileDirty(List<ChangeDetail> details, boolean shouldOptimizeDirtyEmbeddedCollections)
Description copied from interface:TrackableDomainMapperMemberSupportGiven 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:
compileDirtyin 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
protected boolean isDirty(@NonNull ChangeDetail detail)Method to allow us to determine if aChangeDetailis 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 ofNumberorMonetaryAmountthen 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:TrackableDomainMapperMemberSupportCompile theTrackinginformation for a new change- Specified by:
buildTrackingin 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
-
buildTracking
public void buildTracking(Trackable domainInstance, List<ChangeDetail> details)
Description copied from interface:TrackableDomainMapperMemberSupportCompile theTrackinginformation for a new change. This method does not take into account any information harvested from aContextInfoinstance.- Specified by:
buildTrackingin 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:TrackableDomainMapperMemberSupportPopulate the field values after mutation for a changed repository domain instance.- Specified by:
buildChangeDetailAfterin 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:TrackableDomainMapperMemberSupportConstruct aChangeDetailinstance that represents the value of soon-to-be dirty field before the mutating change is applied.- Specified by:
buildChangeDetailBeforein 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- aPropertyTypeInfodescribing the changed field's typebusinessPropertyName- The name of the property on the business domain- Returns:
- The resulting change detail for the dirty field
-
getSerializedType
public String getSerializedType(Type type)
Description copied from interface:TrackableDomainMapperMemberSupportConvert aTypeto aJavaTypeand serialize as a Base64 encoded string for storage. Used for subsequent resurrection of serialized objects.- Specified by:
getSerializedTypein interfaceTrackableDomainMapperMemberSupport- Parameters:
type- The java reflective type- Returns:
- Base64 encoded string result of serializing a
JavaTypeinstance
-
updateChangeSummaryState
protected void updateChangeSummaryState(Trackable entity, Tracking tracking)
-
updatePersistenceMessageState
protected void updatePersistenceMessageState(Trackable entity, Tracking tracking)
-
shouldCompileDetails
protected boolean shouldCompileDetails(Class<?> entityClass)
-
optimizeDirtyEmbeddedCollection
protected ChangeDetail optimizeDirtyEmbeddedCollection(ChangeDetail detail)
OptimizeChangeDetailfor 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
protected void internalOptimizeDirtyEmbeddedCollection(ChangeDetail detail)
OptimizeChangeDetailfor 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)
OptimizeChangeDetailfor 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)
OptimizeChangeDetailfor 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
protected void optimizeDirtyEmbeddedSimpleList(ChangeDetail detail)
OptimizeChangeDetailfor 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
protected <T> void removeUnchangedEmbeddedListElements(List<T> before, List<T> after)
Remove elements which were not changed betweenbeforeandafter.- 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 betweenbeforeandafter.In order to determine which
afterelement is the changed version of abeforeelement, 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 betweenbeforeElementandafterElement.- Parameters:
beforeElement- the element before the changeafterElement- the element after the change
-
optimizeDirtyEmbeddedMap
protected void optimizeDirtyEmbeddedMap(ChangeDetail detail, com.fasterxml.jackson.databind.JavaType javaType)
OptimizeChangeDetailfor 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
protected void optimizeDirtyEmbeddedComplexMap(ChangeDetail detail)
OptimizeChangeDetailfor a dirty embedded map of complex objects by removing unchanged entries and fields.- Parameters:
detail- the dirty embedded map change detail to optimize
-
optimizeDirtyEmbeddedSimpleMap
protected void optimizeDirtyEmbeddedSimpleMap(ChangeDetail detail)
OptimizeChangeDetailfor a dirty embedded map of simple objects by removing unchanged entries.- Parameters:
detail- the dirty embedded map change detail to optimize
-
removeUnchangedEmbeddedMapEntries
protected <T> void removeUnchangedEmbeddedMapEntries(Map<String,T> before, Map<String,T> after)
Remove entries which were not changed betweenbeforeandafter.- 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 betweenbeforeandafter.- 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
protected TrackableBehaviorUtil getBehaviorUtil()
-
getCloneMapper
protected org.modelmapper.ModelMapper getCloneMapper()
-
getContextStateBuilder
protected ContextStateBuilder getContextStateBuilder()
-
getCatalogFinder
protected CatalogFinder<Catalog> getCatalogFinder()
-
getIgnoredRepositories
protected List<com.broadleafcommerce.common.messaging.notification.IgnoredNotificationStateRepository> getIgnoredRepositories()
-
getRepositoryUtility
protected RepositoryUtility getRepositoryUtility()
-
getPolicyUtils
protected PolicyUtils getPolicyUtils()
-
getHelper
protected ChangeTransformerHelper getHelper()
-
-