Class VariantValidator

java.lang.Object
com.broadleafcommerce.catalog.service.validation.VariantValidator
All Implemented Interfaces:
com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator

public class VariantValidator extends Object implements com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
Validations for Variant.
Author:
Samarth Dhruva (samarthd)
  • Constructor Details

    • VariantValidator

      public VariantValidator()
  • Method Details

    • setProductService

      @Autowired @Lazy public void setProductService(ProductService<Product> productService)
      Lazy injection since this validator is itself a service component. This avoids circular dependency exceptions
      Parameters:
      productService - the product service
    • supports

      public boolean supports(Class<?> serviceClass, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      supports in interface com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
    • validate

      public void validate(@NonNull Object businessInstance, @NonNull org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      validate in interface com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
    • validateThresholds

      protected void validateThresholds(Variant variant, Product referencedProduct, org.springframework.validation.Errors errors)
    • validateDefaultPrice

      protected void validateDefaultPrice(Variant variant, Product referencedProduct, javax.money.CurrencyUnit expectedCurrency, org.springframework.validation.Errors errors)
    • validateSalePrice

      protected void validateSalePrice(Variant variant, javax.money.CurrencyUnit expectedCurrency, org.springframework.validation.Errors errors)
    • validateCost

      protected void validateCost(Variant variant, javax.money.CurrencyUnit expectedCurrency, org.springframework.validation.Errors errors)
    • validateCurrency

      protected void validateCurrency(String field, javax.money.MonetaryAmount monetaryAmount, javax.money.CurrencyUnit expectedCurrency, org.springframework.validation.Errors errors)
    • validateActiveEndDate

      protected void validateActiveEndDate(Variant variant, org.springframework.validation.Errors errors)
    • validateProductId

      @Nullable protected Product validateProductId(Variant variant, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Validates that Variant.getProductId() is present and ensures the product exists in the data store.
      Parameters:
      variant - the variant being validated
      errors - the errors object bound to the variant in which any validation errors should be registered
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      the referenced product if it exists in the data store, null otherwise
    • validateProductType

      protected void validateProductType(@Nullable Product referencedProduct, @NonNull org.springframework.validation.Errors errors)
      Validates that the referenced product's product type is VARIANT_BASED as only VARIANT_BASED products can have variants.
      Parameters:
      referencedProduct - product that is referenced by the variant
      errors - the errors object bound to the variant in which any validation errors should be registered
    • validateSku

      protected void validateSku(@NonNull org.springframework.validation.Errors errors)
    • validateOptions

      protected void validateOptions(@NonNull Variant variant, @Nullable Product referencedProduct, @NonNull org.springframework.validation.Errors errors)
    • validateVariantOptionValues

      protected void validateVariantOptionValues(@NonNull Map<String,String> variantOptionValues, Product referencedProduct, org.springframework.validation.Errors errors)
    • getAllowedOptionValuesByAttrName

      protected Map<String,Set<String>> getAllowedOptionValuesByAttrName(Product referencedProduct)
    • allowedOptionValueMapper

      protected Function<? super AttributeChoice,Set<String>> allowedOptionValueMapper()
    • mergeOptionValues

      protected BinaryOperator<Set<String>> mergeOptionValues()
    • getOPTION_DOES_NOT_EXIST_MESSAGE

      protected static String getOPTION_DOES_NOT_EXIST_MESSAGE()
    • getOPTION_DOES_NOT_HAVE_VALUE_MESSAGE

      protected static String getOPTION_DOES_NOT_HAVE_VALUE_MESSAGE()
    • getProductService

      @NonNull protected ProductService<Product> getProductService()