Class Validator

java.lang.Object
org.incenp.obofoundry.sssom.Validator

public class Validator extends Object
Helper class to validate MappingSet and Mapping objects.

This class is primarily intended to be used internally by the parsers for post-parsing validation, to ensure that the parsed objects are compliant with the requirements from the SSSOM specification. However it may also be used independently of the parsers, for example to validate a set that was constructed ex nihilo.

  • Constructor Details

    • Validator

      public Validator()
      Creates a new instance.
    • Validator

      public Validator(ValidationLevel validationLevel)
      Creates a new instance with the specified validation level.
      Parameters:
      validationLevel - Indicates which checks should be performed.
  • Method Details

    • validate

      public EnumSet<ValidationError> validate(MappingSet ms)
      Checks whether the given mapping set, including the mappings it contains, is valid.
      Parameters:
      ms - The mapping set to validate.
      Returns:
      A set of all the validation errors encountered when checking the mapping set (will be empty if the mapping set is in fact valid).
    • validate

      public EnumSet<ValidationError> validate(MappingSet ms, boolean alwaysCheckMappings)
      Checks whether the given mapping set is valid.

      This method allows to skip checking the individual mappings if the set itself is invalid.

      Parameters:
      ms - The mapping set to validate.
      alwaysCheckMappings - If true, individual mappings will always be checked; otherwise, they will be checked only if there are no errors already at the level of the mapping set.
      Returns:
      A set of all the validation errors encountered when checking the mapping set (will be empty if the mapping set is in fact valid).
    • check

      public void check(MappingSet ms) throws SSSOMFormatException
      Checks whether the given mapping set is valid, and throws an exception if it is not.
      Parameters:
      ms - The mapping set to validate.
      Throws:
      SSSOMFormatException - If the mapping set is invalid.
    • validate

      @Deprecated public String validate(Mapping mapping)
      Deprecated.
      Use validate(MappingSet) to validate an entire mapping set instead.
      Validates an individual mapping. This method checks that the slots that are required by the specification are present and non-empty.
      Parameters:
      mapping - The mapping to validate.
      Returns:
      An error message if the mapping is invalid, otherwise null.
    • getCompliantVersion

      public Version getCompliantVersion(MappingSet set)
      Gets the minimum version of the SSSOM specification that the given set is compliant with.

      FIXME: This does not really have anything to do with “validation”, so this class may not be the best place for such a method.

      Parameters:
      set - The set whose compliance is to be checked.
      Returns:
      The earliest version of the SSSOM specification that defines all slots and values required by the set.