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/03 21:28:54 UTC

[isis-app-demo] 01/05: adds removePet action mixin for PetOwner

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 cd5b0e87b29a9645920f73758c18d4e4b9c0d56f
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Sun Oct 3 22:18:33 2021 +0100

    adds removePet action mixin for PetOwner
---
 .../pets/dom/petowner/PetOwner_removePet.java      | 38 ++++++++++++++++++++++
 1 file changed, 38 insertions(+)

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_removePet.java
new file mode 100644
index 0000000..b68918d
--- /dev/null
+++ b/module-pets/src/main/java/petclinic/modules/pets/dom/petowner/PetOwner_removePet.java
@@ -0,0 +1,38 @@
+package petclinic.modules.pets.dom.petowner;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import javax.inject.Inject;
+
+import org.apache.isis.applib.annotation.Action;
+import org.apache.isis.applib.annotation.ActionLayout;
+import org.apache.isis.applib.annotation.Publishing;
+import org.apache.isis.applib.annotation.SemanticsOf;
+import org.apache.isis.applib.services.repository.RepositoryService;
+
+import lombok.RequiredArgsConstructor;
+
+import petclinic.modules.pets.types.PetName;
+
+@Action(
+        semantics = SemanticsOf.IDEMPOTENT,
+        commandPublishing = Publishing.ENABLED,
+        executionPublishing = Publishing.ENABLED
+)
+@ActionLayout(associateWith = "pets", sequence = "2")
+@RequiredArgsConstructor
+public class PetOwner_removePet {
+
+    private final PetOwner petOwner;
+
+    public PetOwner act(@PetName final String name) {
+        petRepository.findByPetOwnerAndName(petOwner, name)
+                .ifPresent(pet -> repositoryService.remove(pet));
+        return petOwner;
+    }
+
+    @Inject PetRepository petRepository;
+    @Inject RepositoryService repositoryService;
+}