Class DefaultAttributeChoiceConfigurationService

java.lang.Object
com.broadleafcommerce.cartoperation.service.configuration.DefaultAttributeChoiceConfigurationService
All Implemented Interfaces:
AttributeChoiceConfigurationService

public class DefaultAttributeChoiceConfigurationService extends Object implements AttributeChoiceConfigurationService
Author:
Chad Harchar (charchar)
  • Constructor Details

    • DefaultAttributeChoiceConfigurationService

      public DefaultAttributeChoiceConfigurationService(org.springframework.context.MessageSource messageSource, com.broadleafcommerce.common.extension.TypeFactory typeFactory)
  • Method Details

    • validateAttributeChoice

      public void validateAttributeChoice(@Nullable com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull String validationFlow, @NonNull @NonNull ProductOption option)
      Description copied from interface: AttributeChoiceConfigurationService
      Perform validation against the provided CartItem for the given attribute choice ProductOption.
      Specified by:
      validateAttributeChoice in interface AttributeChoiceConfigurationService
      Parameters:
      cart - The Cart of the CartItem
      cartItem - The CartItem to perform attribute choice validation against.
      validationFlow - The context used to identify validation requirements of the CartItem at that point in its lifecycle.
      option - The ProductOption (and it's ProductOption.getAttributeChoice() we are using to validate the cart against.
    • determineChosenValue

      protected Optional<String> determineChosenValue(@NonNull @NonNull ProductOption option, @NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @Nullable com.broadleafcommerce.cart.client.domain.Cart cart)
      Determine the chosen value on the cart item for the provided option.
      Parameters:
      option - The option to check the chosen value for.
      cartItem - The cart item to check the chosen value on.
      cart - The cart with the cartItem
      Returns:
      The chosen value on the cart item for the provided option.
    • shouldPerformValidation

      protected boolean shouldPerformValidation(@NonNull @NonNull String validationFlow, @Nullable String validationStrategy)
      Whether to perform the AttributeChoice.getValidationStrategy() for the item for the current flow.
      Parameters:
      validationFlow - The context used to identify validation requirements of the CartItem at that point in its lifecycle.
      validationStrategy - The ValidationStrategy
      Returns:
      Whether to perform the AttributeChoice.getValidationStrategy() for the item for the current flow.
    • performValidationStrategy

      protected void performValidationStrategy(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull AttributeChoice attributeChoice, @NonNull @NonNull String chosenValue)
      Perform the AttributeChoice.getValidationStrategy() on the cartItem and the chosen value.
      Parameters:
      cartItem - The cart item to perform the validation strategy against.
      attributeChoice - The attribute choice to use to perform the validation strategy.
      chosenValue - The determined chosen value from the cart item for the attribute choice.
    • performRegexValidation

      protected void performRegexValidation(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull AttributeChoice attributeChoice, @NonNull @NonNull String chosenValue)
      Perform regex validation from AttributeChoice.getValidationRule() against the cart.
      Parameters:
      cartItem - The cart item to perform regex validation against.
      attributeChoice - The attribute choice to use to perform the validation strategy.
      chosenValue - The determined chosen value from the cart item for the attribute choice.
    • determineMatchedValue

      protected Optional<String> determineMatchedValue(@NonNull @NonNull AttributeChoice attributeChoice, @Nullable String chosenValue)
      If there are any AttributeChoice.getAllowedValues(), make sure that the chosen value matches. Otherwise, the chosen value is returned.
      Parameters:
      attributeChoice - The attribute choice to check allowed values against.
      chosenValue - The chosen value to check against allowed values.
      Returns:
      If there are any AttributeChoice.getAllowedValues(), make sure that the chosen value matches. Otherwise, the chosen value is returned.
    • addAttributeConfigError

      protected void addAttributeConfigError(@NonNull @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull @NonNull String attributeName, @NonNull @NonNull String errorCode, @NonNull @NonNull String errorMessage)
    • getMessage

      protected String getMessage(@NonNull @NonNull String errorMessage, @Nullable Object... args)
    • getMessageSource

      protected org.springframework.context.MessageSource getMessageSource()
    • getTypeFactory

      protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()