Class AbstractCartStatusChangeHandler
- All Implemented Interfaces:
CartStatusHandler
- Direct Known Subclasses:
AbstractAccountCartStatusHandler
,AbstractQuoteCartStatusHandler
-
Field Summary
-
Constructor Summary
ConstructorDescriptionAbstractCartStatusChangeHandler
(com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils authenticationUtils, com.broadleafcommerce.common.extension.TypeFactory typeFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addCartActionAuditUserInfo
(com.broadleafcommerce.cart.client.domain.CartActionAudit cartActionAudit, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hook point to populate fields related to user info in theCartActionAudit
.protected com.broadleafcommerce.cart.client.domain.CartActionAudit
buildCartActionAuditToCreate
(ChangeCartStatusRequest changeStatusRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Builds aCartActionAudit
based on the given fields.protected boolean
canBeReadByUser
(@NonNull CartStatusValidationRequest statusValidationRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines if the cart can be read by the currently authenticated user when the cart's current status isgetStatusToHandle()
.protected boolean
canBeTransitionedToByUser
(@NonNull ChangeCartStatusRequest changeStatusRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines if the cart can be transitioned togetStatusToHandle()
by the currently authenticated user.protected boolean
canBeUpdatedByUser
(@NonNull CartStatusValidationRequest statusValidationRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines if the cart can be updated by the currently authenticated user when the cart's current status isgetStatusToHandle()
.boolean
canHandle
(ChangeCartStatusRequest changeStatusRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines if this handler can handle the status change.protected com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils
protected String
getCartActionType
(ChangeCartStatusRequest changeCartStatusRequest) Hook point to determine the cart action type.protected com.broadleafcommerce.data.tracking.core.policy.trackable.TrackablePolicyUtils
protected abstract String
Gets the status to handle by this handlerprotected com.broadleafcommerce.common.extension.TypeFactory
getValidOriginatingStatuses
(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Gets a set of valid originating statuses that can transition to thegetStatusToHandle()
.protected boolean
isCartOwner
(@NonNull CartStatusValidationRequest statusValidationRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines if the givenCustomerRef
is the owner of the givenCart
.protected boolean
isCartOwner
(@NonNull ChangeCartStatusRequest changeStatusRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines if the givenCustomerRef
is the owner of the givenCart
.protected ChangeCartStatusRequest
postProcessStatusChange
(@NonNull ChangeCartStatusRequest changeStatusRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Perform any additional handling after theCart
has changed status.process
(@NonNull ChangeCartStatusRequest changeStatusRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Processes the cart status change if it is valid.protected ChangeCartStatusRequest
processStatusChange
(@NonNull ChangeCartStatusRequest changeStatusRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Perform the status change of theCart
.void
setPolicyUtils
(com.broadleafcommerce.data.tracking.core.policy.trackable.TrackablePolicyUtils policyUtils) protected void
validateOriginatingStatus
(@NonNull ChangeCartStatusRequest changeStatusRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Validates the originating status.void
validateStatusIsReadableByUser
(@NonNull CartStatusValidationRequest statusValidationRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines if the status is readable by the currently authenticated user.void
validateStatusIsUpdatableByUser
(@NonNull CartStatusValidationRequest statusValidationRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines if the status is updatable by the currently authenticated user.void
validateStatusTransition
(@NonNull ChangeCartStatusRequest changeStatusRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Validates that the status that theCart
is transitioning to is a valid next status.protected void
validateTransitionRules
(@NonNull ChangeCartStatusRequest changeStatusRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Evaluates the givenCart
and next status again any transition rules in place.
-
Field Details
-
USER_AUTHENTICATION_FAILED
- See Also:
-
INACCESSIBLE_CART_STATUS
- See Also:
-
-
Constructor Details
-
AbstractCartStatusChangeHandler
public AbstractCartStatusChangeHandler(com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils authenticationUtils, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
-
-
Method Details
-
getStatusToHandle
Gets the status to handle by this handler- Returns:
- the status to handle by this handler
-
getValidOriginatingStatuses
protected abstract Set<String> getValidOriginatingStatuses(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Gets a set of valid originating statuses that can transition to thegetStatusToHandle()
.The valid originating statuses may vary depending on the context and
certain quote configurations
.- Parameters:
contextInfo
- the contextInfo for the request- Returns:
- a set of valid originating statuses that can transition to the
getStatusToHandle()
-
canHandle
public boolean canHandle(ChangeCartStatusRequest changeStatusRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:CartStatusHandler
Determines if this handler can handle the status change.- Specified by:
canHandle
in interfaceCartStatusHandler
- Parameters:
changeStatusRequest
- theChangeCartStatusRequest
to facilitate the cart status changecontextInfo
- context information surrounding sandboxing and multitenant state- Returns:
- true if this handler can handle the status change, otherwise false
-
process
public ChangeCartStatusRequest process(@NonNull @NonNull ChangeCartStatusRequest changeStatusRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:CartStatusHandler
Processes the cart status change if it is valid.- Specified by:
process
in interfaceCartStatusHandler
- Parameters:
changeStatusRequest
- theChangeCartStatusRequest
to facilitate the cart status changecontextInfo
- context information surrounding sandboxing and multitenant state- Returns:
- the
ChangeCartStatusRequest
with the updatedCart
and other fields.
-
validateStatusTransition
public void validateStatusTransition(@NonNull @NonNull ChangeCartStatusRequest changeStatusRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:CartStatusHandler
Validates that the status that theCart
is transitioning to is a valid next status.- Specified by:
validateStatusTransition
in interfaceCartStatusHandler
- Parameters:
changeStatusRequest
- theChangeCartStatusRequest
to facilitate the cart status changecontextInfo
- context information surrounding sandboxing and multitenant state
-
validateStatusIsReadableByUser
public void validateStatusIsReadableByUser(@NonNull @NonNull CartStatusValidationRequest statusValidationRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:CartStatusHandler
Determines if the status is readable by the currently authenticated user.For example, a sales rep should not be able to read quotes in the
DefaultQuoteStatuses.DRAFTING
status.- Specified by:
validateStatusIsReadableByUser
in interfaceCartStatusHandler
- Parameters:
statusValidationRequest
- theCartStatusValidationRequest
to facilitate the cart status validationcontextInfo
- context information surrounding sandboxing and multitenant state
-
validateStatusIsUpdatableByUser
public void validateStatusIsUpdatableByUser(@NonNull @NonNull CartStatusValidationRequest statusValidationRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:CartStatusHandler
Determines if the status is updatable by the currently authenticated user.For example, a customer should not be able to update quotes in the
DefaultQuoteStatuses.ASSIGNED
status.- Specified by:
validateStatusIsUpdatableByUser
in interfaceCartStatusHandler
- Parameters:
statusValidationRequest
- theCartStatusValidationRequest
to facilitate the cart status validationcontextInfo
- context information surrounding sandboxing and multitenant state
-
isCartOwner
protected boolean isCartOwner(@NonNull @NonNull ChangeCartStatusRequest changeStatusRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines if the givenCustomerRef
is the owner of the givenCart
.- Parameters:
changeStatusRequest
- theChangeCartStatusRequest
to facilitate the cart status changecontextInfo
- context information surrounding sandboxing and multitenant state- Returns:
- true if the currently authenticated user is the owner of the
Cart
, otherwise false
-
isCartOwner
protected boolean isCartOwner(@NonNull @NonNull CartStatusValidationRequest statusValidationRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines if the givenCustomerRef
is the owner of the givenCart
.- Parameters:
statusValidationRequest
- theCartStatusValidationRequest
to facilitate the cart status validationcontextInfo
- context information surrounding sandboxing and multitenant state- Returns:
- true if the currently authenticated user is the owner of the
Cart
, otherwise false
-
canBeReadByUser
protected boolean canBeReadByUser(@NonNull @NonNull CartStatusValidationRequest statusValidationRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines if the cart can be read by the currently authenticated user when the cart's current status isgetStatusToHandle()
.This is helpful to restrict certain user types to read a cart in certain statuses.
For example, in a B2B quote context, a sales rep should not be able to read quotes in the
DefaultQuoteStatuses.DRAFTING
status, only the cart owner can.- Parameters:
statusValidationRequest
- theChangeCartStatusRequest
to facilitate the cart status changecontextInfo
- context information surrounding sandboxing and multitenant state- Returns:
- true if it is readable by the user, otherwise false
-
canBeUpdatedByUser
protected boolean canBeUpdatedByUser(@NonNull @NonNull CartStatusValidationRequest statusValidationRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines if the cart can be updated by the currently authenticated user when the cart's current status isgetStatusToHandle()
.This is helpful to restrict certain user types to update a cart in certain statuses.
For example, in a B2B quote context, only the cart owner should be able to update quotes in the
DefaultQuoteStatuses.DRAFTING
status.- Parameters:
statusValidationRequest
- theCartStatusValidationRequest
to facilitate the cart status validationcontextInfo
- context information surrounding sandboxing and multitenant state- Returns:
- true if it is updatable by the user, otherwise false
-
canBeTransitionedToByUser
protected boolean canBeTransitionedToByUser(@NonNull @NonNull ChangeCartStatusRequest changeStatusRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Determines if the cart can be transitioned togetStatusToHandle()
by the currently authenticated user.This is helpful to restrict certain user types to update a cart in certain statuses.
For example, in a B2B quote context, only the sales rep can transition a quote from
DefaultQuoteStatuses.ASSIGNED
toDefaultQuoteStatuses.PUBLISHED
.- Parameters:
changeStatusRequest
- theChangeCartStatusRequest
to facilitate the cart status changecontextInfo
- context information surrounding sandboxing and multitenant state- Returns:
- true if it can be transitioned to the status by the user, otherwise false
-
validateOriginatingStatus
protected void validateOriginatingStatus(@NonNull @NonNull ChangeCartStatusRequest changeStatusRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Validates the originating status.- Parameters:
changeStatusRequest
- theChangeCartStatusRequest
to facilitate the cart status changecontextInfo
- context information surrounding sandboxing and multitenant state- Throws:
InvalidCartStatusTransitionException
- if the originating status is invalid
-
validateTransitionRules
protected void validateTransitionRules(@NonNull @NonNull ChangeCartStatusRequest changeStatusRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Evaluates the givenCart
and next status again any transition rules in place.By default, this does nothing. This serves as a hook point to add custom transition rules.
- Parameters:
changeStatusRequest
- theChangeCartStatusRequest
to facilitate the cart status changecontextInfo
- context information surrounding sandboxing and multitenant state
-
processStatusChange
protected ChangeCartStatusRequest processStatusChange(@NonNull @NonNull ChangeCartStatusRequest changeStatusRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Perform the status change of theCart
.By default, this updates the status and creates a corresponding
CartActionAudit
. This serves as a hook point for additional steps for the status change.- Parameters:
changeStatusRequest
- theChangeCartStatusRequest
to facilitate the cart status changecontextInfo
- context information surrounding sandboxing and multitenant state- Returns:
- the
ChangeCartStatusRequest
with the updated cart
-
buildCartActionAuditToCreate
protected com.broadleafcommerce.cart.client.domain.CartActionAudit buildCartActionAuditToCreate(ChangeCartStatusRequest changeStatusRequest, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Builds aCartActionAudit
based on the given fields.- Parameters:
changeStatusRequest
- theChangeCartStatusRequest
to facilitate the audit hydrationcontextInfo
- context information surrounding sandboxing and multitenant state- Returns:
- the resulting cart action audit
-
getCartActionType
Hook point to determine the cart action type.Returns
DefaultQuoteActionTypes.UNKNOWN
by default unless overridden.- Parameters:
changeCartStatusRequest
- the change cart status request- Returns:
DefaultQuoteActionTypes.UNKNOWN
by default unless overridden.
-
addCartActionAuditUserInfo
protected void addCartActionAuditUserInfo(com.broadleafcommerce.cart.client.domain.CartActionAudit cartActionAudit, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hook point to populate fields related to user info in theCartActionAudit
.- Parameters:
cartActionAudit
- the cart action auditcontextInfo
- context information surrounding sandboxing and multitenant state
-
postProcessStatusChange
protected ChangeCartStatusRequest postProcessStatusChange(@NonNull @NonNull ChangeCartStatusRequest changeStatusRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Perform any additional handling after theCart
has changed status.By default, this does nothing. This serves as a hook point for customization.
- Parameters:
changeStatusRequest
- theChangeCartStatusRequest
to facilitate the cart status changecontextInfo
- context information surrounding sandboxing and multitenant state- Returns:
- the change status request after performing any additional handling.
-
getAuthenticationUtils
protected com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils getAuthenticationUtils() -
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
getPolicyUtils
@Nullable protected com.broadleafcommerce.data.tracking.core.policy.trackable.TrackablePolicyUtils getPolicyUtils() -
setPolicyUtils
@Autowired(required=false) public void setPolicyUtils(com.broadleafcommerce.data.tracking.core.policy.trackable.TrackablePolicyUtils policyUtils)
-