Class DefaultVariantBasedProductTypeValidator
java.lang.Object
com.broadleafcommerce.catalog.service.validation.product.type.DefaultVariantBasedProductTypeValidator
- All Implemented Interfaces:
ProductTypeValidator
The default validator that is used to validate products whose
types
are DefaultProductType.VARIANT_BASED
.- Author:
- Sunny Yu
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
canValidateCreate
(Product product) Whether or not this validator supports validation to create this product.boolean
canValidateReplace
(Product product, Product existingProduct) Whether or not this validator supports validation to replace this product.boolean
canValidateUpdate
(Product product, Product existingProduct) Whether or not this validator supports validation to update this product.getDiffBetweenStringSets
(Set<String> existingProductAttributes, Set<String> updatedProductAttributes) Compares the set of existing-values and updated-values and returns only the changes in updated-values.getOptionNamesAndValues
(List<? extends ProductOption> productOptions) Creates a Pair of string-sets which contain the options and optionValues for the given list of productOptions.getUsedVariantOptionValuesByNameMap
(List<Variant> variantList) Creates a map containing all the optionNames (as keys) and a set of optionValues (as values) that are currently being used by all the variants of a product.protected VariantService<Variant>
void
setVariantService
(VariantService<Variant> variantService) Lazy injection since this validator is itself a service component.protected void
validateIncludedProducts
(Product businessInstance, org.springframework.validation.Errors errors) protected void
validateOptionsAndOptionValuesUsageInVariants
(Product product, Product existingProduct, List<Variant> variantList, org.springframework.validation.Errors errors) Validates if aProductOption
or itsAttributeChoiceValue
is used in any of the variants of the current productvoid
validateProductForCreate
(Product product, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Validate the product for create.void
validateProductForReplace
(Product product, org.springframework.validation.Errors errors, Product existingProduct, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Validate the product for replace.void
validateProductForUpdate
(Product product, org.springframework.validation.Errors errors, Product existingProduct, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Validate the product for update.protected void
validateVariant
(Variant variant, Product product, org.springframework.validation.Errors errors) protected void
validateVariants
(Product businessInstance, List<? extends Variant> variantsList, org.springframework.validation.Errors errors) Validates the variants and adds errors to the errors object if any.protected void
validateVariants
(Product businessInstance, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Deprecated.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.broadleafcommerce.catalog.service.validation.product.type.ProductTypeValidator
validateDefaultPrice
-
Constructor Details
-
DefaultVariantBasedProductTypeValidator
public DefaultVariantBasedProductTypeValidator()
-
-
Method Details
-
setVariantService
Lazy injection since this validator is itself a service component. This avoids circular dependency exceptions- Parameters:
variantService
- the variant service
-
canValidateCreate
Description copied from interface:ProductTypeValidator
Whether or not this validator supports validation to create this product.- Specified by:
canValidateCreate
in interfaceProductTypeValidator
- Parameters:
product
- the product to validate- Returns:
- true if this validator can validate the product creation
-
canValidateUpdate
Description copied from interface:ProductTypeValidator
Whether or not this validator supports validation to update this product.- Specified by:
canValidateUpdate
in interfaceProductTypeValidator
- Parameters:
product
- the product to validate- Returns:
- true if this validator can validate the product update
-
canValidateReplace
Description copied from interface:ProductTypeValidator
Whether or not this validator supports validation to replace this product.- Specified by:
canValidateReplace
in interfaceProductTypeValidator
- Parameters:
product
- the product to validate- Returns:
- true if this validator can validate the product replace
-
validateProductForCreate
public void validateProductForCreate(Product product, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:ProductTypeValidator
Validate the product for create.- Specified by:
validateProductForCreate
in interfaceProductTypeValidator
- Parameters:
product
- the product to validateerrors
- holder for validation context information. When adding field validation errors, the field names should be in the context of the productcontext
- current context this validation is running in
-
validateProductForUpdate
public void validateProductForUpdate(Product product, org.springframework.validation.Errors errors, Product existingProduct, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:ProductTypeValidator
Validate the product for update.- Specified by:
validateProductForUpdate
in interfaceProductTypeValidator
- Parameters:
product
- the product to validateerrors
- holder for validation context information. When adding field validation errors, the field names should be in the context of the productexistingProduct
- the current product in the databasecontext
- current context this validation is running in
-
validateProductForReplace
public void validateProductForReplace(Product product, org.springframework.validation.Errors errors, Product existingProduct, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:ProductTypeValidator
Validate the product for replace.- Specified by:
validateProductForReplace
in interfaceProductTypeValidator
- Parameters:
product
- the product to validateerrors
- holder for validation context information. When adding field validation errors, the field names should be in the context of the productexistingProduct
- the current product in the databasecontext
- current context this validation is running in
-
validateOptionsAndOptionValuesUsageInVariants
protected void validateOptionsAndOptionValuesUsageInVariants(@NonNull Product product, @NonNull Product existingProduct, List<Variant> variantList, org.springframework.validation.Errors errors) Validates if aProductOption
or itsAttributeChoiceValue
is used in any of the variants of the current product- Parameters:
product
- the updated product with new changesexistingProduct
- the existing product persisted in the dbvariantList
- a list containing all the variants of the product (also the existingProduct)errors
- the errors object
-
getOptionNamesAndValues
protected org.springframework.data.util.Pair<Set<String>,Set<String>> getOptionNamesAndValues(List<? extends ProductOption> productOptions) Creates a Pair of string-sets which contain the options and optionValues for the given list of productOptions.- Parameters:
productOptions
- the list ofProductOption
- Returns:
- a
Pair
ofSet<String>
with all the applicable options and optionValues
-
getDiffBetweenStringSets
protected Set<String> getDiffBetweenStringSets(Set<String> existingProductAttributes, Set<String> updatedProductAttributes) Compares the set of existing-values and updated-values and returns only the changes in updated-values.- Parameters:
existingProductAttributes
- the existing-values against which to compareupdatedProductAttributes
- the updated-values in which changes are to be detected against the existing-values- Returns:
- A
Set
containing the difference between the two sets
-
getUsedVariantOptionValuesByNameMap
Creates a map containing all the optionNames (as keys) and a set of optionValues (as values) that are currently being used by all the variants of a product.- Parameters:
variantList
- the list of all the variants of a product- Returns:
- A Map containing all the in-use optionNames and optionValues
-
validateVariants
@Deprecated(since="2.2.0, 2.1.1, 2.0.2, 1.8.15") protected void validateVariants(Product businessInstance, org.springframework.validation.Errors errors, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Deprecated.UsevalidateVariants(Product, List, Errors)
instead- Parameters:
businessInstance
- the product businessInstanceerrors
- the errors objectcontext
- the contextInfo object
-
validateVariants
protected void validateVariants(Product businessInstance, List<? extends Variant> variantsList, org.springframework.validation.Errors errors) Validates the variants and adds errors to the errors object if any.- Parameters:
businessInstance
- the product businessInstancevariantsList
- the list of variants for the current producterrors
- the errors object
-
validateVariant
-
validateIncludedProducts
protected void validateIncludedProducts(Product businessInstance, org.springframework.validation.Errors errors) -
getVariantService
-
validateVariants(Product, List, Errors)
instead