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 d74562e00454414491653c858958305118a8a2d3
Author: Dan Haywood <[email protected]>
AuthorDate: Sun May 26 14:16:45 2024 +0100

    adds validation to check that each owner's pet has a different name
---
 .../java/domainapp/modules/petowner/dom/petowner/PetOwner.java   | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git 
a/module-petowner/src/main/java/domainapp/modules/petowner/dom/petowner/PetOwner.java
 
b/module-petowner/src/main/java/domainapp/modules/petowner/dom/petowner/PetOwner.java
index d0a4fe4..bf4f670 100644
--- 
a/module-petowner/src/main/java/domainapp/modules/petowner/dom/petowner/PetOwner.java
+++ 
b/module-petowner/src/main/java/domainapp/modules/petowner/dom/petowner/PetOwner.java
@@ -4,6 +4,7 @@ import java.time.LocalTime;
 import java.time.ZoneOffset;
 import java.time.temporal.ChronoUnit;
 import java.util.Comparator;
+import java.util.Objects;
 import java.util.Set;
 import java.util.TreeSet;
 
@@ -171,6 +172,14 @@ public class PetOwner implements Comparable<PetOwner>, 
CalendarEventable {
         return this;
     }
 
+    @MemberSupport
+    public String validate0AddPet(final String name) {
+        if (getPets().stream().anyMatch(x -> Objects.equals(x.getName(), 
name))) {
+            return "This owner already has a pet called '" + name + "'";
+        }
+        return null;
+    }
+
     @Action(choicesFrom = "pets")
     @ActionLayout(associateWith = "pets", sequence = "2")
     public PetOwner removePet(@PetName final Pet pet) {

Reply via email to