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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
     
    protected String
     
    void
    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(Category category, org.springframework.validation.Errors errors)
     
    protected void
    validateActiveStartDate(Category category, org.springframework.validation.Errors errors)
     
    protected void
    validateCategoryAncestry(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 void
    validateName(org.springframework.validation.Errors errors)
     
    protected void
    validateParentCategory(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 void
    validateProductMembershipType(org.springframework.validation.Errors errors)
     
    protected void
    validateUrl(Category category, 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

    • CategoryValidator

      public CategoryValidator()
  • Method Details

    • setCategoryService

      @Autowired @Lazy public void setCategoryService(CategoryService<Category> categoryService)
      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:
      supports in interface com.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 interface com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
    • validateName

      protected void validateName(org.springframework.validation.Errors errors)
    • validateUrl

      protected void validateUrl(Category category, org.springframework.validation.Errors errors)
    • 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. See validateCategoryAncestry(Category, Errors, ContextInfo) for more information.
      Parameters:
      category - the category to validate
      errors - the errors object bound to the category on which errors can be registered
      contextInfo - 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 validated
      errors - the errors object bound to the category on which errors can be registered
      contextInfo - context information surrounding sandboxing and multitenant state
    • prefixWithEntityValidationMessageKey

      protected String prefixWithEntityValidationMessageKey(String errorCode)
    • getCategoryService

      protected CategoryService<Category> getCategoryService()