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
Constructors - 
Method Summary
Modifier and TypeMethodDescriptionprotected Function<? super AttributeChoice,Set<String>> getAllowedOptionValuesByAttrName(Product referencedProduct) protected static Stringprotected static Stringprotected OptionTemplateService<OptionTemplate>protected ProductService<Product>protected voidhydrateOptionTemplates(@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>>voidsetOptionTemplateService(OptionTemplateService<OptionTemplate> optionTemplateService) voidsetProductService(ProductService<Product> productService) Lazy injection since this validator is itself a service component.booleansupports(Class<?> serviceClass, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) voidvalidate(Object businessInstance, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected voidvalidateActiveEndDate(Variant variant, org.springframework.validation.Errors errors) protected voidvalidateCost(Variant variant, javax.money.CurrencyUnit expectedCurrency, org.springframework.validation.Errors errors) protected voidvalidateCurrency(String field, javax.money.MonetaryAmount monetaryAmount, javax.money.CurrencyUnit expectedCurrency, org.springframework.validation.Errors errors) protected voidvalidateDefaultPrice(Variant variant, Product referencedProduct, javax.money.CurrencyUnit expectedCurrency, org.springframework.validation.Errors errors) protected voidvalidateOptions(Variant variant, Product referencedProduct, org.springframework.validation.Errors errors) protected ProductvalidateProductId(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 voidvalidateProductType(Product referencedProduct, org.springframework.validation.Errors errors) Validates that thereferenced product's product typeisVARIANT_BASEDas only VARIANT_BASED products can have variants.protected voidvalidateSalePrice(Variant variant, javax.money.CurrencyUnit expectedCurrency, org.springframework.validation.Errors errors) protected voidvalidateSku(org.springframework.validation.Errors errors) protected voidvalidateThresholds(Variant variant, Product referencedProduct, org.springframework.validation.Errors errors) protected voidvalidateVariantOptionValues(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, waitMethods 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:
 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
 - 
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, 
nullotherwise 
 - 
validateProductType
protected void validateProductType(@Nullable Product referencedProduct, @NonNull org.springframework.validation.Errors errors) Validates that thereferenced product's product typeisVARIANT_BASEDas 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)  
 -