Class ProductOptionValidator
java.lang.Object
com.broadleafcommerce.catalog.service.validation.ProductOptionValidator
- All Implemented Interfaces:
com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
public class ProductOptionValidator
extends Object
implements com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
Validations for
ProductOption. Generally speaking, since ProductOption is not an
independent entity, this validator should be called by the validators of entities who contain
ProductOptions, such as OptionTemplateValidator and
ProductValidator.- Author:
- Samarth Dhruva (samarthd)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classInner class specifically responsible for validation ofProductOption.getAttributeChoice().protected classInner class specifically responsible for validation ofProductOption.getItemChoice(). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Optional<OptionTemplate>findOptionTemplate(String templateContextId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Wrapper aroundOptionTemplateService.readById(String, ContextInfo)that catchesEntityMissingExceptionand returns anOptional.empty()if so.protected CategoryProductService<CategoryProduct>protected CategoryService<Category>protected OptionTemplateService<OptionTemplate>protected ProductService<Product>protected VariantService<Variant>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.voidsetOptionTemplateService(OptionTemplateService<OptionTemplate> optionTemplateService) Lazy injection since this validator is itself a service component.voidsetProductService(ProductService<Product> productService) Lazy injection since this validator is itself a service component.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 voidvalidateAttributeChoice(ProductOption option, org.springframework.validation.Errors errors) protected voidvalidateItemChoice(ProductOption option, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected voidvalidateReferenceOptionTemplate(ProductOption option, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected voidvalidateType(org.springframework.validation.Errors errors) Methods 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
-
ProductOptionValidator
public ProductOptionValidator()
-
-
Method Details
-
setCategoryService
Lazy injection since this validator is itself a service component. This avoids circular dependency exceptions- Parameters:
categoryService- the category service
-
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
-
setOptionTemplateService
@Autowired @Lazy public void setOptionTemplateService(OptionTemplateService<OptionTemplate> optionTemplateService) Lazy injection since this validator is itself a service component. This avoids circular dependency exceptions- Parameters:
optionTemplateService- the optionTemplate service
-
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
-
validateType
protected void validateType(org.springframework.validation.Errors errors) -
validateItemChoice
protected void validateItemChoice(ProductOption option, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
validateReferenceOptionTemplate
protected void validateReferenceOptionTemplate(ProductOption option, org.springframework.validation.Errors errors, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
findOptionTemplate
protected Optional<OptionTemplate> findOptionTemplate(String templateContextId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Wrapper aroundOptionTemplateService.readById(String, ContextInfo)that catchesEntityMissingExceptionand returns anOptional.empty()if so.- Parameters:
templateContextId- the ID of the option template to findcontextInfo- context information surrounding sandboxing and multitenant state- Returns:
- an optional containing the category if found,
Optional.empty()otherwise
-
validateAttributeChoice
protected void validateAttributeChoice(ProductOption option, org.springframework.validation.Errors errors) -
getCategoryService
-
getProductService
-
getCategoryProductService
-
getVariantService
-
getOptionTemplateService
-
getItemChoiceValidator
-
getAttributeChoiceValidator
-