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
Modifier and TypeClassDescriptionprotected class
Inner class specifically responsible for validation ofProductOption.getAttributeChoice()
.protected class
Inner class specifically responsible for validation ofProductOption.getItemChoice()
. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected Optional<OptionTemplate>
findOptionTemplate
(String templateContextId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Wrapper aroundOptionTemplateService.readById(String, ContextInfo)
that catchesEntityMissingException
and returns anOptional.empty()
if so.protected CategoryProductService<CategoryProduct>
protected CategoryService<Category>
protected OptionTemplateService<OptionTemplate>
protected ProductService<Product>
protected VariantService<Variant>
void
setCategoryProductService
(CategoryProductService<CategoryProduct> categoryProductService) Lazy injection since this validator is itself a service component.void
setCategoryService
(CategoryService<Category> categoryService) Lazy injection since this validator is itself a service component.void
setOptionTemplateService
(OptionTemplateService<OptionTemplate> optionTemplateService) Lazy injection since this validator is itself a service component.void
setProductService
(ProductService<Product> productService) Lazy injection since this validator is itself a service component.void
setVariantService
(VariantService<Variant> variantService) Lazy injection since this validator is itself a service component.boolean
void
validate
(Object businessInstance, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected void
validateAttributeChoice
(ProductOption option, org.springframework.validation.Errors errors) protected void
validateItemChoice
(ProductOption option, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected void
validateReferenceOptionTemplate
(ProductOption option, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected void
validateType
(org.springframework.validation.Errors errors) Methods 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
-
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:
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
-
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 catchesEntityMissingException
and 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
-