Class SimpleCharacteristicValueValidator

java.lang.Object
com.broadleafcommerce.catalog.service.validation.characteristic.SimpleCharacteristicValueValidator
All Implemented Interfaces:
CharacteristicValueValidator

public class SimpleCharacteristicValueValidator extends Object implements CharacteristicValueValidator
An implementation of CharacteristicValueValidator that handles validation for simple CharacteristicValue.valueTypes, such as BOOLEAN or STRING.

Simple CharacteristicValue.valueTypes are identified as "simple" because they are expected to be one-to-one matches to their parent Characteristic.valueType.

Since:
Catalog Service 2.2.0, Release Train 2.2.0
Author:
Julia Lopez-Pozas (jlopezpozas)
  • Constructor Details

    • SimpleCharacteristicValueValidator

      public SimpleCharacteristicValueValidator(List<String> nonSimpleCharacteristicValueTypes, List<String> simpleCharacteristicValueValueTypes)
  • Method Details

    • canHandle

      public boolean canHandle(@NonNull @NonNull CharacteristicValue characteristicValue, @Nullable Characteristic characteristic)
      Description copied from interface: CharacteristicValueValidator
      Checks if this Validator can handle validation for the given CharacteristicValue.valueType.
      Specified by:
      canHandle in interface CharacteristicValueValidator
      Parameters:
      characteristicValue - the CharacteristicValue object to check against this Validator's expected Characteristic.valueTypes.
      characteristic - the Characteristic object to check against this Validator's expected Characteristic.valueType. Can be null if the Validator has no need for the Characteristic, like SimpleCharacteristicValueValidator
      Returns:
      true if this Validator handles validation for the Characteristic.value of this Characteristic.valueType, false if not
    • validate

      public void validate(@NonNull @NonNull CharacteristicValue characteristicValue, @NonNull @NonNull org.springframework.validation.Errors errors, @Nullable Characteristic characteristic)
      Description copied from interface: CharacteristicValueValidator
      Validates that each CharacteristicValue.value matches its CharacteristicValue.valueType, along with some DefaultCharacteristicValueValueType specific validation for CharacteristicValues.
      Specified by:
      validate in interface CharacteristicValueValidator
      Parameters:
      characteristicValue - The product characteristic value to validate
      errors - Holder for validation context information
      characteristic - The product characteristic that can be used for validation, if necessary
    • addInvalidCVValueForCVValueTypeError

      protected void addInvalidCVValueForCVValueTypeError(org.springframework.validation.Errors errors, String charValueValue, String charValueValueType)
      Method to add a validation error when the characteristic value's value does not match its value type.
      Parameters:
      errors - Holder for validation context information
      charValueValue - The characteristic value's value
      charValueValueType - The characteristic value's value type
    • getSimpleCharacteristicValueValueTypes

      protected List<String> getSimpleCharacteristicValueValueTypes()
      List of simple CharacteristicValue.valueTypes that match the Characteristic.valueTypes this validator handles.
    • getNonSimpleCharacteristicValueTypes

      protected List<String> getNonSimpleCharacteristicValueTypes()
      The list of Characteristic.valueTypes this Validator does not handle.