You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2021/10/02 15:57:38 UTC
[isis-app-demo] 03/03: moves validation logic for lastName from
property to meta-annotation
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/isis-app-demo.git
commit f9767553e32a9dfb745f8f6ca44439eea260797d
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Sat Oct 2 16:56:00 2021 +0100
moves validation logic for lastName from property to meta-annotation
---
.../petclinic/modules/pets/dom/petowner/PetOwner.java | 8 --------
.../main/java/petclinic/modules/pets/types/LastName.java | 16 ++++++++++++++--
2 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/module-pets/src/main/java/petclinic/modules/pets/dom/petowner/PetOwner.java b/module-pets/src/main/java/petclinic/modules/pets/dom/petowner/PetOwner.java
index 6ccb3a9..e794a58 100644
--- a/module-pets/src/main/java/petclinic/modules/pets/dom/petowner/PetOwner.java
+++ b/module-pets/src/main/java/petclinic/modules/pets/dom/petowner/PetOwner.java
@@ -157,14 +157,6 @@ public class PetOwner implements Comparable<PetOwner> {
public String default1UpdateName() {
return getFirstName();
}
- public String validate0UpdateName(String newName) {
- for (char prohibitedCharacter : "&%$!".toCharArray()) {
- if( newName.contains(""+prohibitedCharacter)) {
- return "Character '" + prohibitedCharacter + "' is not allowed.";
- }
- }
- return null;
- }
@Action(semantics = NON_IDEMPOTENT_ARE_YOU_SURE)
diff --git a/module-pets/src/main/java/petclinic/modules/pets/types/LastName.java b/module-pets/src/main/java/petclinic/modules/pets/types/LastName.java
index 0c85796..5fe25bc 100644
--- a/module-pets/src/main/java/petclinic/modules/pets/types/LastName.java
+++ b/module-pets/src/main/java/petclinic/modules/pets/types/LastName.java
@@ -8,13 +8,25 @@ import java.lang.annotation.Target;
import org.apache.isis.applib.annotation.Parameter;
import org.apache.isis.applib.annotation.ParameterLayout;
import org.apache.isis.applib.annotation.Property;
+import org.apache.isis.applib.spec.AbstractSpecification;
-@Property(maxLength = LastName.MAX_LEN)
-@Parameter(maxLength = LastName.MAX_LEN)
+@Property(maxLength = LastName.MAX_LEN, mustSatisfy = LastName.Spec.class)
+@Parameter(maxLength = LastName.MAX_LEN, mustSatisfy = LastName.Spec.class)
@ParameterLayout(named = "Last Name")
@Target({ ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface LastName {
int MAX_LEN = 40;
+
+ class Spec extends AbstractSpecification<String> {
+ @Override public String satisfiesSafely(String candidate) {
+ for (char prohibitedCharacter : "&%$!".toCharArray()) {
+ if( candidate.contains(""+prohibitedCharacter)) {
+ return "Character '" + prohibitedCharacter + "' is not allowed.";
+ }
+ }
+ return null;
+ }
+ }
}