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 13:33:24 UTC

[isis-app-demo] 04/05: refactors PetOwner delete action to a mixin, and deletes associated Pets

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

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

commit 415e608fe0b4ca470541b77651f3e81eca72a69c
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Tue Oct 5 14:30:32 2021 +0100

    refactors PetOwner delete action to a mixin, and deletes associated Pets
    
    Also:
    - fixes the "associateWith",
    - adds a "name" to the fieldset in layout.xml so that there is a titled panel for the  "delete" action's button to appear in.
    - deletes a defunct unit test
---
 .../modules/pets/dom/petowner/PetOwner_Test.java   | 20 -----------
 .../modules/pets/dom/petowner/PetOwner.java        | 12 -------
 .../modules/pets/dom/petowner/PetOwner.layout.xml  |  2 +-
 .../modules/pets/dom/petowner/PetOwner_delete.java | 40 ++++++++++++++++++++++
 4 files changed, 41 insertions(+), 33 deletions(-)

diff --git a/module-pets-tests/src/test/java/petclinic/modules/pets/dom/petowner/PetOwner_Test.java b/module-pets-tests/src/test/java/petclinic/modules/pets/dom/petowner/PetOwner_Test.java
index a153ab0..0ea697a 100644
--- a/module-pets-tests/src/test/java/petclinic/modules/pets/dom/petowner/PetOwner_Test.java
+++ b/module-pets-tests/src/test/java/petclinic/modules/pets/dom/petowner/PetOwner_Test.java
@@ -48,24 +48,4 @@ class PetOwner_Test {
         }
 
     }
-    @Nested
-    class delete {
-
-        @Test
-        void happy_case() throws Exception {
-
-            // given
-            assertThat(object).isNotNull();
-
-            // expecting
-            when(mockTitleService.titleOf(object)).thenReturn("Foo");
-
-            // when
-            object.delete();
-
-            // then
-            verify(mockMessageService).informUser("'Foo' deleted");
-            verify(mockRepositoryService).removeAndFlush(object);
-        }
-    }
 }
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 02a3561..0f16c8e 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
@@ -32,7 +32,6 @@ import org.apache.isis.applib.services.title.TitleService;
 import org.apache.isis.persistence.jpa.applib.integration.IsisEntityListener;
 
 import static org.apache.isis.applib.annotation.SemanticsOf.IDEMPOTENT;
-import static org.apache.isis.applib.annotation.SemanticsOf.NON_IDEMPOTENT_ARE_YOU_SURE;
 
 import lombok.AccessLevel;
 import lombok.Getter;
@@ -162,17 +161,6 @@ public class PetOwner implements Comparable<PetOwner> {
     }
 
 
-    @Action(semantics = NON_IDEMPOTENT_ARE_YOU_SURE)
-    @ActionLayout(
-            associateWith = "lastName", position = ActionLayout.Position.PANEL,
-            describedAs = "Deletes this object from the persistent datastore")
-    public void delete() {
-        final String title = titleService.titleOf(this);
-        messageService.informUser(String.format("'%s' deleted", title));
-        repositoryService.removeAndFlush(this);
-    }
-
-
 
     private final static Comparator<PetOwner> comparator =
             Comparator.comparing(PetOwner::getLastName);
diff --git a/module-pets/src/main/java/petclinic/modules/pets/dom/petowner/PetOwner.layout.xml b/module-pets/src/main/java/petclinic/modules/pets/dom/petowner/PetOwner.layout.xml
index 3dcd362..4217922 100644
--- a/module-pets/src/main/java/petclinic/modules/pets/dom/petowner/PetOwner.layout.xml
+++ b/module-pets/src/main/java/petclinic/modules/pets/dom/petowner/PetOwner.layout.xml
@@ -12,7 +12,7 @@
                 <bs3:tab name="General">
                     <bs3:row>
                         <bs3:col span="12">
-                            <c:fieldSet id="name"/>
+                            <c:fieldSet id="name" name="Name"/>
                         </bs3:col>
                     </bs3:row>
                 </bs3:tab>
diff --git a/module-pets/src/main/java/petclinic/modules/pets/dom/petowner/PetOwner_delete.java b/module-pets/src/main/java/petclinic/modules/pets/dom/petowner/PetOwner_delete.java
new file mode 100644
index 0000000..c7bb58a
--- /dev/null
+++ b/module-pets/src/main/java/petclinic/modules/pets/dom/petowner/PetOwner_delete.java
@@ -0,0 +1,40 @@
+package petclinic.modules.pets.dom.petowner;
+
+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 org.apache.isis.applib.services.xactn.TransactionService;
+
+import lombok.RequiredArgsConstructor;
+
+import petclinic.modules.pets.dom.pet.PetRepository;
+
+@Action(
+        semantics = SemanticsOf.NON_IDEMPOTENT_ARE_YOU_SURE,
+        commandPublishing = Publishing.ENABLED,
+        executionPublishing = Publishing.ENABLED
+)
+@ActionLayout(
+        associateWith = "name", position = ActionLayout.Position.PANEL,
+        describedAs = "Deletes this object from the persistent datastore")
+@RequiredArgsConstructor
+public class PetOwner_delete {
+
+    private final PetOwner petOwner;
+
+    public void act(
+            ) {
+        petRepository.findByPetOwner(petOwner).forEach(repositoryService::remove);
+        transactionService.flushTransaction();
+        repositoryService.remove(petOwner);
+        return;
+    }
+
+    @Inject PetRepository petRepository;
+    @Inject RepositoryService repositoryService;
+    @Inject TransactionService transactionService;
+}