Class DataDrivenEnumValidator

java.lang.Object
com.broadleafcommerce.catalog.service.validation.DataDrivenEnumValidator
All Implemented Interfaces:
com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator

public class DataDrivenEnumValidator extends Object implements com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
Basic validations for DataDrivenEnum.
Author:
Sunny Yu
  • Constructor Details

    • DataDrivenEnumValidator

      public DataDrivenEnumValidator()
  • Method Details

    • setDataDrivenEnumService

      @Autowired @Lazy public void setDataDrivenEnumService(DataDrivenEnumService<DataDrivenEnum> dataDrivenEnumService)
      Lazy injection since this validator is itself a service component. This avoids circular dependency exceptions
      Parameters:
      dataDrivenEnumService - the data driven enum 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, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      validate in interface com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
    • validateForUpdate

      public void validateForUpdate(@NonNull Object updatedBusinessInstance, @NonNull org.springframework.validation.Errors errors, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      validateForUpdate in interface com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
    • validateForReplace

      public void validateForReplace(@NonNull Object businessInstance, @NonNull org.springframework.validation.Errors errors, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      validateForReplace in interface com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidator
    • validateUpdate

      protected void validateUpdate(@NonNull DataDrivenEnum dataDrivenEnum, @NonNull org.springframework.validation.Errors errors, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • validateType

      protected void validateType(org.springframework.validation.Errors errors)
    • validateValue

      protected void validateValue(@NonNull DataDrivenEnum dataDrivenEnum, org.springframework.validation.Errors errors)
    • validateDisplayValue

      protected void validateDisplayValue(org.springframework.validation.Errors errors)
    • checkTypeAndValueAlreadyExists

      protected void checkTypeAndValueAlreadyExists(@Nullable String id, @NonNull DataDrivenEnum dataDrivenEnum, @NonNull org.springframework.validation.Errors errors, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Validates that the type and value combination provided isn't already in use.
      Parameters:
      id - Optional. The id of the data driven enum being updated. If supplied, validation will pass if the data driven enum is already the owner of the type and value.
      dataDrivenEnum - The data driven enum to validate.
      errors - Errors object bound to dataDrivenEnum
      contextInfo - The current context.
    • readByTypeAndValue

      protected Optional<DataDrivenEnum> readByTypeAndValue(@Nullable String type, @Nullable String value, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Read a data driven enum by type and value.
      Parameters:
      type - The type of the enum.
      value - The value of the enum.
      contextInfo - The current context.
      Returns:
      an Optional containing the DataDrivenEnum with the type and value combination
    • prefixWithEntityValidationMessageKey

      protected String prefixWithEntityValidationMessageKey(String errorCode)
    • getEnumValuePattern

      public String getEnumValuePattern()
    • getDataDrivenEnumService

      protected DataDrivenEnumService<DataDrivenEnum> getDataDrivenEnumService()