Interface Validated

All Known Subinterfaces:
Credentials, RoleUserCredentials
All Known Implementing Classes:
ContentInfo, ContentRepository, DatabaseContentInfo, MetaData, RoleUser, Task, TaskOption, Validation

public interface Validated
This interface defines methods for bean-centric data validation.

Validation is bound to subjects that have distinct names. Each subject corresponds to a different variable, for example a property of a bean. When a subject is found to be invalid, a corresponding instance of ValidationError has to be registered.

ValidationErrors indicate in detail why a Validated object doesn't contain valid data. They should be stored internally and can be manipulated by other classes that are able to work with Validated objects. This makes it possible to collect errors incrementally in one central place and to allow each component in a system to perform its own part of the validation.

A Validated object has a validate() method which should be used to perform mandatory validation on subjects and data that the object itself knows about. This validation has to perform all checks that guarantee a coherent internal state of the data. Note that this method should not reset the validation, but instead add new validation errors to an already existing collection.

Since it's possible that subjects generate multiple ValidationErrors, it's possible to limit their number and only store the first error that occurs for a particular subject.

Since:
1.0
See Also:
  • Method Details

    • validate

      boolean validate()
      Validates the internal subjects.

      This method is not supposed to reset the validation errors or to start the validation from scratch, but it's intended to add additional errors to an existing collection.

      Returns:
      true if no validation errors are present after the validation; or

      false if validation errors are available.

      Since:
      1.0
      See Also:
    • validate

      boolean validate(ValidationContext context)
      Validates the internal subjects and also validates the bean within the provided ValidationContext

      This method is not supposed to reset the validation errors or to start the validation from scratch, but it's intended to add additional errors to an existing collection.

      Parameters:
      context - the ValidationContext in which this bean instance will be additionally validated
      Returns:
      true if no validation errors are present after the validation; or

      false if validation errors are available.

      Since:
      1.0
      See Also:
    • addRule

      void addRule(ValidationRule rule)

      Adds a new validation rule.

      The collection of rules is what is supposed to perform the validation, though any other additional method could be used. At least those rules that have been registered will be evaluated.

      Parameters:
      rule - the rule that will be added
      Since:
      1.0
      See Also:
    • getRules

      List<ValidationRule> getRules()
      Retrieves that validation rules that have been registered.
      Since:
      1.0
      See Also:
    • resetValidation

      void resetValidation()

      Resets the validation by removing all validation errors that are currently present.

      This method is typically used to start a new validation from scratch or to re-validate until all errors have been solved.

      Since:
      1.0
      See Also:
    • addValidationError

      void addValidationError(ValidationError error)
      Add a new validation error explicitly to the collection of already existing errors.

      Note that this method should respect subjects with a limited error amount and only store the first error for these subjects.

      Parameters:
      error - the ValidationError to add
      Since:
      1.0
      See Also:
    • getValidationErrors

      Set<ValidationError> getValidationErrors()
      Returns a set with all the stored ValidationErrors.
      Returns:
      A Set instance with all the stored ValidationErrors. Note that when no errors are available an empty set is returned, not null.
      Since:
      1.0
    • countValidationErrors

      int countValidationErrors()
      Counts the number of stored ValidationErrors.
      Returns:
      The number of stored ValidationErrors.
      Since:
      1.0
    • replaceValidationErrors

      void replaceValidationErrors(Set<ValidationError> errors)
      Replaces the stored ValidationErrors with a new set of errors.
      Parameters:
      errors - the Set instance that contains all the ValidationErrors that have to be stored.
      Since:
      1.0
    • limitSubjectErrors

      void limitSubjectErrors(String subject)
      Limits the number of errors for a particular subject so that maximum one ValidationError can be stored for it.
      Parameters:
      subject - the name of the subject that has to be limited.
      Since:
      1.0
    • unlimitSubjectErrors

      void unlimitSubjectErrors(String subject)
      Unlimits the number of errors for a particular subject so that any number of ValidationErrors can be stored for it.
      Parameters:
      subject - the name of the subject that has to be unlimited.
      Since:
      1.0
    • getValidatedSubjects

      List<String> getValidatedSubjects()
      Returns the list of subjects that this object is able to validate internally through the validate() method.
      Returns:
      a List instance with the names of the internally validated subjects
      Since:
      1.0
    • isSubjectValid

      boolean isSubjectValid(String subject)
      Checks if a subject is valid.

      This is determined by verifying if there are ValidationErrors present for it. This method will thus not execute a validation action.

      Parameters:
      subject - the name of the subject that has to be checked.
      Returns:
      true when no errors could be found for the subject; or

      false when errors are present for the subject.

      Since:
      1.0
      See Also:
    • makeErrorValid

      void makeErrorValid(String identifier, String subject)
      Makes errors for a particular subject and identifier valid.

      This is done by removing all ValidationErrors that are stored with this identifier and subject.

      Parameters:
      identifier - the name of the error identifier that has to be made
      subject - the name of the subject that has to be made valid. valid.
      Since:
      1.0
    • makeSubjectValid

      void makeSubjectValid(String subject)
      Makes a subject valid.

      This is done by removing all ValidationErrors that are stored for it.

      Parameters:
      subject - the name of the subject that has to be made valid.
      Since:
      1.0
    • provideValidatedBean

      void provideValidatedBean(Validated bean)
      Provide the bean instance that will be validated.

      By default 'this' will be used.

      Parameters:
      bean - the bean instance that will be validated
      Since:
      1.0
    • retrieveValidatedBean

      Validated retrieveValidatedBean()
      Retrieves the bean instance that will be validated.
      Since:
      1.0
    • addGroup

      ValidationGroup addGroup(String name)
      Adds a new validation group.
      Parameters:
      name - the name of the validation group that needs to be created and added
      Returns:
      the newly created ValidationGroup
      Since:
      1.0
    • focusGroup

      void focusGroup(String name)
      Focuses on one particular validation group, showing only the ValidationErrors that were generated by its ValidationRules.
      Parameters:
      name - the name of the validation group that will be focused
      Since:
      1.0
    • resetGroup

      void resetGroup(String name)
      Removed all the ValidationErrors of a particular validation group.
      Parameters:
      name - the name of the validation group that will be focused
      Since:
      1.0
    • getGroups

      Retrieves all validation groups.
      Returns:
      the collection of all registered validation groups
      Since:
      1.0
    • getGroup

      ValidationGroup getGroup(String name)
      Retrieve a particular validation group.
      Parameters:
      name - the name of the validation group that will be retrieved
      Returns:
      the requested ValidationGroup; or

      null if no such validation group exists

      Since:
      1.0
    • validateGroup

      boolean validateGroup(String name)
      Validate the ValidationRules of a particular validation group.
      Parameters:
      name - the name of the validation group that will be retrieved
      Returns:
      true if no validation errors were generated; or

      false otherwise

      Since:
      1.0
    • validateGroup

      boolean validateGroup(String name, ValidationContext context)
      Validate the ValidationRules of a particular validation group and also validates the entire bean within the provided ValidationContext
      Parameters:
      name - the name of the validation group
      context - the ValidationContext in which this bean instance will be additionally validated
      Returns:
      true if no validation errors were generated; or

      false otherwise

      Since:
      1.0
    • addConstrainedPropertyRules

      List<PropertyValidationRule> addConstrainedPropertyRules(ConstrainedProperty constrainedProperty)
      Adds the validation rules that are related to a particular ConstrainedProperty.

      If the rules of this property name have already been added before through another ConstrainedProperty instance, its existing ValidationRules will be erased and the previous constraints will be merged into the new ConstrainedProperty before adding its validation rules.

      Parameters:
      constrainedProperty - the ConstrainedProperty that will be inspected
      Returns:
      the list of generated ValidationRules
      Since:
      1.0
    • generateConstrainedPropertyRules

      List<PropertyValidationRule> generateConstrainedPropertyRules(ConstrainedProperty constrainedProperty)
      Generates the validation rules that are related to a particular ConstrainedProperty.
      Parameters:
      constrainedProperty - the ConstrainedProperty that will be inspected
      Returns:
      the list of generated ValidationRules
      Since:
      1.0
    • getLoadingErrors

      Collection<String> getLoadingErrors(String propertyName)
      Returns the collection of error messages that occurred during the loading of the content of a certain property.
      Parameters:
      propertyName - the name of the property whose loading errors should be obtained
      Returns:
      null if no errors occurred during the loading of the content of the provided property or if the property doesn't exist; or

      the requested collection of error messages

      Since:
      1.0