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
    • hydrateOptionTemplates

      protected void hydrateOptionTemplates(@NonNull @NonNull Product product, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Hydrate any product options that were added by reference from option templates to ensure that validation takes all the necessary info into account.
      Parameters:
      product - The parent product of the variant being validated
      contextInfo - Additional tenant and sandbox info
    • 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

      @Deprecated(since="1.9.0", forRemoval=true) protected void validateVariantOptionValues(@NonNull Map<String,String> variantOptionValues, Product referencedProduct, org.springframework.validation.Errors errors)
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 1.9.0, allowed values are no longer validated
    • 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()
    • getOptionTemplateService

      protected OptionTemplateService<OptionTemplate> getOptionTemplateService()
    • setOptionTemplateService

      @Autowired @Lazy public void setOptionTemplateService(OptionTemplateService<OptionTemplate> optionTemplateService)