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 Summary
ConstructorDescriptionDefaultAttributeChoiceConfigurationService
(org.springframework.context.MessageSource messageSource, com.broadleafcommerce.common.extension.TypeFactory typeFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addAttributeConfigError
(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull String attributeName, @NonNull String errorCode, @NonNull String errorMessage) determineChosenValue
(@NonNull ProductOption option, @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, com.broadleafcommerce.cart.client.domain.Cart cart) Determine the chosen value on the cart item for the provided option.determineMatchedValue
(@NonNull AttributeChoice attributeChoice, String chosenValue) If there are anyAttributeChoice.getAllowedValues()
, make sure that the chosen value matches.protected String
getMessage
(@NonNull String errorMessage, Object... args) protected org.springframework.context.MessageSource
protected com.broadleafcommerce.common.extension.TypeFactory
protected void
performRegexValidation
(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull AttributeChoice attributeChoice, @NonNull String chosenValue) Perform regex validation fromAttributeChoice.getValidationRule()
against the cart.protected void
performValidationStrategy
(@NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull AttributeChoice attributeChoice, @NonNull String chosenValue) Perform theAttributeChoice.getValidationStrategy()
on the cartItem and the chosen value.protected boolean
shouldPerformValidation
(@NonNull String validationFlow, String validationStrategy) Whether to perform theAttributeChoice.getValidationStrategy()
for the item for the current flow.void
validateAttributeChoice
(com.broadleafcommerce.cart.client.domain.Cart cart, @NonNull com.broadleafcommerce.cart.client.domain.CartItem cartItem, @NonNull String validationFlow, @NonNull ProductOption option) Perform validation against the providedCartItem
for the given attribute choiceProductOption
.
-
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 providedCartItem
for the given attribute choiceProductOption
.- Specified by:
validateAttributeChoice
in interfaceAttributeChoiceConfigurationService
- Parameters:
cart
- TheCart
of theCartItem
cartItem
- TheCartItem
to performattribute choice
validation against.validationFlow
- The context used to identify validation requirements of theCartItem
at that point in its lifecycle.option
- TheProductOption
(and it'sProductOption.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 theAttributeChoice.getValidationStrategy()
for the item for the current flow.- Parameters:
validationFlow
- The context used to identify validation requirements of theCartItem
at that point in its lifecycle.validationStrategy
- TheValidationStrategy
- 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 theAttributeChoice.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 fromAttributeChoice.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 anyAttributeChoice.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
-
getMessage
-
getMessageSource
protected org.springframework.context.MessageSource getMessageSource() -
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-