Class ProductValidator

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

public class ProductValidator extends Object implements com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
Validations for Product.
Author:
Phillip Verheyden (phillipuniverse), Samarth Dhruva (samarthd)
  • Constructor Details

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

      @Autowired @Lazy public void setProductTypeValidators(List<ProductTypeValidator> productTypeValidators)
    • 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
    • validateForCreate

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

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

      protected void validateProductType(Product product, org.springframework.validation.Errors errors, Product existingProduct)
    • validateForReplace

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

      protected void validateProductFields(Product businessInstance, org.springframework.validation.Errors errors, javax.money.CurrencyUnit expectedCurrency, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Validates the product fields based on common constraints of different product types, such as Product.getName(), Product.getActiveStartDate(), etc. ProductType-specific constraint validations are done by the productTypeValidators, such as Product.getSku().
      Parameters:
      businessInstance - the product to be validated
      errors - the errors object bound to the product in which any validation errors should be registered
      expectedCurrency - expected currency based on the product and the current context
      contextInfo - the current context
    • validateActiveStartDate

      protected void validateActiveStartDate(Product businessInstance, org.springframework.validation.Errors errors)
    • validateActiveEndDate

      protected void validateActiveEndDate(Product businessInstance, org.springframework.validation.Errors errors)
    • validateThreshold

      protected void validateThreshold(Product businessInstance, org.springframework.validation.Errors errors)
    • validateName

      protected void validateName(org.springframework.validation.Errors errors)
    • validateSku

      protected void validateSku(org.springframework.validation.Errors errors)
    • validateDefaultPrice

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

      protected void validateSalePrice(Product businessInstance, javax.money.CurrencyUnit expectedCurrency, org.springframework.validation.Errors errors)
    • validateMsrp

      protected void validateMsrp(Product businessInstance, javax.money.CurrencyUnit expectedCurrency, org.springframework.validation.Errors errors)
    • validateCost

      protected void validateCost(Product businessInstance, javax.money.CurrencyUnit expectedCurrency, org.springframework.validation.Errors errors)
    • validateUrl

      protected void validateUrl(Product businessInstance, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    • validatePrimaryCategory

      protected void validatePrimaryCategory(Product businessInstance, org.springframework.validation.Errors errors, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • validateOptions

      protected void validateOptions(Product businessInstance, org.springframework.validation.Errors errors, javax.money.CurrencyUnit expectedCurrency, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    • validateNoDuplicateProductOptions

      protected void validateNoDuplicateProductOptions(Product businessInstance, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Validates that there are no ProductOptions that have the duplicated AttributeChoice.getAttributeName()
      Parameters:
      businessInstance - the Product instance to validate
      errors - the errors object
      context - the current context
    • getAllProductOptions

      protected List<ProductOption> getAllProductOptions(Product businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Gets a list of ProductOptions from the given Product.

      If the ProductOption.isAddedByReference() is true, then it's hydrated by ProductOption.getTemplateContextId()

      Parameters:
      businessInstance - the Product instance to gets all the ProductOptions from
      context - the current context
      Returns:
      a list of ProductOptions from the given Product.
    • validateIncludedProducts

      protected void validateIncludedProducts(Product businessInstance, org.springframework.validation.Errors errors, javax.money.CurrencyUnit expectedCurrency, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Validates that the product type of the owning product is DefaultProductType.BUNDLE if it has included products. Then validates each included product in.
      Parameters:
      businessInstance - the product to validate
      errors - holder for validation context information. When adding field validation errors, the field names should be in the context of the product
      expectedCurrency - expected currency based on the product and the current context
      contextInfo - the current context
    • validateIncludedProduct

      protected void validateIncludedProduct(IncludedProduct includedProduct, org.springframework.validation.Errors errors, javax.money.CurrencyUnit expectedCurrency, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Validates a specific IncludedProduct from Product.getIncludedProducts(). The errors object at this point should have the nested path set to the add-on that should be validated (for example, includedProduct[2] for the third includedProduct in the list).
      Parameters:
      includedProduct - the add-on to validate
      errors - the errors object in which to report errors, with its nested path already set for the given includedProduct
      contextInfo - context information surrounding sandboxing and multitenant state
    • validateType

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

      protected void validateProduct(IncludedProduct includedProduct, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Parameters:
      includedProduct - the includedProduct to validate
      errors - the errors object in which to report errors, with its nested path already set for the given includedProduct
      contextInfo - context information surrounding sandboxing and multitenant state
    • validateVariant

      protected void validateVariant(IncludedProduct includedProduct, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • validateOverridePrice

      protected void validateOverridePrice(IncludedProduct includedProduct, javax.money.CurrencyUnit expectedCurrency, org.springframework.validation.Errors errors)
    • validateQuantity

      protected void validateQuantity(IncludedProduct includedProduct, org.springframework.validation.Errors errors)
    • resolveCurrencyForValidation

      @NonNull protected javax.money.CurrencyUnit resolveCurrencyForValidation(Product product, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      First, we take what is on the product. If no currency was provided on the product, then we fall back to defaults.
      Parameters:
      product -
      contextInfo -
      Returns:
    • createTemporaryContextInfoWithCurrency

      protected com.broadleafcommerce.data.tracking.core.context.ContextInfo createTemporaryContextInfoWithCurrency(javax.money.CurrencyUnit currencyUnit, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • getExistingProduct

      protected Product getExistingProduct(Product product, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    • getProductOptionValidator

      @NonNull protected ProductOptionValidator getProductOptionValidator()
    • getProductService

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

      protected CategoryService<Category> getCategoryService()
    • getCategoryProductService

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

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

      protected OptionTemplateService<OptionTemplate> getOptionTemplateService()
    • setOptionTemplateService

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

      @NonNull protected List<ProductTypeValidator> getProductTypeValidators()