Class VariantValidator
java.lang.Object
com.broadleafcommerce.catalog.service.validation.VariantValidator
- All Implemented Interfaces:
com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
public class VariantValidator
extends Object
implements com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
Validations for
Variant
.- Author:
- Samarth Dhruva (samarthd)
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected Function<? super AttributeChoice,
Set<String>> getAllowedOptionValuesByAttrName
(Product referencedProduct) protected static String
protected static String
protected OptionTemplateService<OptionTemplate>
protected ProductService<Product>
protected void
hydrateOptionTemplates
(@NonNull Product product, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hydrate any product options that were added by reference from option templates to ensure that validation takes all the necessary info into account.protected BinaryOperator<Set<String>>
void
setOptionTemplateService
(OptionTemplateService<OptionTemplate> optionTemplateService) void
setProductService
(ProductService<Product> productService) Lazy injection since this validator is itself a service component.boolean
supports
(Class<?> serviceClass, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) void
validate
(Object businessInstance, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected void
validateActiveEndDate
(Variant variant, org.springframework.validation.Errors errors) protected void
validateCost
(Variant variant, javax.money.CurrencyUnit expectedCurrency, org.springframework.validation.Errors errors) protected void
validateCurrency
(String field, javax.money.MonetaryAmount monetaryAmount, javax.money.CurrencyUnit expectedCurrency, org.springframework.validation.Errors errors) protected void
validateDefaultPrice
(Variant variant, Product referencedProduct, javax.money.CurrencyUnit expectedCurrency, org.springframework.validation.Errors errors) protected void
validateOptions
(Variant variant, Product referencedProduct, org.springframework.validation.Errors errors) protected Product
validateProductId
(Variant variant, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Validates thatVariant.getProductId()
is present and ensures the product exists in the data store.protected void
validateProductType
(Product referencedProduct, org.springframework.validation.Errors errors) Validates that thereferenced product's product type
isVARIANT_BASED
as only VARIANT_BASED products can have variants.protected void
validateSalePrice
(Variant variant, javax.money.CurrencyUnit expectedCurrency, org.springframework.validation.Errors errors) protected void
validateSku
(org.springframework.validation.Errors errors) protected void
validateThresholds
(Variant variant, Product referencedProduct, org.springframework.validation.Errors errors) protected void
validateVariantOptionValues
(Map<String, String> variantOptionValues, Product referencedProduct, org.springframework.validation.Errors errors) Deprecated, for removal: This API element is subject to removal in a future version.since 1.9.0, allowed values are no longer validatedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
validateForCreate, validateForReplace, validateForUpdate
-
Constructor Details
-
VariantValidator
public VariantValidator()
-
-
Method Details
-
setProductService
Lazy injection since this validator is itself a service component. This avoids circular dependency exceptions- Parameters:
productService
- the product service
-
supports
public boolean supports(Class<?> serviceClass, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - 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
-
hydrateOptionTemplates
protected void hydrateOptionTemplates(@NonNull @NonNull Product product, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hydrate any product options that were added by reference from option templates to ensure that validation takes all the necessary info into account.- Parameters:
product
- The parent product of the variant being validatedcontextInfo
- Additional tenant and sandbox info
-
validateThresholds
-
validateDefaultPrice
-
validateSalePrice
protected void validateSalePrice(Variant variant, javax.money.CurrencyUnit expectedCurrency, org.springframework.validation.Errors errors) -
validateCost
protected void validateCost(Variant variant, javax.money.CurrencyUnit expectedCurrency, org.springframework.validation.Errors errors) -
validateCurrency
protected void validateCurrency(String field, javax.money.MonetaryAmount monetaryAmount, javax.money.CurrencyUnit expectedCurrency, org.springframework.validation.Errors errors) -
validateActiveEndDate
-
validateProductId
@Nullable protected Product validateProductId(Variant variant, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Validates thatVariant.getProductId()
is present and ensures the product exists in the data store.- Parameters:
variant
- the variant being validatederrors
- the errors object bound to the variant in which any validation errors should be registeredcontextInfo
- context information surrounding sandboxing and multitenant state- Returns:
- the referenced product if it exists in the data store,
null
otherwise
-
validateProductType
protected void validateProductType(@Nullable Product referencedProduct, @NonNull org.springframework.validation.Errors errors) Validates that thereferenced product's product type
isVARIANT_BASED
as only VARIANT_BASED products can have variants.- Parameters:
referencedProduct
- product that is referenced by the varianterrors
- the errors object bound to the variant in which any validation errors should be registered
-
validateSku
protected void validateSku(@NonNull org.springframework.validation.Errors errors) -
validateOptions
-
validateVariantOptionValues
@Deprecated(since="1.9.0", forRemoval=true) protected void validateVariantOptionValues(@NonNull Map<String, String> variantOptionValues, Product referencedProduct, org.springframework.validation.Errors errors) Deprecated, for removal: This API element is subject to removal in a future version.since 1.9.0, allowed values are no longer validated -
getAllowedOptionValuesByAttrName
-
allowedOptionValueMapper
-
mergeOptionValues
-
getOPTION_DOES_NOT_EXIST_MESSAGE
-
getOPTION_DOES_NOT_HAVE_VALUE_MESSAGE
-
getProductService
-
getOptionTemplateService
-
setOptionTemplateService
@Autowired @Lazy public void setOptionTemplateService(OptionTemplateService<OptionTemplate> optionTemplateService)
-