Interface TrackableDomainMapperMemberSupport

All Known Implementing Classes:
DefaultTrackableDomainMapperMemberSupport

public interface TrackableDomainMapperMemberSupport
Exposes the functionality necessary to support maintenance of Trackable domain instances. The intent is for DomainMapperMember classes to inject this bean in order to benefit from tracking maintenance during mapping. This separates the ability to track changes from the method of mapping data between the repository domain and the business domain. DomainMapperMembers who want to conditionally support Tracking maintenance should gate access to these support methods based on whether or not the entity being process supports Trackable.
Author:
Jeff Fischer
  • Field Details

  • Method Details

    • handleDelete

      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. See TrackableRepository for more info on persistence behavior based on context. This generally results in a cloned entity to represent sandbox delete state.
      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

      <P> void buildContextState(Trackable domain, P business, @Nullable ContextInfo contextInfo, @Nullable 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. This information can be used to make determination around mutability, as well as details around the nature of field change state (if any).
      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.
      Throws:
      IllegalContextStateException - Thrown because of an error detected in the tracking context state that prevents the ContextState from being built. This is usually due to errors detected in the domain's ChangeDetails or mismatching fields/field types between the tracking and business domains.
      ContextStateProcessingException - Thrown when a non-state related error occurs when attempting to build the ContextState. This is usually related to building the ContextState for the business item's embedded collections. For examples,
      • when invoking (not finding) the correct accessor of a collection field on the businessItem encounters an error.
      • when a ChangeDetail's before or after values cannot be deserialized once a change for a collection has been detected.
    • compileDirty

      List<ChangeDetail> compileDirty(List<ChangeDetail> originalDetails, boolean optimizeDirtyEmbeddedCollections)
      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.

      Parameters:
      originalDetails - unfiltered list of changes
      optimizeDirtyEmbeddedCollections - whether to include only dirty elements and element fields of embedded collection details
      Returns:
      filtered list of changes containing only dirty changes.
    • buildTracking

      void buildTracking(ContextInfo contextInfo, Trackable domainInstance, List<ChangeDetail> details)
      Compile the Tracking information for a new change
      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

      boolean isMappingResetRequired(Trackable domainInstance, ContextInfo contextInfo)
      Whether or not the id will be reset during modify or delete mapping.
      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

      void buildTracking(Trackable domainInstance, List<ChangeDetail> details)
      Compile the Tracking information for a new change. This method does not take into account any information harvested from a ContextInfo instance.
      Parameters:
      domainInstance - The repository domain instance
      details - The details of the current change
    • buildChangeDetailAfter

      List<ChangeDetail> buildChangeDetailAfter(Object repositoryDomain, List<ChangeDetail> details)
      Populate the field values after mutation for a changed repository domain instance.
      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

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

      String getSerializedType(Type type)
      Convert a Type to a JavaType and serialize as a Base64 encoded string for storage. Used for subsequent resurrection of serialized objects.
      Parameters:
      type - The java reflective type
      Returns:
      Base64 encoded string result of serializing a JavaType instance