001/*
002 * SPDX-FileCopyrightText: none
003 * SPDX-License-Identifier: CC0-1.0
004 */
005
006package gov.nist.secauto.metaschema.databind.model.annotations;
007
008import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
009import static java.lang.annotation.RetentionPolicy.RUNTIME;
010
011import gov.nist.secauto.metaschema.core.model.constraint.IConstraint;
012import gov.nist.secauto.metaschema.core.model.constraint.IConstraint.Level;
013
014import java.lang.annotation.Documented;
015import java.lang.annotation.Retention;
016import java.lang.annotation.Target;
017
018import edu.umd.cs.findbugs.annotations.NonNull;
019
020/**
021 * This annotation defines a rule that requires uniqueness among the target
022 * contents of the assembly represented by the containing
023 * {@link MetaschemaAssembly} annotation.
024 */
025@Documented
026@Retention(RUNTIME)
027@Target(ANNOTATION_TYPE)
028public @interface IsUnique {
029  /**
030   * An optional identifier for the constraint, which must be unique to only this
031   * constraint.
032   *
033   * @return the identifier if provided or an empty string otherwise
034   */
035  @SuppressWarnings("PMD.ShortMethodName")
036  @NonNull
037  String id() default "";
038
039  /**
040   * An optional formal name for the constraint.
041   *
042   * @return the formal name if provided or an empty string otherwise
043   */
044  @NonNull
045  String formalName() default "";
046
047  /**
048   * An optional description of the constraint.
049   *
050   * @return the description if provided or an empty string otherwise
051   */
052  @NonNull
053  String description() default "";
054
055  /**
056   * The significance of a violation of this constraint.
057   *
058   * @return the level
059   */
060  @NonNull
061  Level level() default IConstraint.Level.ERROR;
062
063  /**
064   * An optional metapath that points to the target flag or field value that the
065   * constraint applies to. If omitted the target will be ".", which means the
066   * target is the value of the {@link BoundFlag}, {@link BoundField} or
067   * {@link BoundFieldValue} annotation the constraint appears on. In the prior
068   * case, this annotation may only appear on a {@link BoundField} if the field
069   * has no flags, which results in a {@link BoundField} annotation on a field
070   * instance with a scalar, data type value.
071   *
072   * @return the target metapath
073   */
074  @NonNull
075  String target() default ".";
076
077  /**
078   * An optional set of properties associated with these allowed values.
079   *
080   * @return the properties or an empty array with no properties
081   */
082  Property[] properties() default {};
083
084  /**
085   * A list of one or more keys to use in looking up an entry in a given index.
086   *
087   * @return one or more keys
088   */
089  @NonNull
090  KeyField[] keyFields();
091
092  /**
093   * The message to emit when the constraint is violated.
094   *
095   * @return the message or an empty string otherwise
096   */
097  @NonNull
098  String message() default "";
099
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}