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 that the target contents of the
22   * assembly, represented by the containing {@link MetaschemaAssembly}
23   * annotation, reference items in a name index defined by the {@link Index}
24   * constraint.
25   */
26  
27  @Documented
28  @Retention(RUNTIME)
29  @Target(ANNOTATION_TYPE)
30  public @interface IndexHasKey {
31    /**
32     * An optional identifier for the constraint, which must be unique to only this
33     * constraint.
34     *
35     * @return the identifier if provided or an empty string otherwise
36     */
37    @SuppressWarnings("PMD.ShortMethodName")
38    @NonNull
39    String id() default "";
40  
41    /**
42     * An optional formal name for the constraint.
43     *
44     * @return the formal name if provided or an empty string otherwise
45     */
46    @NonNull
47    String formalName() default "";
48  
49    /**
50     * An optional description of the constraint.
51     *
52     * @return the description if provided or an empty string otherwise
53     */
54    @NonNull
55    String description() default "";
56  
57    /**
58     * The significance of a violation of this constraint.
59     *
60     * @return the level
61     */
62    @NonNull
63    Level level() default IConstraint.Level.ERROR;
64  
65    /**
66     * An optional metapath that points to the target flag or field value that the
67     * constraint applies to. If omitted the target will be ".", which means the
68     * target is the value of the {@link BoundFlag}, {@link BoundField} or
69     * {@link BoundFieldValue} annotation the constraint appears on. In the prior
70     * case, this annotation may only appear on a {@link BoundField} if the field
71     * has no flags, which results in a {@link BoundField} annotation on a field
72     * instance with a scalar, data type value.
73     *
74     * @return the target metapath
75     */
76    @NonNull
77    String target() default ".";
78  
79    /**
80     * An optional set of properties associated with these allowed values.
81     *
82     * @return the properties or an empty array with no properties
83     */
84    Property[] properties() default {};
85  
86    /**
87     * A reference to a named index.
88     *
89     * @return the index name
90     */
91    @NonNull
92    String indexName();
93  
94    /**
95     * A list of one or more keys to use in looking up an entry in a given index.
96     *
97     * @return one or more keys
98     */
99    @NonNull
100   KeyField[] keyFields();
101 
102   /**
103    * The message to emit when the constraint is violated.
104    *
105    * @return the message or an empty string otherwise
106    */
107   @NonNull
108   String message() default "";
109 
110   /**
111    * Any remarks about the constraint, encoded as an escaped Markdown string.
112    *
113    * @return an encoded markdown string or an empty string if no remarks are
114    *         provided
115    */
116   @NonNull
117   String remarks() default "";
118 }