1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package dev.metaschema.core.model.constraint.impl;
7   
8   import java.util.Map;
9   import java.util.Set;
10  
11  import dev.metaschema.core.datatype.markup.MarkupLine;
12  import dev.metaschema.core.datatype.markup.MarkupMultiline;
13  import dev.metaschema.core.metapath.IMetapathExpression;
14  import dev.metaschema.core.metapath.item.atomic.IBooleanItem;
15  import dev.metaschema.core.model.IAttributable;
16  import dev.metaschema.core.model.ISource;
17  import dev.metaschema.core.model.constraint.IReportConstraint;
18  import edu.umd.cs.findbugs.annotations.NonNull;
19  import edu.umd.cs.findbugs.annotations.Nullable;
20  
21  /**
22   * Represents a report constraint.
23   * <p>
24   * A report constraint generates a finding when the associated test evaluates to
25   * {@link IBooleanItem#TRUE} against the target. This is the opposite behavior
26   * of an expect constraint, which generates a finding when the test evaluates to
27   * {@code FALSE}.
28   * <p>
29   * Report constraints are useful for:
30   * <ul>
31   * <li>Flagging deprecated patterns or values</li>
32   * <li>Reporting known issues or limitations</li>
33   * <li>Providing informational messages about content characteristics</li>
34   * </ul>
35   *
36   * @since 2.0.0
37   */
38  public final class DefaultReportConstraint
39      extends AbstractConfigurableMessageConstraint
40      implements IReportConstraint {
41    @NonNull
42    private final IMetapathExpression test;
43  
44    /**
45     * Construct a new report constraint.
46     *
47     * @param id
48     *          the optional identifier for the constraint
49     * @param formalName
50     *          the constraint's formal name or {@code null} if not provided
51     * @param description
52     *          the constraint's semantic description or {@code null} if not
53     *          provided
54     * @param source
55     *          information about the constraint source
56     * @param level
57     *          the significance of a violation of this constraint
58     * @param target
59     *          the Metapath expression identifying the nodes the constraint targets
60     * @param properties
61     *          a collection of associated properties
62     * @param test
63     *          a Metapath expression that is evaluated against the target node to
64     *          determine if a condition should be reported; a finding is generated
65     *          when this evaluates to {@code true}
66     * @param message
67     *          an optional message to emit when the constraint condition is matched
68     * @param remarks
69     *          optional remarks describing the intent of the constraint
70     */
71    @SuppressWarnings("PMD.ExcessiveParameterList")
72    public DefaultReportConstraint(
73        @Nullable String id,
74        @Nullable String formalName,
75        @Nullable MarkupLine description,
76        @NonNull ISource source,
77        @NonNull Level level,
78        @NonNull IMetapathExpression target,
79        @NonNull Map<IAttributable.Key, Set<String>> properties,
80        @NonNull IMetapathExpression test,
81        @Nullable String message,
82        @Nullable MarkupMultiline remarks) {
83      super(id, formalName, description, source, level, target, properties, message, remarks);
84      this.test = test;
85    }
86  
87    @Override
88    public IMetapathExpression getTest() {
89      return test;
90    }
91  }