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
  • 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

      @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: TrackableDomainMapperMemberSupport
      Perform a mapping operation that will either create a special delete sandbox state for a domain instance, or will archive an instance. See TrackableRepository 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 interface TrackableDomainMapperMemberSupport
      Parameters:
      repositoryDomain - The domain instance to inactivate
      contextInfo - 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 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. 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 interface TrackableDomainMapperMemberSupport
      Type Parameters:
      P - The business domain type
      Parameters:
      domain - The Trackable repository domain
      business - 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 tracking
      fromMeMapper - 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.
    • 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 interface TrackableDomainMapperMemberSupport
      Parameters:
      details - unfiltered list of changes
      shouldOptimizeDirtyEmbeddedCollections - 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 a 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.
      Parameters:
      detail -
      Returns:
    • buildTracking

      public void buildTracking(ContextInfo contextInfo, Trackable domainInstance, List<ChangeDetail> details)
      Description copied from interface: TrackableDomainMapperMemberSupport
      Compile the Tracking information for a new change
      Specified by:
      buildTracking in interface TrackableDomainMapperMemberSupport
      Parameters:
      contextInfo - The context information used to determine sandbox and multitenant state in tracking
      domainInstance - The repository domain instance
      details - The details of the current change
    • isMappingResetRequired

      public boolean isMappingResetRequired(Trackable domainInstance, ContextInfo contextInfo)
      Description copied from interface: TrackableDomainMapperMemberSupport
      Whether or not the id will be reset during modify or delete mapping.
      Specified by:
      isMappingResetRequired in interface TrackableDomainMapperMemberSupport
      Parameters:
      domainInstance - The repository domain instance for which mapping will occur
      contextInfo - 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

      public void buildTracking(Trackable domainInstance, List<ChangeDetail> details)
      Description copied from interface: TrackableDomainMapperMemberSupport
      Compile the Tracking information for a new change. This method does not take into account any information harvested from a ContextInfo instance.
      Specified by:
      buildTracking in interface TrackableDomainMapperMemberSupport
      Parameters:
      domainInstance - The repository domain instance
      details - 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 interface TrackableDomainMapperMemberSupport
      Parameters:
      repositoryDomain - persistence-based domain instance that is being changed
      details - list of change details for the fields that were impacted
      Returns:
      the updated change details with ChangeDetail.setAfterValue(String) modified with the result from repositoryDomain
    • buildChangeDetailBefore

      public ChangeDetail buildChangeDetailBefore(ContextInfo contextInfo, Trackable repositoryDomain, String propertyName, PropertyTypeInfo propertyTypeInfo, String businessPropertyName)
      Description copied from interface: TrackableDomainMapperMemberSupport
      Construct a ChangeDetail instance that represents the value of soon-to-be dirty field before the mutating change is applied.
      Specified by:
      buildChangeDetailBefore in interface TrackableDomainMapperMemberSupport
      Parameters:
      contextInfo - The context information used to determine sandbox and multitenant state in tracking
      repositoryDomain - The persisted domain instance
      propertyName - The name of the property being changed
      propertyTypeInfo - a PropertyTypeInfo describing the changed field's type
      businessPropertyName - 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: TrackableDomainMapperMemberSupport
      Convert a Type to a JavaType and serialize as a Base64 encoded string for storage. Used for subsequent resurrection of serialized objects.
      Specified by:
      getSerializedType in interface TrackableDomainMapperMemberSupport
      Parameters:
      type - The java reflective type
      Returns:
      Base64 encoded string result of serializing a JavaType instance
    • updateChangeSummaryState

      protected void updateChangeSummaryState(Trackable entity, Tracking tracking)
    • updatePersistenceMessageState

      protected void updatePersistenceMessageState(Trackable entity, Tracking tracking)
    • shouldCompileDetails

      protected boolean shouldCompileDetails(Class<?> entityClass)
      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 the SuppressNotificationContext.isCompileChangeDetails() if it's available.

      If all of the IgnoredNotificationStateRepository.isCompileChangeDetails() is false and SuppressNotificationContext is available, the result from IgnoredNotificationStateRepository only takes precedence if it also has IgnoredNotificationStateRepository.getMessageType() defined, otherwise the result from SuppressNotificationContext is used.

    • getIgnoredNotificationStateRepositories

      @NonNull protected List<com.broadleafcommerce.common.messaging.notification.IgnoredNotificationStateRepository> getIgnoredNotificationStateRepositories(Object repository)
    • getRepositoryForEntity

      protected Object getRepositoryForEntity(Class<?> entityClass)
    • shouldBuildNotificationState

      protected boolean shouldBuildNotificationState(Trackable entity, String eventType)
      Determines if a notification state should be created for the supplied entity.
      Parameters:
      entity - The entity to check
      eventType - The event type
      Returns:
      true if notification state should be created for the supplied event type, else false.
    • optimizeDirtyEmbeddedCollection

      protected ChangeDetail optimizeDirtyEmbeddedCollection(ChangeDetail detail)
      Optimize ChangeDetail 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

      protected void internalOptimizeDirtyEmbeddedCollection(ChangeDetail detail)
      Optimize ChangeDetail 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)
      Optimize 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.

      Parameters:
      detail - the dirty embedded iterable change detail to optimize
      javaType - 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)
      Optimize 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.

      Parameters:
      detail - the dirty embedded iterable change detail to optimize
      javaType - the type of the embedded iterable
    • optimizeDirtyEmbeddedSimpleList

      protected void optimizeDirtyEmbeddedSimpleList(ChangeDetail detail)
      Optimize 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.

      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 between before and after.
      Type Parameters:
      T - the type of element
      Parameters:
      before - the list of elements before the change
      after - 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 between 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.

      Parameters:
      before - the list of elements before the change
      after - the list of elements after the change
      collectionJavaType - 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 between beforeElement and afterElement.
      Parameters:
      beforeElement - the element before the change
      afterElement - the element after the change
    • optimizeDirtyEmbeddedMap

      protected void optimizeDirtyEmbeddedMap(ChangeDetail detail, com.fasterxml.jackson.databind.JavaType javaType)
      Optimize ChangeDetail for a dirty embedded map by removing unchanged entries and fields.
      Parameters:
      detail - the dirty embedded map change detail to optimize
      javaType - the type of the embedded map
    • isGenericObjectMap

      protected boolean isGenericObjectMap(com.fasterxml.jackson.databind.JavaType javaType)
    • optimizeDirtyEmbeddedComplexMap

      protected void optimizeDirtyEmbeddedComplexMap(ChangeDetail detail)
      Optimize ChangeDetail 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

      protected void optimizeDirtyEmbeddedSimpleMap(ChangeDetail detail)
      Optimize ChangeDetail for 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 between before and after.
      Type Parameters:
      T - the type of the map value
      Parameters:
      before - the map before the change
      after - 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 between before and after.
      Parameters:
      before - the map before the change
      after - 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 are 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.

      Parameters:
      detail - the dirty embedded other collection change detail to optimize
      javaType - 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()