Class DefaultSandBoxHelper

java.lang.Object
org.broadleafcommerce.common.sandbox.DefaultSandBoxHelper
All Implemented Interfaces:
SandBoxHelper

@Component("blSandBoxHelper") public class DefaultSandBoxHelper extends Object implements SandBoxHelper
Author:
Jeff Fischer
See Also:
  • Constructor Details

    • DefaultSandBoxHelper

      public DefaultSandBoxHelper()
  • Method Details

    • getSandBoxVersionId

      public Long getSandBoxVersionId(Class<?> linkedObjectType, Long requestedParent)
      Description copied from interface: SandBoxHelper
      Return the sandbox version id for the requested original id. Will return null if no sandbox version is available.
      Specified by:
      getSandBoxVersionId in interface SandBoxHelper
      Parameters:
      linkedObjectType - the type of the entity in question
      requestedParent - the id to check
      Returns:
      the sandbox version, or null
    • getCascadedProductionStateId

      public Long getCascadedProductionStateId(Class<?> linkedObjectType, Long requestedParent)
      Description copied from interface: SandBoxHelper
      Find the production sandbox clone, if any, in the current site for the supplied type and primary key value. The assumption is that the primary key value supplied is from a parent catalog or profile. Since these are multitenant concepts, the response from this method should only be non-null when the multitenant module is loaded and active. When multitenant is used, changes can "cascade" through catalogs or profiles, finally ending at a standard site level.
      Specified by:
      getCascadedProductionStateId in interface SandBoxHelper
      Returns:
    • retrieveCascadedState

      public Long retrieveCascadedState(Class<?> ceilingImpl, Long requestedParent, jakarta.persistence.EntityManager em)
      Description copied from interface: SandBoxHelper
      Find the production version of an entity in the current catalog. The idVal supplied is presumably from a parent catalog from which the current catalog is derived. This is different than SandBoxHelper.getCascadedProductionStateId(Class, Long) in that the other is only targeting the production state existing as an override in a standard site. However, in contrast, this method will find the current production version in the current catalog related to a parent catalog version id, regardless if the current catalog belongs to a standard site or a template site.
      Specified by:
      retrieveCascadedState in interface SandBoxHelper
      Returns:
    • isRelatedToParentCatalogIds

      public boolean isRelatedToParentCatalogIds(Object entity, Long... candidateRelatedIds)
      Description copied from interface: SandBoxHelper
      Determine if the current entity is related via propagation inheritance to any of the candidate primary key values. If you have one of more parent catalog primary key values for the current entity type, then this is a convenient way to determine if the current entity directly inherits from one or more of them.
      Specified by:
      isRelatedToParentCatalogIds in interface SandBoxHelper
      Returns:
    • mergeCloneIds

      public List<Long> mergeCloneIds(Class<?> type, Long... originalIds)
      Description copied from interface: SandBoxHelper
      Retrieve a list of values that includes the the original ids passed in and any sandbox versions of those ids, if available. This is useful for some queries that require search values for both the original id and the sandbox id.
      Specified by:
      mergeCloneIds in interface SandBoxHelper
      Parameters:
      type - the type of the entity in question
      originalIds - one or more ids values for which sandbox versions should be included
      Returns:
      the merged id list
    • getSandBoxToOriginalMap

      public com.google.common.collect.BiMap<Long,Long> getSandBoxToOriginalMap(Class<?> type, Long... originalIds)
      Description copied from interface: SandBoxHelper
      Retrieve a map keyed by sandbox id, with the value being the matching original item id for that sandbox item. Only members from the ids list passed in that have a sandbox counterpart are included.
      Specified by:
      getSandBoxToOriginalMap in interface SandBoxHelper
      Parameters:
      type - the type of the entity in question
      originalIds - list of ids to check
      Returns:
      the map of sandbox to original ids
    • getTopmostProductionOriginalId

      public Long getTopmostProductionOriginalId(Class<?> type, Long id)
      Description copied from interface: SandBoxHelper

      Returns the topmost production id for the given type. The given id can exist anywhere in the hierarchy of production clones. The most hiearchies that can exist is this:

      • A TEMPLATE site owns catalog1 and catalog2
      • catalog2 is derived from catalog1 using SYNCED_COPY
      • catalog2 is assigned to a STANDARD site as CUSTOMIZABLE

      Production versions of entities can thus exist in 3 places: catalog1, catalog2, and the STANDARD site overrides. This supports IDs at all levels in the hierarchy, and will always return the production id from catalog1:

      • Production id from catalog1
      • Sandbox clone id from catalog1
      • Production id from catalog2
      • Sandbox clone id from catalog2
      • Production id from the standard site override
      • Sandbox clone from the standard site

      If no results are found for the given type and id (or the id is already the topmost production id) then id is returned.

      While the example given was for catalog hierarchies, this method also supports PROFILE hierarchies for CMS data

      Specified by:
      getTopmostProductionOriginalId in interface SandBoxHelper
      Parameters:
      type - the class name of the entity type to get the clone for
      id - a primary key anywhere in the hiearchy of overrides
      Returns:
      the topmost production id in a multitenant hierarchy
    • getOriginalId

      public SandBoxHelper.OriginalIdResponse getOriginalId(Class<?> type, Long id)
      Description copied from interface: SandBoxHelper
      Return the original id for the requested id. Will return the passed in id if the type is not sandboxable. Will return null if the passed in id is not a sandbox record, or if it's a sandbox add.
      Specified by:
      getOriginalId in interface SandBoxHelper
      Parameters:
      type - the type of the entity in question
      id - the id to check
      Returns:
      the original id for the requested sandbox id
    • getOriginalId

      public Long getOriginalId(Object test)
      Specified by:
      getOriginalId in interface SandBoxHelper
    • getProductionOriginalId

      public SandBoxHelper.OriginalIdResponse getProductionOriginalId(Class<?> type, Long id)
      Description copied from interface: SandBoxHelper
      Return the original id for the requested id as if this was a production request. The id passed in should be a production id. You will receive back the original id for this production id. The only time this makes sense is when the passed in id is for the production record from a standard site. This method is useful when you want the template record id for a standard site production id while in a sandbox context.
      Specified by:
      getProductionOriginalId in interface SandBoxHelper
      Returns:
    • isSandBoxable

      public boolean isSandBoxable(String className)
      Description copied from interface: SandBoxHelper
      Whether or not the class is sandboxable
      Specified by:
      isSandBoxable in interface SandBoxHelper
      Parameters:
      className - the classname to check
      Returns:
      whether or not it's sandboxable
    • isPromote

      public boolean isPromote()
      Description copied from interface: SandBoxHelper
      Is the current thread involved in a promote operation?
      Specified by:
      isPromote in interface SandBoxHelper
      Returns:
      whether or not a promote is currently taking place
    • isReject

      public boolean isReject()
      Description copied from interface: SandBoxHelper
      Is the current thread involved in a reject operation?
      Specified by:
      isReject in interface SandBoxHelper
      Returns:
      whether or not a reject is currently taking place
    • isReplayOperation

      public boolean isReplayOperation()
      Description copied from interface: SandBoxHelper
      Is the current thread involved in a replay operation (i.e. promote, revert, reject, approve and sync).
      Specified by:
      isReplayOperation in interface SandBoxHelper
      Returns:
      whether or not there is a replay operation in progress
    • optionallyIncludeDeletedItemsInQueriesAndCollections

      public void optionallyIncludeDeletedItemsInQueriesAndCollections(Runnable runnable, boolean includeDeleted)
      Description copied from interface: SandBoxHelper
      For the passed in code block (Runnable), whether or not sandbox entities marked as deleted should be included in any results from queries or lazy collection retrievals.
      Specified by:
      optionallyIncludeDeletedItemsInQueriesAndCollections in interface SandBoxHelper
      Parameters:
      runnable - the block of code for which this setting should be in effect
      includeDeleted - whether or not to include deleted sandbox items
    • getProductionRecordIdIfApplicable

      public Long getProductionRecordIdIfApplicable(jakarta.persistence.EntityManager em, Object startFieldValue)
      Specified by:
      getProductionRecordIdIfApplicable in interface SandBoxHelper
      Returns:
    • getTopMostOriginalRecord

      public <T> T getTopMostOriginalRecord(T record)
      Description copied from interface: SandBoxHelper
      If record is sandboxable, check to see if an original version of the passed in record exists. If so, return that original version. Otherwise, return null. The original record is the highest in the hierarchy, if applicable.
      Specified by:
      getTopMostOriginalRecord in interface SandBoxHelper
      Parameters:
      record - the entity instance to check
      Returns:
      the original record, or null if not exists
    • ignoreCloneCache

      public void ignoreCloneCache(boolean ignoreCache)
      Description copied from interface: SandBoxHelper
      Set when you want to override caching behavior related to finding sandbox versions. Generally, this only impacts retrieval of site level overrides in the multitenant edition. Setting this to true will cause sandbox version detection to go to the database rather than use the cache. This can be useful in situations where you may not trust the cache. This is an advanced option and is not normally used.
      Specified by:
      ignoreCloneCache in interface SandBoxHelper