1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package dev.metaschema.core.model.validation;
7   
8   import java.util.Collections;
9   import java.util.List;
10  
11  import dev.metaschema.core.model.constraint.IConstraint.Level;
12  import edu.umd.cs.findbugs.annotations.NonNull;
13  
14  /**
15   * Provides data that is the result of a completed content validation.
16   */
17  public interface IValidationResult {
18    /**
19     * A validation result indicating no validation errors were found.
20     */
21    @NonNull
22    IValidationResult PASSING_RESULT = new IValidationResult() {
23  
24      @Override
25      public boolean isPassing() {
26        return true;
27      }
28  
29      @Override
30      public Level getHighestSeverity() {
31        return Level.INFORMATIONAL;
32      }
33  
34      @SuppressWarnings("null")
35      @Override
36      public List<? extends IValidationFinding> getFindings() {
37        return Collections.emptyList();
38      }
39    };
40  
41    /**
42     * Determines if the result of validation was valid or not.
43     *
44     * @return {@code true} if the result was determined to be valid or
45     *         {@code false} otherwise
46     */
47    default boolean isPassing() {
48      return getHighestSeverity().ordinal() < Level.ERROR.ordinal();
49    }
50  
51    /**
52     * Get the highest finding severity level for the validation. The level
53     * {@link Level#INFORMATIONAL} will be returned if no validation findings were
54     * identified.
55     *
56     * @return the highest finding severity level
57     */
58    @NonNull
59    Level getHighestSeverity();
60  
61    /**
62     * Get the list of validation findings, which may be empty.
63     *
64     * @return the list
65     */
66    @NonNull
67    List<? extends IValidationFinding> getFindings();
68  }