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:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.broadleafcommerce.common.sandbox.SandBoxHelper
SandBoxHelper.OriginalIdResponse
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetCascadedProductionStateId
(Class<?> linkedObjectType, Long requestedParent) Find the production sandbox clone, if any, in the current site for the supplied type and primary key value.getOriginalId
(Class<?> type, Long id) Return the original id for the requested id.getOriginalId
(Object test) getProductionOriginalId
(Class<?> type, Long id) Return the original id for the requested id as if this was a production request.getProductionRecordIdIfApplicable
(jakarta.persistence.EntityManager em, Object startFieldValue) getSandBoxToOriginalMap
(Class<?> type, Long... originalIds) Retrieve a map keyed by sandbox id, with the value being the matching original item id for that sandbox item.getSandBoxVersionId
(Class<?> linkedObjectType, Long requestedParent) Return the sandbox version id for the requested original id.<T> T
getTopMostOriginalRecord
(T record) If record is sandboxable, check to see if an original version of the passed in record exists.getTopmostProductionOriginalId
(Class<?> type, Long id) Returns the topmost production id for the given type.void
ignoreCloneCache
(boolean ignoreCache) Set when you want to override caching behavior related to finding sandbox versions.boolean
Is the current thread involved in a promote operation?boolean
isReject()
Is the current thread involved in a reject operation?boolean
isRelatedToParentCatalogIds
(Object entity, Long... candidateRelatedIds) Determine if the current entity is related via propagation inheritance to any of the candidate primary key values.boolean
Is the current thread involved in a replay operation (i.e. promote, revert, reject, approve and sync).boolean
isSandBoxable
(String className) Whether or not the class is sandboxablemergeCloneIds
(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.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.retrieveCascadedState
(Class<?> ceilingImpl, Long requestedParent, jakarta.persistence.EntityManager em) Find the production version of an entity in the current catalog.
-
Constructor Details
-
DefaultSandBoxHelper
public DefaultSandBoxHelper()
-
-
Method Details
-
getSandBoxVersionId
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 interfaceSandBoxHelper
- Parameters:
linkedObjectType
- the type of the entity in questionrequestedParent
- the id to check- Returns:
- the sandbox version, or null
-
getCascadedProductionStateId
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 interfaceSandBoxHelper
- 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 thanSandBoxHelper.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 interfaceSandBoxHelper
- Returns:
-
isRelatedToParentCatalogIds
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 interfaceSandBoxHelper
- Returns:
-
mergeCloneIds
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 interfaceSandBoxHelper
- Parameters:
type
- the type of the entity in questionoriginalIds
- 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 interfaceSandBoxHelper
- Parameters:
type
- the type of the entity in questionoriginalIds
- list of ids to check- Returns:
- the map of sandbox to original ids
-
getTopmostProductionOriginalId
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 interfaceSandBoxHelper
- Parameters:
type
- the class name of the entity type to get the clone forid
- a primary key anywhere in the hiearchy of overrides- Returns:
- the topmost production id in a multitenant hierarchy
-
getOriginalId
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 interfaceSandBoxHelper
- Parameters:
type
- the type of the entity in questionid
- the id to check- Returns:
- the original id for the requested sandbox id
-
getOriginalId
- Specified by:
getOriginalId
in interfaceSandBoxHelper
-
getProductionOriginalId
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 interfaceSandBoxHelper
- Returns:
-
isSandBoxable
Description copied from interface:SandBoxHelper
Whether or not the class is sandboxable- Specified by:
isSandBoxable
in interfaceSandBoxHelper
- 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 interfaceSandBoxHelper
- 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 interfaceSandBoxHelper
- 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 interfaceSandBoxHelper
- 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 interfaceSandBoxHelper
- Parameters:
runnable
- the block of code for which this setting should be in effectincludeDeleted
- whether or not to include deleted sandbox items
-
getProductionRecordIdIfApplicable
public Long getProductionRecordIdIfApplicable(jakarta.persistence.EntityManager em, Object startFieldValue) - Specified by:
getProductionRecordIdIfApplicable
in interfaceSandBoxHelper
- 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 interfaceSandBoxHelper
- 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 interfaceSandBoxHelper
-