Class ProductOptionValidator

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

public class ProductOptionValidator extends Object implements com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
Validations for ProductOption. Generally speaking, since ProductOption is not an independent entity, this validator should be called by the validators of entities who contain ProductOptions, such as OptionTemplateValidator and ProductValidator.
Author:
Samarth Dhruva (samarthd)
  • Constructor Details

    • ProductOptionValidator

      public ProductOptionValidator()
  • Method Details

    • setCategoryService

      @Autowired @Lazy public void setCategoryService(CategoryService<Category> categoryService)
      Lazy injection since this validator is itself a service component. This avoids circular dependency exceptions
      Parameters:
      categoryService - the category service
    • 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
    • setCategoryProductService

      @Autowired @Lazy public void setCategoryProductService(CategoryProductService<CategoryProduct> categoryProductService)
      Lazy injection since this validator is itself a service component. This avoids circular dependency exceptions
      Parameters:
      categoryProductService - the category product service
    • setVariantService

      @Autowired @Lazy public void setVariantService(VariantService<Variant> variantService)
      Lazy injection since this validator is itself a service component. This avoids circular dependency exceptions
      Parameters:
      variantService - the variant service
    • setOptionTemplateService

      @Autowired @Lazy public void setOptionTemplateService(OptionTemplateService<OptionTemplate> optionTemplateService)
      Lazy injection since this validator is itself a service component. This avoids circular dependency exceptions
      Parameters:
      optionTemplateService - the optionTemplate service
    • supports

      public boolean supports(Class<?> clazz, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      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
    • validateType

      protected void validateType(org.springframework.validation.Errors errors)
    • validateItemChoice

      protected void validateItemChoice(ProductOption option, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • validateReferenceOptionTemplate

      protected void validateReferenceOptionTemplate(ProductOption option, org.springframework.validation.Errors errors, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • findOptionTemplate

      protected Optional<OptionTemplate> findOptionTemplate(String templateContextId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Wrapper around OptionTemplateService.readById(String, ContextInfo) that catches EntityMissingException and returns an Optional.empty() if so.
      Parameters:
      templateContextId - the ID of the option template to find
      contextInfo - context information surrounding sandboxing and multitenant state
      Returns:
      an optional containing the category if found, Optional.empty() otherwise
    • validateAttributeChoice

      protected void validateAttributeChoice(ProductOption option, org.springframework.validation.Errors errors)
    • getCategoryService

      @NonNull protected CategoryService<Category> getCategoryService()
    • getProductService

      @NonNull protected ProductService<Product> getProductService()
    • getCategoryProductService

      @NonNull protected CategoryProductService<CategoryProduct> getCategoryProductService()
    • getVariantService

      @NonNull protected VariantService<Variant> getVariantService()
    • getOptionTemplateService

      protected OptionTemplateService<OptionTemplate> getOptionTemplateService()
    • getItemChoiceValidator

      @NonNull protected ProductOptionValidator.ItemChoiceValidator getItemChoiceValidator()
    • getAttributeChoiceValidator

      @NonNull protected ProductOptionValidator.AttributeChoiceValidator getAttributeChoiceValidator()