Class AbstractCartStatusChangeHandler

java.lang.Object
com.broadleafcommerce.cartoperation.service.status.AbstractCartStatusChangeHandler
All Implemented Interfaces:
CartStatusHandler
Direct Known Subclasses:
AbstractAccountCartStatusHandler, AbstractQuoteCartStatusHandler

public abstract class AbstractCartStatusChangeHandler extends Object implements CartStatusHandler
  • Field Details

  • Constructor Details

    • AbstractCartStatusChangeHandler

      public AbstractCartStatusChangeHandler(com.broadleafcommerce.resource.security.utils.service.AuthenticationUtils authenticationUtils, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
  • Method Details

    • getStatusToHandle

      protected abstract String 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 the getStatusToHandle().

      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 interface CartStatusHandler
      Parameters:
      changeStatusRequest - the ChangeCartStatusRequest to facilitate the cart status change
      contextInfo - 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 interface CartStatusHandler
      Parameters:
      changeStatusRequest - the ChangeCartStatusRequest to facilitate the cart status change
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      the ChangeCartStatusRequest with the updated Cart 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 the Cart is transitioning to is a valid next status.
      Specified by:
      validateStatusTransition in interface CartStatusHandler
      Parameters:
      changeStatusRequest - the ChangeCartStatusRequest to facilitate the cart status change
      contextInfo - 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 interface CartStatusHandler
      Parameters:
      statusValidationRequest - the CartStatusValidationRequest to facilitate the cart status validation
      contextInfo - 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 interface CartStatusHandler
      Parameters:
      statusValidationRequest - the CartStatusValidationRequest to facilitate the cart status validation
      contextInfo - 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 given CustomerRef is the owner of the given Cart.
      Parameters:
      changeStatusRequest - the ChangeCartStatusRequest to facilitate the cart status change
      contextInfo - 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 given CustomerRef is the owner of the given Cart.
      Parameters:
      statusValidationRequest - the CartStatusValidationRequest to facilitate the cart status validation
      contextInfo - 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 is getStatusToHandle().

      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 - the ChangeCartStatusRequest to facilitate the cart status change
      contextInfo - 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 is getStatusToHandle().

      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 - the CartStatusValidationRequest to facilitate the cart status validation
      contextInfo - 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 to getStatusToHandle() 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 to DefaultQuoteStatuses.PUBLISHED.

      Parameters:
      changeStatusRequest - the ChangeCartStatusRequest to facilitate the cart status change
      contextInfo - 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 - the ChangeCartStatusRequest to facilitate the cart status change
      contextInfo - 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 given Cart 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 - the ChangeCartStatusRequest to facilitate the cart status change
      contextInfo - 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 the Cart.

      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 - the ChangeCartStatusRequest to facilitate the cart status change
      contextInfo - 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 a CartActionAudit based on the given fields.
      Parameters:
      changeStatusRequest - the ChangeCartStatusRequest to facilitate the audit hydration
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      the resulting cart action audit
    • getCartActionType

      protected String getCartActionType(ChangeCartStatusRequest changeCartStatusRequest)
      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 the CartActionAudit.
      Parameters:
      cartActionAudit - the cart action audit
      contextInfo - 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 the Cart has changed status.

      By default, this does nothing. This serves as a hook point for customization.

      Parameters:
      changeStatusRequest - the ChangeCartStatusRequest to facilitate the cart status change
      contextInfo - 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)