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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected com.broadleafcommerce.data.tracking.core.context.ContextInfocreateTemporaryContextInfoWithCurrency(javax.money.CurrencyUnit currencyUnit, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected CategoryProductService<CategoryProduct>protected CategoryService<Category>protected ProductgetExistingProduct(Product product, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected ProductOptionValidatorprotected ProductService<Product>protected List<ProductTypeValidator>protected VariantService<Variant>protected javax.money.CurrencyUnitresolveCurrencyForValidation(Product product, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) First, we take what is on the product.voidsetCategoryProductService(CategoryProductService<CategoryProduct> categoryProductService) Lazy injection since this validator is itself a service component.voidsetCategoryService(CategoryService<Category> categoryService) Lazy injection since this validator is itself a service component.voidsetProductService(ProductService<Product> productService) Lazy injection since this validator is itself a service component.voidsetProductTypeValidators(List<ProductTypeValidator> productTypeValidators) voidsetVariantService(VariantService<Variant> variantService) Lazy injection since this validator is itself a service component.booleanvoidvalidate(Object businessInstance, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected voidvalidateActiveEndDate(Product businessInstance, org.springframework.validation.Errors errors) protected voidvalidateActiveStartDate(Product businessInstance, org.springframework.validation.Errors errors) protected voidvalidateCost(Product businessInstance, javax.money.CurrencyUnit expectedCurrency, org.springframework.validation.Errors errors) protected voidvalidateDefaultPrice(Product businessInstance, javax.money.CurrencyUnit expectedCurrency, org.springframework.validation.Errors errors) voidvalidateForCreate(Object businessInstance, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) voidvalidateForReplace(Object businessInstance, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) voidvalidateForUpdate(Object businessInstance, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected voidvalidateIncludedProduct(IncludedProduct includedProduct, org.springframework.validation.Errors errors, javax.money.CurrencyUnit expectedCurrency, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Validates a specificIncludedProductfromProduct.getIncludedProducts().protected voidvalidateIncludedProducts(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.BUNDLEif it has included products.protected voidvalidateMsrp(Product businessInstance, javax.money.CurrencyUnit expectedCurrency, org.springframework.validation.Errors errors) protected voidvalidateName(org.springframework.validation.Errors errors) protected voidvalidateOptions(Product businessInstance, org.springframework.validation.Errors errors, javax.money.CurrencyUnit expectedCurrency, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected voidvalidateOverridePrice(IncludedProduct includedProduct, javax.money.CurrencyUnit expectedCurrency, org.springframework.validation.Errors errors) protected voidvalidatePrimaryCategory(Product businessInstance, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected voidvalidateProduct(IncludedProduct includedProduct, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Validates thatIncludedProduct.getProduct()exists.protected voidvalidateProductFields(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 voidvalidateProductType(Product product, org.springframework.validation.Errors errors, Product existingProduct) protected voidvalidateQuantity(IncludedProduct includedProduct, org.springframework.validation.Errors errors) protected voidvalidateSalePrice(Product businessInstance, javax.money.CurrencyUnit expectedCurrency, org.springframework.validation.Errors errors) protected voidvalidateSku(org.springframework.validation.Errors errors) protected voidvalidateThreshold(Product businessInstance, org.springframework.validation.Errors errors) protected voidvalidateType(org.springframework.validation.Errors errors) protected voidvalidateUrl(Product businessInstance, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected voidvalidateVariant(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:
supportsin 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:
validatein 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:
validateForCreatein 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:
validateForUpdatein 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:
validateForReplacein 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.BUNDLEif 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 specificIncludedProductfromProduct.getIncludedProducts(). Theerrorsobject 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 givenincludedProductcontextInfo- 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.STANDARDorDefaultProductType.VARIANT_BASED.- Parameters:
includedProduct- the includedProduct to validateerrors- the errors object in which to report errors, with its nested path already set for the givenincludedProductcontextInfo- 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
-