public class DefaultTrackableDomainMapperMemberSupport extends Object implements TrackableDomainMapperMemberSupport
REFLECTIVE_ERROR, SYSTEM
Constructor and 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) |
Modifier and Type | Method and Description |
---|---|
List<ChangeDetail> |
buildChangeDetailAfter(Object repositoryDomain,
List<ChangeDetail> details)
Populate the field values after mutation for a changed repository domain instance.
|
ChangeDetail |
buildChangeDetailBefore(ContextInfo contextInfo,
Trackable repositoryDomain,
String propertyName,
PropertyTypeInfo propertyTypeInfo,
String businessPropertyName)
Construct a
ChangeDetail 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 in
ContextState 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 the
Tracking information for a new change |
void |
buildTracking(Trackable domainInstance,
List<ChangeDetail> details)
Compile the
Tracking information for a new change. |
List<ChangeDetail> |
compileDirty(List<ChangeDetail> details,
boolean shouldOptimizeDirtyEmbeddedCollections)
Given a list of changes, determine which are actually dirty.
|
protected TrackableBehaviorUtil |
getBehaviorUtil() |
protected CatalogFinder<Catalog> |
getCatalogFinder() |
protected org.modelmapper.ModelMapper |
getCloneMapper() |
protected ContextStateBuilder |
getContextStateBuilder() |
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 |
getFactory() |
protected ChangeTransformerHelper |
getHelper() |
protected List<com.broadleafcommerce.common.messaging.notification.IgnoredNotificationStateRepository> |
getIgnoredRepositories() |
protected com.fasterxml.jackson.core.type.TypeReference<javax.money.MonetaryAmount> |
getMonetaryAmountTypeReference() |
protected PolicyUtils |
getPolicyUtils() |
protected RepositoryUtility |
getRepositoryUtility() |
String |
getSerializedType(Type type)
Convert a
Type to a JavaType and serialize as a Base64 encoded string for
storage. |
Trackable |
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 |
internalOptimizeDirtyEmbeddedCollection(ChangeDetail detail)
Optimize
ChangeDetail for a dirty embedded collection by removing unchanged elements
and fields. |
protected boolean |
isDirty(ChangeDetail detail)
Method to allow us to determine if a
ChangeDetail is dirty. |
protected boolean |
isGenericObjectList(com.fasterxml.jackson.databind.JavaType javaType) |
protected boolean |
isGenericObjectMap(com.fasterxml.jackson.databind.JavaType javaType) |
protected ChangeDetail |
optimizeDirtyEmbeddedCollection(ChangeDetail detail)
Optimize
ChangeDetail for a dirty embedded collection by removing unchanged elements
and fields. |
protected void |
optimizeDirtyEmbeddedComplexList(ChangeDetail detail,
com.fasterxml.jackson.databind.JavaType javaType)
Optimize
ChangeDetail for a dirty embedded iterable by removing unchanged elements
and fields. |
protected void |
optimizeDirtyEmbeddedComplexMap(ChangeDetail detail)
Optimize
ChangeDetail 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)
Optimize
ChangeDetail 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 between
before and after . |
protected void |
optimizeDirtyEmbeddedMap(ChangeDetail detail,
com.fasterxml.jackson.databind.JavaType javaType)
Optimize
ChangeDetail 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 between
before and after . |
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 |
optimizeDirtyEmbeddedSimpleList(ChangeDetail detail)
Optimize
ChangeDetail for a dirty embedded iterable by removing unchanged elements. |
protected void |
optimizeDirtyEmbeddedSimpleMap(ChangeDetail detail)
Optimize
ChangeDetail 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 between
beforeElement and afterElement . |
protected <T> void |
removeUnchangedEmbeddedListElements(List<T> before,
List<T> after)
Remove elements which were not changed between
before and after . |
protected <T> void |
removeUnchangedEmbeddedMapEntries(Map<String,T> before,
Map<String,T> after)
Remove entries which were not changed between
before and after . |
void |
setIgnoredRepositories(List<com.broadleafcommerce.common.messaging.notification.IgnoredNotificationStateRepository> ignoredRepositories) |
void |
setPolicyUtils(PolicyUtils policyUtils) |
void |
setRepositoryUtility(RepositoryUtility repositoryUtility) |
protected boolean |
shouldCompileDetails(Class<?> entityClass) |
protected void |
updateChangeSummaryState(Trackable entity,
Tracking tracking) |
protected void |
updatePersistenceMessageState(Trackable entity,
Tracking tracking) |
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)
@Autowired public void setPolicyUtils(@Nullable PolicyUtils policyUtils)
@Autowired public void setIgnoredRepositories(@Nullable List<com.broadleafcommerce.common.messaging.notification.IgnoredNotificationStateRepository> ignoredRepositories)
@Autowired public void setRepositoryUtility(@Nullable @Lazy RepositoryUtility repositoryUtility)
public Trackable handleDelete(Trackable repositoryDomain, ContextInfo contextInfo)
TrackableDomainMapperMemberSupport
TrackableRepository
for more info
on persistence behavior based on context. This generally results in a cloned entity to
represent sandbox delete state.handleDelete
in interface TrackableDomainMapperMemberSupport
repositoryDomain
- The domain instance to inactivatecontextInfo
- The context information used to make tracking determinations relevant to
sandboxing and multitenant concerns.public <P> void buildContextState(Trackable domain, P business, @Nullable ContextInfo contextInfo, @Nullable org.modelmapper.ModelMapper fromMeMapper)
TrackableDomainMapperMemberSupport
ContextState
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).buildContextState
in interface TrackableDomainMapperMemberSupport
P
- The business domain typedomain
- The Trackable repository domainbusiness
- The business domain mapped from the repository domain. Iff the business
domain implements ContextStateAware
, calculated ContextState will be added.contextInfo
- The context information used to determine sandbox and multitenant state in
trackingfromMeMapper
- if domain
is ModelMapperMappable
, this should contain the
result of ModelMapperMappable.fromMe()
. This mapper is used to perform any
necessary conversion from persisted instances to business instances. If domain
is not ModelMapperMappable
, then this should be left null.public List<ChangeDetail> compileDirty(List<ChangeDetail> details, boolean shouldOptimizeDirtyEmbeddedCollections)
TrackableDomainMapperMemberSupport
If we should optimizeDirtyEmbeddedCollections
, then any details containing
collections will be optimized to remove non-dirty elements, and non-dirty fields of elements.
compileDirty
in interface TrackableDomainMapperMemberSupport
details
- unfiltered list of changesshouldOptimizeDirtyEmbeddedCollections
- whether to include only dirty elements and element
fields of embedded collection detailsprotected boolean isDirty(@NonNull ChangeDetail detail)
ChangeDetail
is dirty. By default this compares
the beforeValue and afterValue for equality. If they are not equal, then if the
ChangeDetail.getSerializedFieldType()
returns a classname that is a subclass or
implementation of Number
or MonetaryAmount
then those instances are
constructed and compared to ensure that leading or trailing zeros don't cause false
positives.detail
- public void buildTracking(ContextInfo contextInfo, Trackable domainInstance, List<ChangeDetail> details)
TrackableDomainMapperMemberSupport
Tracking
information for a new changebuildTracking
in interface TrackableDomainMapperMemberSupport
contextInfo
- The context information used to determine sandbox and multitenant state in
trackingdomainInstance
- The repository domain instancedetails
- The details of the current changepublic void buildTracking(Trackable domainInstance, List<ChangeDetail> details)
TrackableDomainMapperMemberSupport
Tracking
information for a new change. This method does not take into
account any information harvested from a ContextInfo
instance.buildTracking
in interface TrackableDomainMapperMemberSupport
domainInstance
- The repository domain instancedetails
- The details of the current changepublic List<ChangeDetail> buildChangeDetailAfter(Object repositoryDomain, List<ChangeDetail> details)
TrackableDomainMapperMemberSupport
buildChangeDetailAfter
in interface TrackableDomainMapperMemberSupport
repositoryDomain
- persistence-based domain instance that is being changeddetails
- list of change details for the fields that were impactedChangeDetail.setAfterValue(String)
modified
with the result from repositoryDomain
public ChangeDetail buildChangeDetailBefore(ContextInfo contextInfo, Trackable repositoryDomain, String propertyName, PropertyTypeInfo propertyTypeInfo, String businessPropertyName)
TrackableDomainMapperMemberSupport
ChangeDetail
instance that represents the value of soon-to-be dirty field
before the mutating change is applied.buildChangeDetailBefore
in interface TrackableDomainMapperMemberSupport
contextInfo
- The context information used to determine sandbox and multitenant state in
trackingrepositoryDomain
- The persisted domain instancepropertyName
- The name of the property being changedpropertyTypeInfo
- a PropertyTypeInfo
describing the changed field's typebusinessPropertyName
- The name of the property on the business domainpublic String getSerializedType(Type type)
TrackableDomainMapperMemberSupport
Type
to a JavaType
and serialize as a Base64 encoded string for
storage. Used for subsequent resurrection of serialized objects.getSerializedType
in interface TrackableDomainMapperMemberSupport
type
- The java reflective typeJavaType
instanceprotected void updateChangeSummaryState(Trackable entity, Tracking tracking)
protected void updatePersistenceMessageState(Trackable entity, Tracking tracking)
protected boolean shouldCompileDetails(Class<?> entityClass)
protected ChangeDetail optimizeDirtyEmbeddedCollection(ChangeDetail detail)
ChangeDetail
for a dirty embedded collection by removing unchanged elements
and fields.detail
- the dirty change detail to optimizeprotected void internalOptimizeDirtyEmbeddedCollection(ChangeDetail detail)
ChangeDetail
for a dirty embedded collection by removing unchanged elements
and fields.detail
- the dirty change detail to optimizeprotected void optimizeDirtyEmbeddedList(ChangeDetail detail, com.fasterxml.jackson.databind.JavaType javaType)
ChangeDetail
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.
detail
- the dirty embedded iterable change detail to optimizejavaType
- the type of the embedded iterableprotected boolean isGenericObjectList(com.fasterxml.jackson.databind.JavaType javaType)
protected void optimizeDirtyEmbeddedComplexList(ChangeDetail detail, com.fasterxml.jackson.databind.JavaType javaType)
ChangeDetail
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.
detail
- the dirty embedded iterable change detail to optimizejavaType
- the type of the embedded iterableprotected void optimizeDirtyEmbeddedSimpleList(ChangeDetail detail)
ChangeDetail
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.
detail
- the dirty embedded iterable change detail to optimizeprotected <T> void removeUnchangedEmbeddedListElements(List<T> before, List<T> after)
before
and after
.T
- the type of elementbefore
- the list of elements before the changeafter
- the list of elements after the changeprotected void optimizeDirtyEmbeddedListElementFields(List<Map<String,Object>> before, List<Map<String,Object>> after, com.fasterxml.jackson.databind.JavaType collectionJavaType)
before
and after
.
In order to determine which after
element is the changed version of a before
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.
before
- the list of elements before the changeafter
- the list of elements after the changecollectionJavaType
- the type of the embedded iterableIllegalArgumentException
- if unable to find an id field@NonNull protected String getEmbeddedCollectionElementIdFieldName(com.fasterxml.jackson.databind.JavaType collectionJavaType)
collectionJavaType
- the type of the embedded iterableIllegalArgumentException
- if unable to find an id fieldprotected void removeUnchangedEmbeddedCollectionElementFields(Map<String,Object> beforeElement, Map<String,Object> afterElement)
beforeElement
and afterElement
.beforeElement
- the element before the changeafterElement
- the element after the changeprotected void optimizeDirtyEmbeddedMap(ChangeDetail detail, com.fasterxml.jackson.databind.JavaType javaType)
ChangeDetail
for a dirty embedded map by removing unchanged entries and
fields.detail
- the dirty embedded map change detail to optimizejavaType
- the type of the embedded mapprotected boolean isGenericObjectMap(com.fasterxml.jackson.databind.JavaType javaType)
protected void optimizeDirtyEmbeddedComplexMap(ChangeDetail detail)
ChangeDetail
for a dirty embedded map of complex objects by removing
unchanged entries and fields.detail
- the dirty embedded map change detail to optimizeprotected void optimizeDirtyEmbeddedSimpleMap(ChangeDetail detail)
ChangeDetail
for a dirty embedded map of simple objects by removing
unchanged entries.detail
- the dirty embedded map change detail to optimizeprotected <T> void removeUnchangedEmbeddedMapEntries(Map<String,T> before, Map<String,T> after)
before
and after
.T
- the type of the map valuebefore
- the map before the changeafter
- the map after the changeprotected void optimizeDirtyEmbeddedMapEntryFields(Map<String,Map<String,Object>> before, Map<String,Map<String,Object>> after)
before
and after
.before
- the map before the changeafter
- the map after the changeprotected void optimizeDirtyEmbeddedOther(ChangeDetail detail, com.fasterxml.jackson.databind.JavaType javaType)
Iterable
, 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.
detail
- the dirty embedded other collection change detail to optimizejavaType
- the type of the embedded other collectionprotected com.fasterxml.jackson.core.type.TypeReference<javax.money.MonetaryAmount> getMonetaryAmountTypeReference()
protected com.broadleafcommerce.common.extension.TypeFactory getFactory()
protected TrackableBehaviorUtil getBehaviorUtil()
protected org.modelmapper.ModelMapper getCloneMapper()
protected ContextStateBuilder getContextStateBuilder()
protected CatalogFinder<Catalog> getCatalogFinder()
protected List<com.broadleafcommerce.common.messaging.notification.IgnoredNotificationStateRepository> getIgnoredRepositories()
protected RepositoryUtility getRepositoryUtility()
protected PolicyUtils getPolicyUtils()
protected ChangeTransformerHelper getHelper()
Copyright © 2021. All rights reserved.