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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected com.broadleafcommerce.data.tracking.core.context.ContextInfo
createTemporaryContextInfoWithCurrency
(javax.money.CurrencyUnit currencyUnit, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected CategoryProductService<CategoryProduct>
protected CategoryService<Category>
protected Product
getExistingProduct
(Product product, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected ProductOptionValidator
protected ProductService<Product>
protected List<ProductTypeValidator>
protected VariantService<Variant>
protected javax.money.CurrencyUnit
resolveCurrencyForValidation
(Product product, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) First, we take what is on the product.void
setCategoryProductService
(CategoryProductService<CategoryProduct> categoryProductService) Lazy injection since this validator is itself a service component.void
setCategoryService
(CategoryService<Category> categoryService) Lazy injection since this validator is itself a service component.void
setProductService
(ProductService<Product> productService) Lazy injection since this validator is itself a service component.void
setProductTypeValidators
(List<ProductTypeValidator> productTypeValidators) void
setVariantService
(VariantService<Variant> variantService) Lazy injection since this validator is itself a service component.boolean
void
validate
(Object businessInstance, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected void
validateActiveEndDate
(Product businessInstance, org.springframework.validation.Errors errors) protected void
validateActiveStartDate
(Product businessInstance, org.springframework.validation.Errors errors) protected void
validateCost
(Product businessInstance, javax.money.CurrencyUnit expectedCurrency, org.springframework.validation.Errors errors) protected void
validateDefaultPrice
(Product businessInstance, javax.money.CurrencyUnit expectedCurrency, org.springframework.validation.Errors errors) void
validateForCreate
(Object businessInstance, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) void
validateForReplace
(Object businessInstance, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) void
validateForUpdate
(Object businessInstance, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected void
validateIncludedProduct
(IncludedProduct includedProduct, org.springframework.validation.Errors errors, javax.money.CurrencyUnit expectedCurrency, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Validates a specificIncludedProduct
fromProduct.getIncludedProducts()
.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 isDefaultProductType.BUNDLE
if it has included products.protected void
validateMsrp
(Product businessInstance, javax.money.CurrencyUnit expectedCurrency, org.springframework.validation.Errors errors) protected void
validateName
(org.springframework.validation.Errors errors) protected void
validateOptions
(Product businessInstance, org.springframework.validation.Errors errors, javax.money.CurrencyUnit expectedCurrency, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected void
validateOverridePrice
(IncludedProduct includedProduct, javax.money.CurrencyUnit expectedCurrency, org.springframework.validation.Errors errors) protected void
validatePrimaryCategory
(Product businessInstance, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected void
validateProduct
(IncludedProduct includedProduct, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Validates thatIncludedProduct.getProduct()
exists.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 differentproduct types
, such asProduct.getName()
,Product.getActiveStartDate()
, etc.protected void
validateProductType
(Product product, org.springframework.validation.Errors errors, Product existingProduct) protected void
validateQuantity
(IncludedProduct includedProduct, org.springframework.validation.Errors errors) protected void
validateSalePrice
(Product businessInstance, javax.money.CurrencyUnit expectedCurrency, org.springframework.validation.Errors errors) protected void
validateSku
(org.springframework.validation.Errors errors) protected void
validateThreshold
(Product businessInstance, org.springframework.validation.Errors errors) protected void
validateType
(org.springframework.validation.Errors errors) protected void
validateUrl
(Product businessInstance, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected void
validateVariant
(IncludedProduct includedProduct, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
-
Constructor Details
-
ProductValidator
-
-
Method Details
-
setProductService
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
Lazy injection since this validator is itself a service component. This avoids circular dependency exceptions- Parameters:
variantService
- the variant service
-
setCategoryService
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 interfacecom.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 interfacecom.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 interfacecom.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 interfacecom.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
-
validateProductType
-
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 interfacecom.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 differentproduct types
, such asProduct.getName()
,Product.getActiveStartDate()
, etc. ProductType-specific constraint validations are done by theproductTypeValidators
, such asProduct.getSku()
.- Parameters:
businessInstance
- the product to be validatederrors
- the errors object bound to the product in which any validation errors should be registeredexpectedCurrency
- expected currency based on the product and the current contextcontextInfo
- 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) -
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 isDefaultProductType.BUNDLE
if it has included products. Then validates each included product in.- Parameters:
businessInstance
- the product to validateerrors
- holder for validation context information. When adding field validation errors, the field names should be in the context of the productexpectedCurrency
- expected currency based on the product and the current contextcontextInfo
- 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 specificIncludedProduct
fromProduct.getIncludedProducts()
. Theerrors
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 validateerrors
- the errors object in which to report errors, with its nested path already set for the givenincludedProduct
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) Validates thatIncludedProduct.getProduct()
exists. Also validates that the product type ofIncludedProduct.getProduct()
isDefaultProductType.STANDARD
orDefaultProductType.VARIANT_BASED
.- Parameters:
includedProduct
- the includedProduct to validateerrors
- the errors object in which to report errors, with its nested path already set for the givenincludedProduct
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
-
getProductOptionValidator
-
getProductService
-
getCategoryService
-
getCategoryProductService
-
getVariantService
-
getProductTypeValidators
-