Interface SandBoxHelper

All Known Implementing Classes:
DefaultSandBoxHelper

public interface SandBoxHelper
Utility class for working with sandboxable entities. The functionality provided by DefaultSandBoxHelper in core is generally innocuous, with more interesting sandbox related functionality being provided in the commercial enterprise module.
Author:
Jeff Fischer
See Also:
  • Method Details

    • mergeCloneIds

      List<Long> mergeCloneIds(Class<?> type, Long... originalIds)
      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.
      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
    • ignoreCloneCache

      void ignoreCloneCache(boolean ignoreCache)
      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.
      Parameters:
      ignoreCache -
    • getSandBoxToOriginalMap

      com.google.common.collect.BiMap<Long,Long> getSandBoxToOriginalMap(Class<?> type, Long... ids)
      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.
      Parameters:
      type - the type of the entity in question
      ids - list of ids to check
      Returns:
      the map of sandbox to original ids
    • getSandBoxVersionId

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

      Long getCascadedProductionStateId(Class<?> linkedObjectType, Long requestedParent)
      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.
      Parameters:
      linkedObjectType -
      requestedParent -
      Returns:
    • retrieveCascadedState

      Long retrieveCascadedState(Class<?> ceilingImpl, Long requestedParent, jakarta.persistence.EntityManager em)
      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 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.
      Parameters:
      ceilingImpl -
      requestedParent -
      em -
      Returns:
    • isRelatedToParentCatalogIds

      boolean isRelatedToParentCatalogIds(Object entity, Long... candidateRelatedIds)
      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.
      Parameters:
      entity -
      candidateRelatedIds -
      Returns:
    • getOriginalId

      SandBoxHelper.OriginalIdResponse getOriginalId(Class<?> type, Long id)
      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.
      Parameters:
      type - the type of the entity in question
      id - the id to check
      Returns:
      the original id for the requested sandbox id
    • getProductionOriginalId

      SandBoxHelper.OriginalIdResponse getProductionOriginalId(Class<?> type, Long id)
      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.
      Parameters:
      type -
      id -
      Returns:
    • getTopmostProductionOriginalId

      Long getTopmostProductionOriginalId(Class<?> type, Long id)

      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

      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

      Long getOriginalId(Object test)
    • isSandBoxable

      boolean isSandBoxable(String className)
      Whether or not the class is sandboxable
      Parameters:
      className - the classname to check
      Returns:
      whether or not it's sandboxable
    • isPromote

      boolean isPromote()
      Is the current thread involved in a promote operation?
      Returns:
      whether or not a promote is currently taking place
    • isReject

      boolean isReject()
      Is the current thread involved in a reject operation?
      Returns:
      whether or not a reject is currently taking place
    • isReplayOperation

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

      void optionallyIncludeDeletedItemsInQueriesAndCollections(Runnable runnable, boolean includeDeleted)
      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.
      Parameters:
      runnable - the block of code for which this setting should be in effect
      includeDeleted - whether or not to include deleted sandbox items
    • getProductionRecordIdIfApplicable

      Long getProductionRecordIdIfApplicable(jakarta.persistence.EntityManager em, Object startFieldValue)
      Parameters:
      em -
      startFieldValue -
      Returns:
    • getTopMostOriginalRecord

      <T> T getTopMostOriginalRecord(T record)
      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.
      Parameters:
      record - the entity instance to check
      Returns:
      the original record, or null if not exists