Class ContextInfo
- java.lang.Object
-
- com.broadleafcommerce.data.tracking.core.context.ContextInfo
-
- All Implemented Interfaces:
com.broadleafcommerce.common.extension.cache.temporal.TemporalIdentifier
public class ContextInfo extends Object implements com.broadleafcommerce.common.extension.cache.temporal.TemporalIdentifier
POJO representing context information regarding the current API request. This object is generally created in a@RestController
implementation before being passed as a parameter to an internal data service.- Author:
- Jeff Fischer
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ContextInfo.QueryHint
This is a generic hint concept that is used to influence persistence tier queries.static class
ContextInfo.QueryHints
Container object for one or moreContextInfo.QueryHint
instances.static interface
ContextInfo.QueryInfluencer
A dynamic component that theNarrowExecutor
will invoke to generate aNode
filter string that can be parsed and set as a predicate on the ultimate query it is processing.
-
Constructor Summary
Constructors Constructor Description ContextInfo()
ContextInfo(ContextInfo contextInfo)
Create a copy of an existing ContextInfo, including a copy of itsContextRequest
.ContextInfo(OperationType operationType)
ContextInfo(OperationType operationType, boolean ignoreNarrowing)
Convenience constructor to set the operationType and ignoreNarrowing indicatorContextInfo(OperationType operationType, ContextRequest request)
Convenience method for operationType and contextRequestContextInfo(OperationType operationType, ContextRequest request, String author)
Convenience method for operationType and contextRequest
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
canEqual(Object other)
boolean
equals(Object o)
Map<String,Object>
getAdditionalProperties()
This is a generic Map to support the ability for Broadleaf clients, specifically, to add additional (typically transient) properties during a particular request flow to support setting up and passing along additional state throughout a particular API invocation or web request.String
getAuthor()
Returns the user principal for this request.ContextIdOverwriteBehavior
getContextIdOverwriteBehavior()
Used forOperationType.CREATE
requests for entities to determine whetherCreateSetupDomainMapperMember
should autogenerate a context ID for the current request.ContextRequest
getContextRequest()
Specific sandbox and multitenant context information.Currency
getDefaultCurrency()
The defaultCurrency
for this request.String
getIpAddress()
The ip address of the remote callerLocale
getLocale()
TheLocale
for this context, primarily used for translation.OperationType
getOperationType()
The type of CRUD operation being requestedInstant
getPreviewDate()
The date in which to preview data.PreviewToken
getPreviewToken()
The preview token for use when previewing sandbox data.ContextInfo.QueryHints
getQueryHints()
List<ContextInfo.QueryInfluencer>
getQueryInfluencers()
This field is not serialized or deserialized asQueryInfluencers
are dynamic, functional components that execute logic rather than hold data.int
hashCode()
boolean
hasPreviewDate()
Return true if this request is using a preview date.boolean
isClearOverride()
Used forOperationType.DELETE
requests of entities marked asTrackableBehavior.CATALOG
to indicate whether the record for deletion is an override of a parent catalog that should be cleared instead of deleted.boolean
isFilterByActiveDates()
Whether or not entities that implementActiveAware
will be filtered by their active dates during fetch narrowing.boolean
isIgnoreDeleteFiltering()
Whether or not to ignore narrowing on deleted sandbox items.boolean
isIgnoreNarrowing()
Whether or not to turn off sandbox and multitenant narrowing behavior.boolean
isIgnoreTranslation()
Whether to ignore the process of translating fields while executingDomainMapperManager.fromRepositoryDomain(Object, Class, ContextInfo)
for a given request.boolean
isIncludePendingCatalogs()
Whether or not pending catalogs should be included in this context.Instant
nowOrPreviewDate()
Returns the time to be used for the current request.void
setAuthor(String author)
Intended to be the current Spring Security principal (the logged in user)void
setClearOverride(boolean clearOverride)
Used forOperationType.DELETE
requests of entities marked asTrackableBehavior.CATALOG
to indicate whether the record for deletion is an override of a parent catalog that should be cleared instead of deleted.void
setContextIdOverwriteBehavior(ContextIdOverwriteBehavior contextIdOverwriteBehavior)
Used forOperationType.CREATE
requests for entities to determine whetherCreateSetupDomainMapperMember
should autogenerate a context ID for the current request.void
setContextRequest(ContextRequest contextRequest)
Specific sandbox and multitenant context information.void
setDefaultCurrency(Currency defaultCurrency)
The defaultCurrency
for this request.void
setFilterByActiveDates(boolean filterByActiveDates)
void
setIgnoreDeleteFiltering(boolean ignoreDeleteFiltering)
Whether or not to ignore narrowing on deleted sandbox items.void
setIgnoreNarrowing(boolean ignoreNarrowing)
Whether or not to turn off sandbox and multitenant narrowing behavior.void
setIgnoreTranslation(boolean ignoreTranslation)
Whether to ignore the process of translating fields while executingDomainMapperManager.fromRepositoryDomain(Object, Class, ContextInfo)
for a given request.void
setIncludePendingCatalogs(boolean includePendingCatalogs)
Whether or not pending catalogs should be included in this context.void
setIpAddress(String ipAddress)
The ip address of the remote callervoid
setLocale(Locale locale)
TheLocale
for this context, primarily used for translation.void
setOperationType(OperationType operationType)
The type of CRUD operation being requestedvoid
setPendingCatalogs(boolean includePendingCatalogs)
void
setPreviewDate(Instant previewDate)
The date in which to preview data.void
setPreviewToken(PreviewToken previewToken)
The preview token for use when previewing sandbox data.void
setQueryHints(ContextInfo.QueryHints queryHints)
void
setQueryInfluencers(List<ContextInfo.QueryInfluencer> queryInfluencers)
This field is not serialized or deserialized asQueryInfluencers
are dynamic, functional components that execute logic rather than hold data.String
toString()
ContextInfo
withOperationType(ContextInfo info, OperationType type)
Creates a new ContextInfo and sets the operation type.
-
-
-
Constructor Detail
-
ContextInfo
public ContextInfo(@NonNull OperationType operationType)
-
ContextInfo
public ContextInfo(OperationType operationType, boolean ignoreNarrowing)
Convenience constructor to set the operationType and ignoreNarrowing indicator- Parameters:
operationType
-ignoreNarrowing
-
-
ContextInfo
public ContextInfo(@NonNull OperationType operationType, ContextRequest request)
Convenience method for operationType and contextRequest- Parameters:
operationType
-
-
ContextInfo
public ContextInfo(@NonNull OperationType operationType, ContextRequest request, String author)
Convenience method for operationType and contextRequest- Parameters:
operationType
-
-
ContextInfo
public ContextInfo(@NonNull ContextInfo contextInfo)
Create a copy of an existing ContextInfo, including a copy of itsContextRequest
.- Parameters:
contextInfo
- The ContextInfo to create the copy from.- See Also:
ContextRequest(ContextRequest)
-
ContextInfo
public ContextInfo()
-
-
Method Detail
-
setFilterByActiveDates
public void setFilterByActiveDates(boolean filterByActiveDates)
-
getAuthor
public String getAuthor()
Returns the user principal for this request.If a
previewToken
is present, and it matches the current context, this will returnPreviewToken.getAuthor()
instead. This is primarily engaged to allow anonymous requests from an application to preview a user's sandbox data.- Returns:
- the user principal for this request
-
nowOrPreviewDate
public Instant nowOrPreviewDate()
Returns the time to be used for the current request. Generally this returns the result ofInstant.now()
, except for when a validpreviewDate
is set, in which case the preview date will be used.- Specified by:
nowOrPreviewDate
in interfacecom.broadleafcommerce.common.extension.cache.temporal.TemporalIdentifier
- Returns:
- the current time or preview date
-
hasPreviewDate
public boolean hasPreviewDate()
Return true if this request is using a preview date. Caching implementations may be bypassed if this is true.- Returns:
- true if this context has a valid preview date
-
setPendingCatalogs
public void setPendingCatalogs(boolean includePendingCatalogs)
-
withOperationType
public ContextInfo withOperationType(ContextInfo info, OperationType type)
Creates a new ContextInfo and sets the operation type.- Parameters:
type
-- Returns:
-
getIpAddress
public String getIpAddress()
The ip address of the remote caller- Returns:
- The ip address
-
isIgnoreNarrowing
public boolean isIgnoreNarrowing()
Whether or not to turn off sandbox and multitenant narrowing behavior. Narrowing is applied as part of a read operations where additional discrimination is performed to retrieve the appropriate sandbox or catalog result for a given entity context id. In a write operation these discriminators are automatically applied to theTrackable
instance based on other information within theContextInfo
. SeeTrackableRepository
for more information.- Returns:
- Whether or not to turn off narrowing behavior
-
isIgnoreDeleteFiltering
public boolean isIgnoreDeleteFiltering()
Whether or not to ignore narrowing on deleted sandbox items. Deleted sandbox items are generally filtered out of results. However, it can occasionally be useful to include those items in results. Setting this flag to true on a fetch request will enable that behavior.- Returns:
- Whether or not to ignore narrowing on deleted sandbox items
-
isIncludePendingCatalogs
public boolean isIncludePendingCatalogs()
Whether or not pending catalogs should be included in this context. Generally, pending catalogs are only interesting to admin requests.- Returns:
- Whether or not pending catalogs should be included in this context
-
getLocale
public Locale getLocale()
TheLocale
for this context, primarily used for translation.- Returns:
- The
Locale
for this context, primarily used for translation
-
getDefaultCurrency
public Currency getDefaultCurrency()
The defaultCurrency
for this request. This is typically set by aContextInfoCustomizer
implementation. This may be null if not otherwise resolved.- Returns:
- The default currency
-
getAdditionalProperties
public Map<String,Object> getAdditionalProperties()
This is a generic Map to support the ability for Broadleaf clients, specifically, to add additional (typically transient) properties during a particular request flow to support setting up and passing along additional state throughout a particular API invocation or web request. Note that this should normally be used by Broadleaf clients and not internally by Broadleaf framework engineers.- Returns:
- A Map that can generically hold state
-
isIgnoreTranslation
public boolean isIgnoreTranslation()
Whether to ignore the process of translating fields while executingDomainMapperManager.fromRepositoryDomain(Object, Class, ContextInfo)
for a given request.- Returns:
- Whether to ignore the process of translating fields while executing
DomainMapperManager.fromRepositoryDomain(java.lang.Object, java.lang.Class<P>, com.broadleafcommerce.data.tracking.core.context.ContextInfo)
for a given request
-
isClearOverride
public boolean isClearOverride()
Used forOperationType.DELETE
requests of entities marked asTrackableBehavior.CATALOG
to indicate whether the record for deletion is an override of a parent catalog that should be cleared instead of deleted.- Returns:
- Whether the
TrackableBehavior.CATALOG
record forOperationType.DELETE
is an override that should be cleared.
-
getQueryHints
public ContextInfo.QueryHints getQueryHints()
-
getQueryInfluencers
public List<ContextInfo.QueryInfluencer> getQueryInfluencers()
This field is not serialized or deserialized asQueryInfluencers
are dynamic, functional components that execute logic rather than hold data. These are intended to be added and used by internal service logic for internal use rather than transferred between services.- See Also:
ContextInfo.QueryInfluencer
-
getContextIdOverwriteBehavior
public ContextIdOverwriteBehavior getContextIdOverwriteBehavior()
Used forOperationType.CREATE
requests for entities to determine whetherCreateSetupDomainMapperMember
should autogenerate a context ID for the current request. This allows for different behavior on a request-by-request basis to override the global system behavior defined inCreateSetupDomainMapperMember.isAutogenerateContextIdIfUnset()
andCreateSetupDomainMapperMember.isOverwriteExistingContextIdOnCreate()
.
-
getContextRequest
@NonNull public ContextRequest getContextRequest()
Specific sandbox and multitenant context information. This should never be null but all of the properties within it can be- Returns:
- Request context information
-
getPreviewToken
public PreviewToken getPreviewToken()
The preview token for use when previewing sandbox data. This token is used as proof of access to read sandbox data for a user within a certain context, usually anonymous.This token is expected to be validated to match the current request during policy validation and if it passes, will be used to inform the narrowing behavior for sandboxable entities.
- Returns:
- the decoded preview token object
- See Also:
for how this is resolves from a web request
-
getPreviewDate
public Instant getPreviewDate()
The date in which to preview data. This is utilized by services that opt-in to usenowOrPreviewDate()
for their date filtering.This will only be defined and applicable when a valid
previewToken
exists on the context.This will be ignored if it is ever found to be before
Instant.now()
, as this functionality is only intended to support previewing future states, and never past states.
-
isFilterByActiveDates
public boolean isFilterByActiveDates()
Whether or not entities that implementActiveAware
will be filtered by their active dates during fetch narrowing.- Specified by:
isFilterByActiveDates
in interfacecom.broadleafcommerce.common.extension.cache.temporal.TemporalIdentifier
-
setAuthor
public void setAuthor(String author)
Intended to be the current Spring Security principal (the logged in user)- Parameters:
author
- The logged in user
-
setIpAddress
public void setIpAddress(String ipAddress)
The ip address of the remote caller- Parameters:
ipAddress
- The ip address
-
setIgnoreNarrowing
public void setIgnoreNarrowing(boolean ignoreNarrowing)
Whether or not to turn off sandbox and multitenant narrowing behavior. Narrowing is applied as part of a read operations where additional discrimination is performed to retrieve the appropriate sandbox or catalog result for a given entity context id. In a write operation these discriminators are automatically applied to theTrackable
instance based on other information within theContextInfo
. SeeTrackableRepository
for more information.- Parameters:
ignoreNarrowing
- Whether or not to turn off narrowing behavior
-
setIgnoreDeleteFiltering
public void setIgnoreDeleteFiltering(boolean ignoreDeleteFiltering)
Whether or not to ignore narrowing on deleted sandbox items. Deleted sandbox items are generally filtered out of results. However, it can occasionally be useful to include those items in results. Setting this flag to true on a fetch request will enable that behavior.- Parameters:
ignoreDeleteFiltering
- Whether or not to ignore narrowing on deleted sandbox items
-
setIncludePendingCatalogs
public void setIncludePendingCatalogs(boolean includePendingCatalogs)
Whether or not pending catalogs should be included in this context. Generally, pending catalogs are only interesting to admin requests.- Parameters:
includePendingCatalogs
- Whether or not pending catalogs should be included in this context
-
setLocale
public void setLocale(Locale locale)
TheLocale
for this context, primarily used for translation.- Parameters:
locale
- TheLocale
for this context, primarily used for translation
-
setDefaultCurrency
public void setDefaultCurrency(Currency defaultCurrency)
The defaultCurrency
for this request. This is typically set by aContextInfoCustomizer
implementation. This may be null if not otherwise resolved.- Parameters:
The
- default currency
-
setIgnoreTranslation
public void setIgnoreTranslation(boolean ignoreTranslation)
Whether to ignore the process of translating fields while executingDomainMapperManager.fromRepositoryDomain(Object, Class, ContextInfo)
for a given request.- Parameters:
ignoreTranslation
- Whether to ignore the process of translating fields while executingDomainMapperManager.fromRepositoryDomain(java.lang.Object, java.lang.Class<P>, com.broadleafcommerce.data.tracking.core.context.ContextInfo)
for a given request
-
setClearOverride
public void setClearOverride(boolean clearOverride)
Used forOperationType.DELETE
requests of entities marked asTrackableBehavior.CATALOG
to indicate whether the record for deletion is an override of a parent catalog that should be cleared instead of deleted.- Parameters:
clearOverride
- Whether theTrackableBehavior.CATALOG
record forOperationType.DELETE
is an override that should be cleared.
-
setQueryHints
public void setQueryHints(ContextInfo.QueryHints queryHints)
-
setQueryInfluencers
public void setQueryInfluencers(List<ContextInfo.QueryInfluencer> queryInfluencers)
This field is not serialized or deserialized asQueryInfluencers
are dynamic, functional components that execute logic rather than hold data. These are intended to be added and used by internal service logic for internal use rather than transferred between services.- See Also:
ContextInfo.QueryInfluencer
-
setContextIdOverwriteBehavior
public void setContextIdOverwriteBehavior(ContextIdOverwriteBehavior contextIdOverwriteBehavior)
Used forOperationType.CREATE
requests for entities to determine whetherCreateSetupDomainMapperMember
should autogenerate a context ID for the current request. This allows for different behavior on a request-by-request basis to override the global system behavior defined inCreateSetupDomainMapperMember.isAutogenerateContextIdIfUnset()
andCreateSetupDomainMapperMember.isOverwriteExistingContextIdOnCreate()
.
-
setContextRequest
public void setContextRequest(@NonNull ContextRequest contextRequest)
Specific sandbox and multitenant context information. This should never be null but all of the properties within it can be- Parameters:
contextRequest
- Request context information
-
setPreviewToken
public void setPreviewToken(PreviewToken previewToken)
The preview token for use when previewing sandbox data. This token is used as proof of access to read sandbox data for a user within a certain context, usually anonymous.This token is expected to be validated to match the current request during policy validation and if it passes, will be used to inform the narrowing behavior for sandboxable entities.
- Parameters:
previewToken
- the decoded preview token object- See Also:
for how this is resolves from a web request
-
setPreviewDate
public void setPreviewDate(Instant previewDate)
The date in which to preview data. This is utilized by services that opt-in to usenowOrPreviewDate()
for their date filtering.This will only be defined and applicable when a valid
previewToken
exists on the context.This will be ignored if it is ever found to be before
Instant.now()
, as this functionality is only intended to support previewing future states, and never past states.
-
canEqual
protected boolean canEqual(Object other)
-
getOperationType
@NonNull public OperationType getOperationType()
The type of CRUD operation being requested- Returns:
- The type of CRUD operation
-
setOperationType
@NonNull public void setOperationType(OperationType operationType)
The type of CRUD operation being requested- Parameters:
operationType
- The type of CRUD operation
-
-