Class DefaultTrackableDomainMapperMemberSupport

    • 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: 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:
      • 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
      • 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)
        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()
      • getCloneMapper

        protected org.modelmapper.ModelMapper getCloneMapper()
      • getIgnoredRepositories

        protected List<com.broadleafcommerce.common.messaging.notification.IgnoredNotificationStateRepository> getIgnoredRepositories()
      • getPolicyUtils

        protected PolicyUtils getPolicyUtils()