1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package gov.nist.secauto.metaschema.databind.model.annotations;
7   
8   import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
9   import static java.lang.annotation.RetentionPolicy.RUNTIME;
10  
11  import gov.nist.secauto.metaschema.core.model.constraint.IConstraint;
12  import gov.nist.secauto.metaschema.core.model.constraint.IConstraint.Level;
13  
14  import java.lang.annotation.Documented;
15  import java.lang.annotation.Retention;
16  import java.lang.annotation.Target;
17  
18  import edu.umd.cs.findbugs.annotations.NonNull;
19  
20  /**
21   * This annotation defines a rule that requires uniqueness among the target
22   * contents of the assembly represented by the containing
23   * {@link MetaschemaAssembly} annotation.
24   */
25  @Documented
26  @Retention(RUNTIME)
27  @Target(ANNOTATION_TYPE)
28  public @interface IsUnique {
29    /**
30     * An optional identifier for the constraint, which must be unique to only this
31     * constraint.
32     *
33     * @return the identifier if provided or an empty string otherwise
34     */
35    @SuppressWarnings("PMD.ShortMethodName")
36    @NonNull
37    String id() default "";
38  
39    /**
40     * An optional formal name for the constraint.
41     *
42     * @return the formal name if provided or an empty string otherwise
43     */
44    @NonNull
45    String formalName() default "";
46  
47    /**
48     * An optional description of the constraint.
49     *
50     * @return the description if provided or an empty string otherwise
51     */
52    @NonNull
53    String description() default "";
54  
55    /**
56     * The significance of a violation of this constraint.
57     *
58     * @return the level
59     */
60    @NonNull
61    Level level() default IConstraint.Level.ERROR;
62  
63    /**
64     * An optional metapath that points to the target flag or field value that the
65     * constraint applies to. If omitted the target will be ".", which means the
66     * target is the value of the {@link BoundFlag}, {@link BoundField} or
67     * {@link BoundFieldValue} annotation the constraint appears on. In the prior
68     * case, this annotation may only appear on a {@link BoundField} if the field
69     * has no flags, which results in a {@link BoundField} annotation on a field
70     * instance with a scalar, data type value.
71     *
72     * @return the target metapath
73     */
74    @NonNull
75    String target() default ".";
76  
77    /**
78     * An optional set of properties associated with these allowed values.
79     *
80     * @return the properties or an empty array with no properties
81     */
82    Property[] properties() default {};
83  
84    /**
85     * A list of one or more keys to use in looking up an entry in a given index.
86     *
87     * @return one or more keys
88     */
89    @NonNull
90    KeyField[] keyFields();
91  
92    /**
93     * The message to emit when the constraint is violated.
94     *
95     * @return the message or an empty string otherwise
96     */
97    @NonNull
98    String message() default "";
99  
100   /**
101    * Any remarks about the constraint, encoded as an escaped Markdown string.
102    *
103    * @return an encoded markdown string or an empty string if no remarks are
104    *         provided
105    */
106   @NonNull
107   String remarks() default "";
108 }