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