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

danhaywood pushed a commit to branch CAUSEWAY-3361
in repository https://gitbox.apache.org/repos/asf/causeway.git

commit dd9ed9ccc7d7559434783ce0513550a6997a8287
Author: danhaywood <[email protected]>
AuthorDate: Fri Feb 17 09:14:26 2023 +0000

    CAUSEWAY-3361: adds configuration properties to disable audittrail, 
commandlog and executionlog optionally
---
 .../core/config/CausewayConfiguration.java         | 120 ++++++++++++++++++++-
 .../subscriber/CommandSubscriberForCommandLog.java |   4 +
 .../ExecutionSubscriberForExecutionLog.java        |  10 +-
 ...ntityPropertyChangeSubscriberForAuditTrail.java |   6 +-
 4 files changed, 135 insertions(+), 5 deletions(-)

diff --git 
a/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java
 
b/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java
index f37d86a31b..c669ed5533 100644
--- 
a/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java
+++ 
b/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java
@@ -75,8 +75,6 @@ import org.apache.causeway.applib.services.userui.UserMenu;
 import 
org.apache.causeway.applib.value.semantics.TemporalValueSemantics.TemporalEditingPattern;
 import org.apache.causeway.commons.internal.base._NullSafe;
 import org.apache.causeway.commons.internal.context._Context;
-import org.apache.causeway.core.config.CausewayConfiguration.Core;
-import org.apache.causeway.core.config.CausewayConfiguration.Viewer;
 import org.apache.causeway.core.config.metamodel.facets.ActionConfigOptions;
 import 
org.apache.causeway.core.config.metamodel.facets.CollectionLayoutConfigOptions;
 import 
org.apache.causeway.core.config.metamodel.facets.DomainObjectConfigOptions;
@@ -2860,10 +2858,87 @@ public class CausewayConfiguration {
     @Data
     public static class Extensions {
 
+        private final AuditTrail auditTrail = new AuditTrail();
+        @Data
+        public static class AuditTrail {
+
+            /**
+             * As per {@link AuditTrail#getPersist()}.
+             *
+             * <p>
+             *     Implementation note: we use an enum here (rather than a 
simple boolean) to allow for future
+             *     enhancements.
+             * </p>
+             */
+            public enum PersistPolicy {
+                /**
+                 * Persist to the audit trail.  This is the default.
+                 */
+                ENABLED,
+                /**
+                 * Do <i>NOT</i> persist to the audit trail.
+                 *
+                 * <p>
+                 *     One reason to use this option is if you wish to provide 
your own implementation that wraps
+                 *     or delegates to the default implementation of {@link 
EntityPropertyChangeSubscriber} that is
+                 *     provided by the <i>audittrail</i> extension.  Because 
entity property changes are published to
+                 *     <i>all</i> subscribers on the class path, you can 
disable the default implementation from
+                 *     doing anything using this setting.
+                 * </p>
+                 */
+                DISABLED;
+
+                public boolean isDisabled() { return this == DISABLED; }
+            }
+
+            /**
+             * Whether the {@link EntityPropertyChangeSubscriber} 
implementation provided by this extension (which
+             * persists property changes to the audit trail) is enabled or not.
+             */
+            @Getter @Setter
+            private PersistPolicy persist = PersistPolicy.ENABLED;
+        }
+
         private final CommandLog commandLog = new CommandLog();
         @Data
         public static class CommandLog {
 
+            /**
+             * As per {@link CommandLog#getPersist()}.
+             *
+             * <p>
+             *     Implementation note: we use an enum here (rather than a 
simple boolean) to allow for future
+             *     enhancements.
+             * </p>
+             */
+            public enum PersistPolicy {
+                /**
+                 * Persist to the command log .  This is the default.
+                 */
+                ENABLED,
+                /**
+                 * Do <i>NOT</i> persist to the audit trail.
+                 *
+                 * <p>
+                 *     One reason to use this option is if you wish to provide 
your own implementation that wraps
+                 *     or delegates to the default implementation of {@link 
org.apache.causeway.applib.services.publishing.spi.CommandSubscriber} that is
+                 *     provided by the <i>commandlog</i> extension.  Because 
commands are published to
+                 *     <i>all</i> subscribers on the class path, you can 
disable the default implementation from
+                 *     doing anything using this setting.
+                 * </p>
+                 */
+                DISABLED;
+
+                public boolean isDisabled() { return this == DISABLED; }
+            }
+
+            /**
+             * Whether the {@link 
org.apache.causeway.applib.services.publishing.spi.CommandSubscriber} 
implementation
+             * provided by this extension (which persists commands to the 
command log) is enabled or not.
+             */
+            @Getter @Setter
+            private PersistPolicy persist = PersistPolicy.ENABLED;
+
             public enum PublishPolicy {
                 ALWAYS,
                 ONLY_IF_SYSTEM_CHANGED,
@@ -3064,6 +3139,47 @@ public class CausewayConfiguration {
 
         }
 
+        private final ExecutionLog executionLog = new ExecutionLog();
+        @Data
+        public static class ExecutionLog {
+
+            /**
+             * As per {@link ExecutionLog#getPersist()}.
+             *
+             * <p>
+             *     Implementation note: we use an enum here (rather than a 
simple boolean) to allow for future
+             *     enhancements.
+             * </p>
+             */
+            public enum PersistPolicy {
+                /**
+                 * Persist to the audit trail.  This is the default.
+                 */
+                ENABLED,
+                /**
+                 * Do <i>NOT</i> persist to the audit trail.
+                 *
+                 * <p>
+                 *     One reason to use this option is if you wish to provide 
your own implementation that wraps
+                 *     or delegates to the default implementation of {@link 
org.apache.causeway.applib.services.publishing.spi.ExecutionSubscriber} that is
+                 *     provided by the <i>executionLog</i> extension.  Because 
executions are published to
+                 *     <i>all</i> subscribers on the class path, you can 
disable the default implementation from
+                 *     doing anything using this setting.
+                 * </p>
+                 */
+                DISABLED;
+
+                public boolean isDisabled() { return this == DISABLED; }
+            }
+
+            /**
+             * Whether the {@link EntityPropertyChangeSubscriber} 
implementation provided by this extension (which
+             * persists property changes to the audit trail) is enabled or not.
+             */
+            @Getter @Setter
+            private PersistPolicy persist = PersistPolicy.ENABLED;
+        }
+
         private final ExecutionOutbox executionOutbox = new ExecutionOutbox();
         @Valid
         @Data
diff --git 
a/extensions/core/commandlog/applib/src/main/java/org/apache/causeway/extensions/commandlog/applib/subscriber/CommandSubscriberForCommandLog.java
 
b/extensions/core/commandlog/applib/src/main/java/org/apache/causeway/extensions/commandlog/applib/subscriber/CommandSubscriberForCommandLog.java
index 1d9650109b..cb5df8a42a 100644
--- 
a/extensions/core/commandlog/applib/src/main/java/org/apache/causeway/extensions/commandlog/applib/subscriber/CommandSubscriberForCommandLog.java
+++ 
b/extensions/core/commandlog/applib/src/main/java/org/apache/causeway/extensions/commandlog/applib/subscriber/CommandSubscriberForCommandLog.java
@@ -57,6 +57,10 @@ public class CommandSubscriberForCommandLog implements 
CommandSubscriber {
     @Override
     public void onCompleted(final Command command) {
 
+        if 
(causewayConfiguration.getExtensions().getCommandLog().getPersist().isDisabled())
 {
+            return;
+        }
+
         // skip if no changes AND skipping is allowed
         if 
(causewayConfiguration.getExtensions().getCommandLog().getPublishPolicy().isOnlyIfSystemChanged()
                 && !command.isSystemStateChanged()) {
diff --git 
a/extensions/core/executionlog/applib/src/main/java/org/apache/causeway/extensions/executionlog/applib/spiimpl/ExecutionSubscriberForExecutionLog.java
 
b/extensions/core/executionlog/applib/src/main/java/org/apache/causeway/extensions/executionlog/applib/spiimpl/ExecutionSubscriberForExecutionLog.java
index eaf919dbca..5db13b43dc 100644
--- 
a/extensions/core/executionlog/applib/src/main/java/org/apache/causeway/extensions/executionlog/applib/spiimpl/ExecutionSubscriberForExecutionLog.java
+++ 
b/extensions/core/executionlog/applib/src/main/java/org/apache/causeway/extensions/executionlog/applib/spiimpl/ExecutionSubscriberForExecutionLog.java
@@ -20,6 +20,7 @@ package 
org.apache.causeway.extensions.executionlog.applib.spiimpl;
 
 import javax.inject.Inject;
 
+import org.apache.causeway.core.config.CausewayConfiguration;
 import org.springframework.stereotype.Service;
 
 import org.apache.causeway.applib.services.iactn.Execution;
@@ -32,13 +33,18 @@ import lombok.RequiredArgsConstructor;
  * @since 2.0 {@index}
  */
 @Service
-@RequiredArgsConstructor
+@RequiredArgsConstructor(onConstructor_ = {@Inject})
 public class ExecutionSubscriberForExecutionLog implements ExecutionSubscriber 
{
 
-    final @Inject ExecutionLogEntryRepository repository;
+    final ExecutionLogEntryRepository repository;
+    final CausewayConfiguration causewayConfiguration;
 
     @Override
     public void onExecution(Execution<?, ?> execution) {
+        if 
(causewayConfiguration.getExtensions().getExecutionLog().getPersist().isDisabled())
 {
+            return;
+        }
+
         repository.createEntryAndPersist(execution);
     }
 
diff --git 
a/extensions/security/audittrail/applib/src/main/java/org/apache/causeway/extensions/audittrail/applib/spiimpl/EntityPropertyChangeSubscriberForAuditTrail.java
 
b/extensions/security/audittrail/applib/src/main/java/org/apache/causeway/extensions/audittrail/applib/spiimpl/EntityPropertyChangeSubscriberForAuditTrail.java
index 578477fca0..f8483560f6 100644
--- 
a/extensions/security/audittrail/applib/src/main/java/org/apache/causeway/extensions/audittrail/applib/spiimpl/EntityPropertyChangeSubscriberForAuditTrail.java
+++ 
b/extensions/security/audittrail/applib/src/main/java/org/apache/causeway/extensions/audittrail/applib/spiimpl/EntityPropertyChangeSubscriberForAuditTrail.java
@@ -24,6 +24,7 @@ import javax.annotation.Priority;
 import javax.inject.Inject;
 import javax.inject.Named;
 
+import org.apache.causeway.core.config.CausewayConfiguration;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.stereotype.Service;
 
@@ -57,11 +58,14 @@ public class EntityPropertyChangeSubscriberForAuditTrail 
implements EntityProper
 
     final TransactionService transactionService;
     final AuditTrailEntryRepository<? extends AuditTrailEntry> 
auditTrailEntryRepository;
+    final CausewayConfiguration causewayConfiguration;
 
     @Override
     public void onChanging(EntityPropertyChange entityPropertyChange) {
+        if 
(causewayConfiguration.getExtensions().getAuditTrail().getPersist().isDisabled())
 {
+            return;
+        }
         auditTrailEntryRepository.createFor(entityPropertyChange);
-
     }
 
     @Override

Reply via email to