Skip to content

Commit

Permalink
Added support for custom constraint messages in all but allowed value…
Browse files Browse the repository at this point in the history
  • Loading branch information
david-waltermire committed Oct 27, 2024
1 parent c183670 commit c782f23
Show file tree
Hide file tree
Showing 43 changed files with 755 additions and 396 deletions.
2 changes: 1 addition & 1 deletion core/metaschema
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* SPDX-FileCopyrightText: none
* SPDX-License-Identifier: CC0-1.0
*/

package gov.nist.secauto.metaschema.core.model.constraint;

import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;

/**
* Provides builder methods for the core data elements of an
* {@link IConstraint}.
* <p>
* The base class of all constraint builders.
*
* @param <T>
* the Java type of the implementing builder
* @param <R>
* the Java type of the resulting built object
* @since 2.0.0
*/
public abstract class AbstractConfigurableMessageConstraintBuilder<
T extends AbstractConfigurableMessageConstraintBuilder<T, R>,
R extends IConfigurableMessageConstraint>
extends AbstractConstraintBuilder<T, R> {
private String message;

/**
* A message to emit when the constraint is violated. Allows embedded Metapath
* expressions using the syntax {@code \{ metapath \}}.
*
* @param message
* the message if defined or {@code null} otherwise
* @return this builder
*/
@NonNull
public T message(@NonNull String message) {
this.message = message;
return getThis();
}

/**
* Get the constraint message provided to the builder.
*
* @return the message or {@code null} if no message is set
*/
@Nullable
protected String getMessage() {
return message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public abstract class AbstractConstraintBuilder<
private String target = IConstraint.DEFAULT_TARGET_METAPATH;
@NonNull
private Map<IAttributable.Key, Set<String>> properties = new LinkedHashMap<>(); // NOPMD not thread safe
private String message;
private MarkupMultiline remarks;

/**
Expand Down Expand Up @@ -180,20 +179,6 @@ public T property(@NonNull IAttributable.Key key, @NonNull Set<String> values) {
return getThis();
}

/**
* A message to emit when the constraint is violated. Allows embedded Metapath
* expressions using the syntax {@code \{ metapath \}}.
*
* @param message
* the message if defined or {@code null} otherwise
* @return this builder
*/
@NonNull
public T message(@NonNull String message) {
this.message = message;
return getThis();
}

/**
* Set the provided {@code remarks}.
*
Expand Down Expand Up @@ -309,16 +294,6 @@ protected Map<IAttributable.Key, Set<String>> getProperties() {
return properties;
}

/**
* Get the constraint message provided to the builder.
*
* @return the message or {@code null} if no message is set
*/
@Nullable
protected String getMessage() {
return message;
}

/**
* Get the remarks provided to the builder.
*
Expand Down
Loading

0 comments on commit c782f23

Please sign in to comment.