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 2017/09/18 09:06:33 UTC

isis git commit: ISIS-1719: fires events while installing fixtures

Repository: isis
Updated Branches:
  refs/heads/master 81a7a462a -> bf056704a


ISIS-1719: fires events while installing fixtures

(for QueryResultsCache to listen to).


Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/bf056704
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/bf056704
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/bf056704

Branch: refs/heads/master
Commit: bf056704a3b4d839887750a2a6073db76ad741dc
Parents: 81a7a46
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Mon Sep 18 08:59:24 2017 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Mon Sep 18 10:06:24 2017 +0100

----------------------------------------------------------------------
 .../guides/rgcfg/_rgcfg_configuring-core.adoc   | 39 ++++++++++++++++++--
 .../fixtures/FixturesInstallerAbstract.java     |  3 +-
 .../fixtures/FixturesInstallerDelegate.java     | 38 +++++++++++++------
 3 files changed, 62 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/bf056704/adocs/documentation/src/main/asciidoc/guides/rgcfg/_rgcfg_configuring-core.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/guides/rgcfg/_rgcfg_configuring-core.adoc b/adocs/documentation/src/main/asciidoc/guides/rgcfg/_rgcfg_configuring-core.adoc
index 2a9bf6b..3e85c30 100644
--- a/adocs/documentation/src/main/asciidoc/guides/rgcfg/_rgcfg_configuring-core.adoc
+++ b/adocs/documentation/src/main/asciidoc/guides/rgcfg/_rgcfg_configuring-core.adoc
@@ -168,6 +168,33 @@ Configuration properties for the JDO/DataNucleus objectstore can be found in the
 
 
 
+[[__rgcfg_configuring-core_fixture-events]]
+== Fixture Events
+
+(As of `1.15.1-SNAPSHOT`), events are fired to indicate the start and end of fixtures are being installed.
+This are listened to by the xref:rgsvc.adoc#_rgsvc_persistence-layer-api_QueryResultsCache[`QueryResultsCache`] to disable caching during this period.
+
+.Core Configuration Properties for Fixture Events
+[cols="2a,1,3a", options="header"]
+|===
+|Property
+|Value +
+(default value)
+|Description
+
+
+|`isis.fixtures.fireEvents`
+|`true`,`false` +
+(`true`)
+|(As of `1.15.1-SNAPSHOT`), whether fixture `FixturesInstallingEvent` and `FixturesInstalledEvent` events should be posted while the system is bootstrapping.
+
+
+
+|===
+
+
+
+
 [[__rgcfg_configuring-core_services]]
 == Services
 
@@ -726,21 +753,25 @@ See xref:../ugbtb/ugbtb.adoc#_ugbtb_programming-model_layout-metadata-reader[Lay
 
 The framework provides the `isis.reflector.facet.filterVisibility` configuration property that influences whether a returned object is visible to the end-user:
 
-* Action invocations: +
+* Action invocations:
 
++
 If an action returns a collection that includes the object, then the object will be excluded from the list when rendered.
 If it returns a single object and the user does not have access to that object, then the action will seemingly return `null`
 
-* Collections: +
+* Collections:
 
++
 If a parent object has a collection references another object to which the user does not have access, then (as for actions) the object will not be rendered in the list
 
-* Properties: +
+* Properties:
 
++
 If an parent object has a (scalar) reference some other object to which the user does not have access, then the reference will be rendered as empty.
 
-* Choices and autoComplete lists: +
+* Choices and autoComplete lists:
 
++
 If an object is returned in a list of choices or within an auto-complete list, and the user does not have access, then it is excluded from the rendered list.
 
 The original motivation for this feature was to transparently support such features as multi-tenancy (as per the (non-ASF) http://github.com/isisaddons/isis-module-security[Isis addons' security] module).

http://git-wip-us.apache.org/repos/asf/isis/blob/bf056704/core/runtime/src/main/java/org/apache/isis/core/runtime/fixtures/FixturesInstallerAbstract.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/fixtures/FixturesInstallerAbstract.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/fixtures/FixturesInstallerAbstract.java
index 2765bbe..15c8c8d 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/fixtures/FixturesInstallerAbstract.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/fixtures/FixturesInstallerAbstract.java
@@ -31,8 +31,7 @@ public abstract class FixturesInstallerAbstract {
     private final FixturesInstallerDelegate delegate;
     protected final IsisConfiguration configuration;
 
-    public FixturesInstallerAbstract(
-            final IsisSessionFactory isisSessionFactory) {
+    public FixturesInstallerAbstract(final IsisSessionFactory isisSessionFactory) {
         delegate = new FixturesInstallerDelegate(isisSessionFactory);
         configuration = isisSessionFactory.getConfiguration();
     }

http://git-wip-us.apache.org/repos/asf/isis/blob/bf056704/core/runtime/src/main/java/org/apache/isis/core/runtime/fixtures/FixturesInstallerDelegate.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/fixtures/FixturesInstallerDelegate.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/fixtures/FixturesInstallerDelegate.java
index 3065591..8ef8aba 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/fixtures/FixturesInstallerDelegate.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/fixtures/FixturesInstallerDelegate.java
@@ -27,11 +27,14 @@ import com.google.common.collect.Lists;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import org.apache.isis.applib.events.system.FixturesInstalledEvent;
+import org.apache.isis.applib.events.system.FixturesInstallingEvent;
 import org.apache.isis.applib.fixtures.CompositeFixture;
 import org.apache.isis.applib.fixtures.FixtureType;
 import org.apache.isis.applib.fixtures.InstallableFixture;
 import org.apache.isis.applib.fixtures.LogonFixture;
-import org.apache.isis.applib.fixtures.switchuser.SwitchUserService;
+import org.apache.isis.applib.services.eventbus.EventBusService;
+import org.apache.isis.core.commons.config.IsisConfiguration;
 import org.apache.isis.core.commons.lang.ObjectExtensions;
 import org.apache.isis.core.metamodel.services.ServicesInjector;
 import org.apache.isis.core.runtime.system.DeploymentType;
@@ -39,7 +42,6 @@ import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
 import org.apache.isis.core.runtime.system.session.IsisSessionFactory;
 import org.apache.isis.core.runtime.system.transaction.IsisTransactionManager;
 
-// REVIEW: could probably inline
 public class FixturesInstallerDelegate {
 
     private static final Logger LOG = LoggerFactory.getLogger(FixturesInstallerDelegate.class);
@@ -47,17 +49,12 @@ public class FixturesInstallerDelegate {
     //region > Constructor, fields
 
     private final IsisSessionFactory isisSessionFactory;
-    private final SwitchUserService switchUserService;
 
-    //endregion
     public FixturesInstallerDelegate(final IsisSessionFactory isisSessionFactory) {
         this.isisSessionFactory = isisSessionFactory;
-        switchUserService = isisSessionFactory.getServicesInjector().lookupService(SwitchUserService.class);
     }
 
-    //region > addFixture, getFixtures
-
-    protected final List<Object> fixtures = Lists.newArrayList();
+    private final List<Object> fixtures = Lists.newArrayList();
 
     /**
      * Automatically flattens any {@link List}s, recursively (depth-first) if
@@ -95,10 +92,25 @@ public class FixturesInstallerDelegate {
      * {@link org.apache.isis.core.runtime.fixtures.FixturesInstallerAbstract} to be
      * reused across multiple tests (REVIEW: does that make sense?)
      */
-    public final void installFixtures() {
-        installFixtures(getFixtures());
+    public void installFixtures() {
+        final IsisConfiguration configuration = getConfiguration();
+        final boolean fireEvents = configuration.getBoolean("isis.fixtures.fireEvents", true);
+        final EventBusService eventBusService = getEventBusService();
+        try {
+            if(fireEvents) {
+                eventBusService.post(new FixturesInstallingEvent(this));
+            }
+            installFixtures(Collections.unmodifiableList(fixtures));
+        } finally {
+            if(fireEvents) {
+                eventBusService.post(new FixturesInstalledEvent(this));
+            }
+        }
     }
 
+    private IsisConfiguration getConfiguration() {
+        return isisSessionFactory.getServicesInjector().lookupService(IsisConfiguration.class);
+    }
 
     private void installFixtures(final List<Object> fixtures) {
         for (final Object fixture : fixtures) {
@@ -189,7 +201,7 @@ public class FixturesInstallerDelegate {
      * <p>
      * Used to automatically logon if in {@link DeploymentType#SERVER_PROTOTYPE} mode.
      */
-    public LogonFixture getLogonFixture() {
+    LogonFixture getLogonFixture() {
         return logonFixture;
     }
 
@@ -202,7 +214,6 @@ public class FixturesInstallerDelegate {
         }
     }
 
-
     //endregion
 
     //region > dependencies (derived)
@@ -211,6 +222,9 @@ public class FixturesInstallerDelegate {
         return isisSessionFactory.getServicesInjector();
     }
 
+    private EventBusService getEventBusService() {
+        return getServicesInjector().lookupService(EventBusService.class);
+    }
 
     private PersistenceSession getPersistenceSession() {
         return isisSessionFactory.getCurrentSession().getPersistenceSession();