Class CategoryValidator
java.lang.Object
com.broadleafcommerce.catalog.service.validation.CategoryValidator
- All Implemented Interfaces:
com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
public class CategoryValidator
extends Object
implements com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
Validations for
Category.- Author:
- Samarth Dhruva (samarthd)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected CategoryService<Category>protected StringprefixWithEntityValidationMessageKey(String errorCode) voidsetCategoryService(CategoryService<Category> categoryService) 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(Category category, org.springframework.validation.Errors errors) protected voidvalidateActiveStartDate(Category category, org.springframework.validation.Errors errors) protected voidvalidateCategoryAncestry(Category category, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) For a cycle check, we could theoretically just compare the category's id against each of its ancestors instead of keeping a set of all seen ancestors.protected voidvalidateName(org.springframework.validation.Errors errors) protected voidvalidateParentCategory(Category category, org.springframework.validation.Errors errors, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Traverses the full ancestry of the category to confirm each ancestor still exists and there are no cycles, either in the case that the ancestors already had cycles, or in the case that this category itself causes a cycle.protected voidvalidateProductMembershipType(org.springframework.validation.Errors errors) protected voidvalidateUrl(Category category, 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
-
CategoryValidator
public CategoryValidator()
-
-
Method Details
-
setCategoryService
Lazy injection since this validator is itself a service component. This avoids circular dependency exceptions- Parameters:
categoryService- the category 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
-
validateName
protected void validateName(org.springframework.validation.Errors errors) -
validateUrl
-
validateActiveStartDate
protected void validateActiveStartDate(Category category, org.springframework.validation.Errors errors) -
validateActiveEndDate
protected void validateActiveEndDate(Category category, org.springframework.validation.Errors errors) -
validateProductMembershipType
protected void validateProductMembershipType(org.springframework.validation.Errors errors) -
validateParentCategory
protected void validateParentCategory(Category category, org.springframework.validation.Errors errors, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Traverses the full ancestry of the category to confirm each ancestor still exists and there are no cycles, either in the case that the ancestors already had cycles, or in the case that this category itself causes a cycle. SeevalidateCategoryAncestry(Category, Errors, ContextInfo)for more information.- Parameters:
category- the category to validateerrors- the errors object bound to thecategoryon which errors can be registeredcontextInfo- context information surrounding sandboxing and multitenant state
-
validateCategoryAncestry
protected void validateCategoryAncestry(Category category, org.springframework.validation.Errors errors, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) For a cycle check, we could theoretically just compare the category's id against each of its ancestors instead of keeping a set of all seen ancestors. This is because we can be fairly confident that each already-persisted ancestor was also validated against having cycles in its own ancestry, and thus any cycle will almost definitely be caused by this category becoming a parent of itself.However, it's possible there is a pre-existing cycle if category data was persisted without validation (ex: via direct SQL). Checking for it here helps guard against an infinite loop in this logic which could be caused by such a cycle.
- Parameters:
category- the category whose ancestry should be validatederrors- the errors object bound to thecategoryon which errors can be registeredcontextInfo- context information surrounding sandboxing and multitenant state
-
prefixWithEntityValidationMessageKey
-
getCategoryService
-