This is an automated email from the ASF dual-hosted git repository. danhaywood pushed a commit to branch v2 in repository https://gitbox.apache.org/repos/asf/causeway-app-petclinic.git
commit b398464983c4728958c6bf40f537791e38144e1e Author: Dan Haywood <[email protected]> AuthorDate: Sat May 25 15:30:54 2024 +0100 Adds a mustSatisfy Specification to Name meta-annotation --- .../java/domainapp/modules/petowner/types/Name.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/module-petowner/src/main/java/domainapp/modules/petowner/types/Name.java b/module-petowner/src/main/java/domainapp/modules/petowner/types/Name.java index 0e36990..8110a5b 100644 --- a/module-petowner/src/main/java/domainapp/modules/petowner/types/Name.java +++ b/module-petowner/src/main/java/domainapp/modules/petowner/types/Name.java @@ -8,13 +8,26 @@ import java.lang.annotation.Target; import org.apache.causeway.applib.annotation.Parameter; import org.apache.causeway.applib.annotation.ParameterLayout; import org.apache.causeway.applib.annotation.Property; +import org.apache.causeway.applib.spec.AbstractSpecification; -@Property(maxLength = Name.MAX_LEN) -@Parameter(maxLength = Name.MAX_LEN) +@Property(maxLength = Name.MAX_LEN, mustSatisfy = Name.Spec.class) +@Parameter(maxLength = Name.MAX_LEN, mustSatisfy = Name.Spec.class) @ParameterLayout(named = "Name") @Target({ ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE }) @Retention(RetentionPolicy.RUNTIME) public @interface Name { int MAX_LEN = 40; + String PROHIBITED_CHARACTERS = "&%$!"; + + class Spec extends AbstractSpecification<String> { + @Override public String satisfiesSafely(String candidate) { + for (char prohibitedCharacter : PROHIBITED_CHARACTERS.toCharArray()) { + if( candidate.contains(""+prohibitedCharacter)) { + return "Character '" + prohibitedCharacter + "' is not allowed."; + } + } + return null; + } + } }
