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/05 12:42:39 UTC

[isis-app-demo] 01/01: refactors removePet to removePets, usiing choicesFrom

This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to tag tags/04-09-optional
in repository https://gitbox.apache.org/repos/asf/isis-app-demo.git

commit a282aad5e8185f765692b29f261dd9a25039b04c
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Tue Oct 5 13:41:34 2021 +0100

    refactors removePet to removePets, usiing choicesFrom
---
 ...Owner_removePet.java => PetOwner_removePets.java} | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)

diff --git a/module-pets/src/main/java/petclinic/modules/pets/dom/petowner/PetOwner_removePet.java b/module-pets/src/main/java/petclinic/modules/pets/dom/petowner/PetOwner_removePets.java
similarity index 62%
rename from module-pets/src/main/java/petclinic/modules/pets/dom/petowner/PetOwner_removePet.java
rename to module-pets/src/main/java/petclinic/modules/pets/dom/petowner/PetOwner_removePets.java
index bba2eac..9ed1710 100644
--- a/module-pets/src/main/java/petclinic/modules/pets/dom/petowner/PetOwner_removePet.java
+++ b/module-pets/src/main/java/petclinic/modules/pets/dom/petowner/PetOwner_removePets.java
@@ -19,32 +19,22 @@ import petclinic.modules.pets.types.PetName;
 @Action(
         semantics = SemanticsOf.IDEMPOTENT,
         commandPublishing = Publishing.ENABLED,
-        executionPublishing = Publishing.ENABLED
+        executionPublishing = Publishing.ENABLED,
+        choicesFrom = "pets"
 )
 @ActionLayout(associateWith = "pets", sequence = "2")
 @RequiredArgsConstructor
-public class PetOwner_removePet {
+public class PetOwner_removePets {
 
     private final PetOwner petOwner;
 
-    public PetOwner act(@PetName final String name) {
-        petRepository.findByPetOwnerAndName(petOwner, name)
-                .ifPresent(pet -> repositoryService.remove(pet));
+    public PetOwner act(final List<Pet> pets) {
+        pets.forEach(repositoryService::remove);
         return petOwner;
     }
     public String disableAct() {
         return petRepository.findByPetOwner(petOwner).isEmpty() ? "No pets" : null;
     }
-    public List<String> choices0Act() {
-        return petRepository.findByPetOwner(petOwner)
-                .stream()
-                .map(Pet::getName)
-                .collect(Collectors.toList());
-    }
-    public String default0Act() {
-        List<String> names = choices0Act();
-        return names.size() == 1 ? names.get(0) : null;
-    }
 
     @Inject PetRepository petRepository;
     @Inject RepositoryService repositoryService;