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

arnold pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract.git


The following commit(s) were added to refs/heads/develop by this push:
     new ee1f988be Enable/Disable Messaging in Read Only instance mode
ee1f988be is described below

commit ee1f988be6c6fbd33c156e45549e97a25b449012
Author: Jose Alberto Hernandez <[email protected]>
AuthorDate: Sat May 28 15:43:08 2022 -0500

    Enable/Disable Messaging in Read Only instance mode
---
 .../core/config/EnableFineractEventsCondition.java | 38 ++++++++++++++++++++++
 .../config/MessagingConfiguration.java             |  3 ++
 .../ActiveMQNotificationEventListener.java         |  3 ++
 .../ActiveMQNotificationEventPublisher.java        |  3 ++
 4 files changed, 47 insertions(+)

diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/EnableFineractEventsCondition.java
 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/EnableFineractEventsCondition.java
new file mode 100644
index 000000000..1c3f6710d
--- /dev/null
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/config/EnableFineractEventsCondition.java
@@ -0,0 +1,38 @@
+/**
+ * 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 org.apache.fineract.infrastructure.core.config;
+
+import java.util.Optional;
+import org.springframework.context.annotation.Condition;
+import org.springframework.context.annotation.ConditionContext;
+import org.springframework.core.type.AnnotatedTypeMetadata;
+
+public class EnableFineractEventsCondition implements Condition {
+
+    @Override
+    public boolean matches(ConditionContext context, AnnotatedTypeMetadata 
metadata) {
+        boolean isReadModeEnabled = 
Optional.ofNullable(context.getEnvironment().getProperty("fineract.mode.read-enabled",
 Boolean.class))
+                .orElse(true);
+        boolean isWriteModeEnabled = 
Optional.ofNullable(context.getEnvironment().getProperty("fineract.mode.write-enabled",
 Boolean.class))
+                .orElse(true);
+        boolean isBatchModeEnabled = 
Optional.ofNullable(context.getEnvironment().getProperty("fineract.mode.batch-enabled",
 Boolean.class))
+                .orElse(true);
+        return !isReadModeEnabled && (isWriteModeEnabled || 
isBatchModeEnabled);
+    }
+}
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/notification/config/MessagingConfiguration.java
 
b/fineract-provider/src/main/java/org/apache/fineract/notification/config/MessagingConfiguration.java
index bf26aea5b..f67f60e95 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/notification/config/MessagingConfiguration.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/notification/config/MessagingConfiguration.java
@@ -21,11 +21,13 @@ package org.apache.fineract.notification.config;
 import javax.jms.ExceptionListener;
 import javax.jms.JMSException;
 import org.apache.activemq.ActiveMQConnectionFactory;
+import 
org.apache.fineract.infrastructure.core.config.EnableFineractEventsCondition;
 import 
org.apache.fineract.notification.eventandlistener.NotificationEventListener;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Conditional;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Profile;
 import org.springframework.core.env.Environment;
@@ -35,6 +37,7 @@ import 
org.springframework.jms.listener.DefaultMessageListenerContainer;
 
 @Configuration
 @Profile("activeMqEnabled")
+@Conditional(EnableFineractEventsCondition.class)
 public class MessagingConfiguration {
 
     @Autowired
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/notification/eventandlistener/ActiveMQNotificationEventListener.java
 
b/fineract-provider/src/main/java/org/apache/fineract/notification/eventandlistener/ActiveMQNotificationEventListener.java
index 1798082f4..f19f3e513 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/notification/eventandlistener/ActiveMQNotificationEventListener.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/notification/eventandlistener/ActiveMQNotificationEventListener.java
@@ -23,13 +23,16 @@ import javax.jms.Message;
 import javax.jms.ObjectMessage;
 import javax.jms.Session;
 import lombok.RequiredArgsConstructor;
+import 
org.apache.fineract.infrastructure.core.config.EnableFineractEventsCondition;
 import org.apache.fineract.notification.data.NotificationData;
+import org.springframework.context.annotation.Conditional;
 import org.springframework.context.annotation.Profile;
 import org.springframework.jms.listener.SessionAwareMessageListener;
 import org.springframework.stereotype.Component;
 
 @Component
 @Profile("activeMqEnabled")
+@Conditional(EnableFineractEventsCondition.class)
 @RequiredArgsConstructor
 public class ActiveMQNotificationEventListener implements 
SessionAwareMessageListener {
 
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/notification/eventandlistener/ActiveMQNotificationEventPublisher.java
 
b/fineract-provider/src/main/java/org/apache/fineract/notification/eventandlistener/ActiveMQNotificationEventPublisher.java
index 66830f49b..9a6c3191a 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/notification/eventandlistener/ActiveMQNotificationEventPublisher.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/notification/eventandlistener/ActiveMQNotificationEventPublisher.java
@@ -21,13 +21,16 @@ package org.apache.fineract.notification.eventandlistener;
 import javax.jms.Queue;
 import lombok.RequiredArgsConstructor;
 import org.apache.activemq.command.ActiveMQQueue;
+import 
org.apache.fineract.infrastructure.core.config.EnableFineractEventsCondition;
 import org.apache.fineract.notification.data.NotificationData;
+import org.springframework.context.annotation.Conditional;
 import org.springframework.context.annotation.Profile;
 import org.springframework.jms.core.JmsTemplate;
 import org.springframework.stereotype.Service;
 
 @Service
 @Profile("activeMqEnabled")
+@Conditional(EnableFineractEventsCondition.class)
 @RequiredArgsConstructor
 public class ActiveMQNotificationEventPublisher implements 
NotificationEventPublisher {
 

Reply via email to