You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2021/05/12 06:54:38 UTC

[isis] branch master updated: ISIS-2620: Demo: add EventLogJpa variant

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

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new f1f81c9  ISIS-2620: Demo: add EventLogJpa variant
f1f81c9 is described below

commit f1f81c90819092087898f4106c801b8514d99118
Author: Andi Huber <ah...@apache.org>
AuthorDate: Wed May 12 08:54:23 2021 +0200

    ISIS-2620: Demo: add EventLogJpa variant
---
 .../objects/other/embedded/EmbeddedTypeMenu.java   |  3 +
 .../EventLogEntryJdoRepository.java                | 12 +++-
 .../core/eventbusservice/EventLogEntryJpa.java     | 80 ++++++++++++++++++++++
 ...sitory.java => EventLogEntryJpaRepository.java} | 20 ++++--
 ...epository.java => EventLogEntryRepository.java} | 27 +++-----
 .../EventSubscriberDemoImplementation.java         |  6 +-
 6 files changed, 120 insertions(+), 28 deletions(-)

diff --git a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/other/embedded/EmbeddedTypeMenu.java b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/other/embedded/EmbeddedTypeMenu.java
index 460f141..4b153cf 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/other/embedded/EmbeddedTypeMenu.java
+++ b/examples/demo/domain/src/main/java/demoapp/dom/domain/objects/other/embedded/EmbeddedTypeMenu.java
@@ -18,6 +18,8 @@
  */
 package demoapp.dom.domain.objects.other.embedded;
 
+import org.springframework.context.annotation.Profile;
+
 import org.apache.isis.applib.annotation.Action;
 import org.apache.isis.applib.annotation.ActionLayout;
 import org.apache.isis.applib.annotation.DomainService;
@@ -26,6 +28,7 @@ import org.apache.isis.applib.services.factory.FactoryService;
 
 import lombok.RequiredArgsConstructor;
 
+@Profile("demo-jdo")
 @DomainService(nature=NatureOfService.VIEW, objectType = "demo.EmbeddedTypeMenu")
 @RequiredArgsConstructor
 public class EmbeddedTypeMenu {
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/services/core/eventbusservice/EventLogEntryJdoRepository.java b/examples/demo/domain/src/main/java/demoapp/dom/services/core/eventbusservice/EventLogEntryJdoRepository.java
index e922223..412fcd6 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/services/core/eventbusservice/EventLogEntryJdoRepository.java
+++ b/examples/demo/domain/src/main/java/demoapp/dom/services/core/eventbusservice/EventLogEntryJdoRepository.java
@@ -30,20 +30,30 @@ import org.apache.isis.applib.services.repository.RepositoryService;
 
 import lombok.RequiredArgsConstructor;
 
+import demoapp.dom.services.core.eventbusservice.EventBusServiceDemoVm.UiButtonEvent;
+
 @Profile("demo-jdo")
 @Repository
 @Named("demo.eventLogRepository")
 @RequiredArgsConstructor(onConstructor_ = { @Inject })
-public class EventLogEntryJdoRepository {
+public class EventLogEntryJdoRepository
+implements EventLogEntryRepository<EventLogEntryJdo> {
 
     final RepositoryService repositoryService;
 
+    @Override
     public List<EventLogEntryJdo> listAll(){
         return repositoryService.allInstances(EventLogEntryJdo.class);
     }
 
+    @Override
     public void add(EventLogEntryJdo entry) {
         repositoryService.persist(entry);
     }
 
+    @Override
+    public EventLogEntryJdo newEntityFor(UiButtonEvent event) {
+        return EventLogEntryJdo.of(event);
+    }
+
 }
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/services/core/eventbusservice/EventLogEntryJpa.java b/examples/demo/domain/src/main/java/demoapp/dom/services/core/eventbusservice/EventLogEntryJpa.java
new file mode 100644
index 0000000..ce9777d
--- /dev/null
+++ b/examples/demo/domain/src/main/java/demoapp/dom/services/core/eventbusservice/EventLogEntryJpa.java
@@ -0,0 +1,80 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package demoapp.dom.services.core.eventbusservice;
+
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+
+import javax.persistence.Entity;
+
+import org.springframework.context.annotation.Profile;
+
+import org.apache.isis.applib.annotation.Action;
+import org.apache.isis.applib.annotation.DomainObject;
+import org.apache.isis.applib.annotation.Editing;
+import org.apache.isis.applib.annotation.Property;
+
+import lombok.Getter;
+import lombok.Setter;
+import lombok.val;
+
+import demoapp.dom.services.core.eventbusservice.EventBusServiceDemoVm.UiButtonEvent;
+
+@Profile("demo-jpa")
+@Entity
+@DomainObject
+public class EventLogEntryJpa {
+
+    public static EventLogEntryJpa of(UiButtonEvent even) {
+        val x = new EventLogEntryJpa();
+        x.setEvent("Button clicked " + LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_TIME));
+        return x;
+    }
+
+    public String title() {
+        return getEvent();
+    }
+
+    @javax.persistence.Column(nullable = true)
+    @Property(editing = Editing.DISABLED)
+    @Getter @Setter
+    private String event;
+
+    // demonstrating 2 methods of changing a property ...
+    // - inline edit
+    // - via action
+
+    public static enum Acknowledge {
+        IGNORE,
+        CRITICAL
+    }
+
+    @javax.persistence.Column(nullable = true)
+    @Property(editing = Editing.ENABLED)
+    @Getter @Setter
+    private Acknowledge acknowledge;
+
+    @Action(associateWith = "acknowledge")
+    public EventLogEntryJpa acknowledge(Acknowledge acknowledge) {
+        setAcknowledge(acknowledge);
+        return this;
+    }
+
+
+}
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/services/core/eventbusservice/EventLogEntryJdoRepository.java b/examples/demo/domain/src/main/java/demoapp/dom/services/core/eventbusservice/EventLogEntryJpaRepository.java
similarity index 72%
copy from examples/demo/domain/src/main/java/demoapp/dom/services/core/eventbusservice/EventLogEntryJdoRepository.java
copy to examples/demo/domain/src/main/java/demoapp/dom/services/core/eventbusservice/EventLogEntryJpaRepository.java
index e922223..e7330ca 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/services/core/eventbusservice/EventLogEntryJdoRepository.java
+++ b/examples/demo/domain/src/main/java/demoapp/dom/services/core/eventbusservice/EventLogEntryJpaRepository.java
@@ -30,20 +30,30 @@ import org.apache.isis.applib.services.repository.RepositoryService;
 
 import lombok.RequiredArgsConstructor;
 
-@Profile("demo-jdo")
+import demoapp.dom.services.core.eventbusservice.EventBusServiceDemoVm.UiButtonEvent;
+
+@Profile("demo-jpa")
 @Repository
 @Named("demo.eventLogRepository")
 @RequiredArgsConstructor(onConstructor_ = { @Inject })
-public class EventLogEntryJdoRepository {
+public class EventLogEntryJpaRepository
+implements EventLogEntryRepository<EventLogEntryJpa> {
 
     final RepositoryService repositoryService;
 
-    public List<EventLogEntryJdo> listAll(){
-        return repositoryService.allInstances(EventLogEntryJdo.class);
+    @Override
+    public List<EventLogEntryJpa> listAll(){
+        return repositoryService.allInstances(EventLogEntryJpa.class);
     }
 
-    public void add(EventLogEntryJdo entry) {
+    @Override
+    public void add(EventLogEntryJpa entry) {
         repositoryService.persist(entry);
     }
 
+    @Override
+    public EventLogEntryJpa newEntityFor(UiButtonEvent event) {
+        return EventLogEntryJpa.of(event);
+    }
+
 }
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/services/core/eventbusservice/EventLogEntryJdoRepository.java b/examples/demo/domain/src/main/java/demoapp/dom/services/core/eventbusservice/EventLogEntryRepository.java
similarity index 57%
copy from examples/demo/domain/src/main/java/demoapp/dom/services/core/eventbusservice/EventLogEntryJdoRepository.java
copy to examples/demo/domain/src/main/java/demoapp/dom/services/core/eventbusservice/EventLogEntryRepository.java
index e922223..864d7df 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/services/core/eventbusservice/EventLogEntryJdoRepository.java
+++ b/examples/demo/domain/src/main/java/demoapp/dom/services/core/eventbusservice/EventLogEntryRepository.java
@@ -20,30 +20,21 @@ package demoapp.dom.services.core.eventbusservice;
 
 import java.util.List;
 
-import javax.inject.Inject;
-import javax.inject.Named;
+import lombok.val;
 
-import org.springframework.context.annotation.Profile;
-import org.springframework.stereotype.Repository;
+import demoapp.dom.services.core.eventbusservice.EventBusServiceDemoVm.UiButtonEvent;
 
-import org.apache.isis.applib.services.repository.RepositoryService;
+public interface EventLogEntryRepository<T> {
 
-import lombok.RequiredArgsConstructor;
+    List<T> listAll();
 
-@Profile("demo-jdo")
-@Repository
-@Named("demo.eventLogRepository")
-@RequiredArgsConstructor(onConstructor_ = { @Inject })
-public class EventLogEntryJdoRepository {
+    void add(T entry);
 
-    final RepositoryService repositoryService;
+    T newEntityFor(UiButtonEvent event);
 
-    public List<EventLogEntryJdo> listAll(){
-        return repositoryService.allInstances(EventLogEntryJdo.class);
-    }
-
-    public void add(EventLogEntryJdo entry) {
-        repositoryService.persist(entry);
+    default void storeEvent(UiButtonEvent event) {
+        val entry = newEntityFor(event);
+        add(entry);
     }
 
 }
diff --git a/examples/demo/domain/src/main/java/demoapp/dom/services/core/eventbusservice/EventSubscriberDemoImplementation.java b/examples/demo/domain/src/main/java/demoapp/dom/services/core/eventbusservice/EventSubscriberDemoImplementation.java
index c8a92b8..26bc69a 100644
--- a/examples/demo/domain/src/main/java/demoapp/dom/services/core/eventbusservice/EventSubscriberDemoImplementation.java
+++ b/examples/demo/domain/src/main/java/demoapp/dom/services/core/eventbusservice/EventSubscriberDemoImplementation.java
@@ -66,14 +66,12 @@ public class EventSubscriberDemoImplementation {
             objectType = "demo.eventLogWriter")
     public static class EventLogWriter {
 
-        @Inject private EventLogEntryJdoRepository eventLogEntryJdoRepository;
+        @Inject private EventLogEntryRepository<? extends Object> eventLogEntryRepository;
 
         @Action // called asynchronously by above invocation
         public void storeEvent(UiButtonEvent event) {
 
-            val entry = EventLogEntryJdo.of(event);
-            eventLogEntryJdoRepository.add(entry);
-
+            eventLogEntryRepository.storeEvent(event);
         }
 
     }