You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by ik...@apache.org on 2019/09/02 00:04:27 UTC
[fineract-cn-notifications] 40/43: Retained JMS Configuration
This is an automated email from the ASF dual-hosted git repository.
ikamga pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-notifications.git
commit 6b0cd7aacdfe4776ec5df59ccef17b7259c0d978
Author: Ebenezer Graham <eg...@alustudent.com>
AuthorDate: Mon Jun 24 14:56:43 2019 +0400
Retained JMS Configuration
---
.../api/v1/events/NotificationEventConstants.java | 3 +
.../cn/notification/AbstractNotificationTest.java | 3 +-
.../fineract/cn/notification/TestEmailService.java | 14 +++-
.../fineract/cn/notification/TestSMSService.java | 13 +++-
.../listener/ConfigurationEventListener.java | 3 +-
.../cn/notification/listener/EventListener.java | 77 ++++++++++++++++++++++
.../fineract/cn/notification/listener/TestJMS.java | 47 +++++++++++++
.../handler/EmailConfigurationCommandHandler.java | 4 +-
.../handler/SMSConfigurationCommandHandler.java | 4 +-
.../internal/config/NotificationConfiguration.java | 31 +++++++--
.../EmailGatewayConfigurationRepository.java | 3 +-
.../SMSGatewayConfigurationRepository.java | 2 +-
.../service/internal/service/EmailService.java | 12 +---
.../internal/service/NotificationService.java | 2 +-
.../service/internal/service/SMSService.java | 6 +-
.../service/listener/CustomerEventListener.java | 4 +-
.../db/migrations/mariadb/V1__initial_setup.sql | 5 +-
17 files changed, 198 insertions(+), 35 deletions(-)
diff --git a/api/src/main/java/org/apache/fineract/cn/notification/api/v1/events/NotificationEventConstants.java b/api/src/main/java/org/apache/fineract/cn/notification/api/v1/events/NotificationEventConstants.java
index 4711a87..05bcfa3 100644
--- a/api/src/main/java/org/apache/fineract/cn/notification/api/v1/events/NotificationEventConstants.java
+++ b/api/src/main/java/org/apache/fineract/cn/notification/api/v1/events/NotificationEventConstants.java
@@ -59,4 +59,7 @@ public interface NotificationEventConstants {
String SELECTOR_SEND_EMAIL_NOTIFICATION = SELECTOR_NAME + " = '" + SEND_EMAIL_NOTIFICATION + "'";
String SELECTOR_SEND_SMS_NOTIFICATION = SELECTOR_NAME + " = '" + SEND_SMS_NOTIFICATION + "'";
+
+ String TEST = "jms-test";
+ String SELECTOR_TEST = SELECTOR_NAME + " = '" + TEST + "'";
}
diff --git a/component-test/src/main/java/org/apache/fineract/cn/notification/AbstractNotificationTest.java b/component-test/src/main/java/org/apache/fineract/cn/notification/AbstractNotificationTest.java
index 194c6c5..4f0dbc1 100644
--- a/component-test/src/main/java/org/apache/fineract/cn/notification/AbstractNotificationTest.java
+++ b/component-test/src/main/java/org/apache/fineract/cn/notification/AbstractNotificationTest.java
@@ -53,8 +53,9 @@ public class AbstractNotificationTest extends SuiteTestEnvironment {
public final static TenantDataStoreContextTestRule tenantDataStoreContext = TenantDataStoreContextTestRule.forRandomTenantName(cassandraInitializer, mariaDBInitializer);
public static final String LOGGER_NAME = "test-logger";
public static final String TEST_USER = "homer";
- public static final String TEST_ADDRESS = "egraham15@alustudent.com";
+ public static final String TEST_ADDRESS = "egraham15@alustudent.com"; // Replace with developer's dummy testing email
public static final String TEST_TEMPLATE= "sample";
+ public static final String SMS_TEST_NUMBER= "+23058409206"; // Replace with developers dummy testing number
@SuppressWarnings("WeakerAccess")
@Autowired
diff --git a/component-test/src/main/java/org/apache/fineract/cn/notification/TestEmailService.java b/component-test/src/main/java/org/apache/fineract/cn/notification/TestEmailService.java
index e4cd844..f7c9f45 100644
--- a/component-test/src/main/java/org/apache/fineract/cn/notification/TestEmailService.java
+++ b/component-test/src/main/java/org/apache/fineract/cn/notification/TestEmailService.java
@@ -54,7 +54,6 @@ public class TestEmailService extends AbstractNotificationTest {
TEST_ADDRESS,
TEST_TEMPLATE,
null);
- //Assert.assertTrue(this.eventRecorder.wait(NotificationEventConstants.SEND_EMAIL_NOTIFICATION,TEST_ADDRESS ));
}
@Test
@@ -81,8 +80,6 @@ public class TestEmailService extends AbstractNotificationTest {
TEST_TEMPLATE,
templateVariables
);
-
- //Assert.assertTrue(this.eventRecorder.wait(NotificationEventConstants.SEND_EMAIL_NOTIFICATION,TEST_ADDRESS ));
}
@Test(expected = NotFoundException.class)
@@ -115,6 +112,17 @@ public class TestEmailService extends AbstractNotificationTest {
}
@Test
+ public void deleteConfiguration() throws InterruptedException {
+ logger.info("Delete Email configuration");
+
+ notificationManager.createEmailConfiguration(emailConfiguration);
+ Assert.assertTrue(eventRecorder.wait(NotificationEventConstants.POST_EMAIL_CONFIGURATION, emailConfiguration.getIdentifier()));
+
+ notificationManager.deleteEmailConfiguration(emailConfiguration.getIdentifier());
+ Assert.assertTrue(eventRecorder.wait(NotificationEventConstants.DELETE_EMAIL_CONFIGURATION, emailConfiguration.getIdentifier()));
+ }
+
+ @Test
public void shouldFindDefaultGateway() {
this.logger.info("Find Active Gateway");
Assert.assertNotNull(this.emailService.getDefaultEmailConfigurationEntity());
diff --git a/component-test/src/main/java/org/apache/fineract/cn/notification/TestSMSService.java b/component-test/src/main/java/org/apache/fineract/cn/notification/TestSMSService.java
index 4b5e251..5bf34fb 100644
--- a/component-test/src/main/java/org/apache/fineract/cn/notification/TestSMSService.java
+++ b/component-test/src/main/java/org/apache/fineract/cn/notification/TestSMSService.java
@@ -84,8 +84,19 @@ public class TestSMSService extends AbstractNotificationTest {
@Test
public void shouldSendAnSMS(){
this.logger.info("Send SMS Notification");
- String to = this.notificationService.sendSMS("+23058409206",
+ int to = this.notificationService.sendSMS(SMS_TEST_NUMBER,
"Dear Valued Customer\n\nTalk is cheap show me the code\n\nBest Regards\nYour MFI");
Assert.assertNotNull(to);
}
+
+ @Test
+ public void deleteConfiguration() throws InterruptedException {
+ logger.info("Delete SMS configuration");
+
+ notificationManager.createSMSConfiguration(smsConfiguration);
+ Assert.assertTrue(eventRecorder.wait(NotificationEventConstants.POST_SMS_CONFIGURATION, smsConfiguration.getIdentifier()));
+
+ notificationManager.deleteSMSConfiguration(smsConfiguration.getIdentifier());
+ Assert.assertTrue(eventRecorder.wait(NotificationEventConstants.DELETE_SMS_CONFIGURATION, smsConfiguration.getIdentifier()));
+ }
}
diff --git a/component-test/src/main/java/org/apache/fineract/cn/notification/listener/ConfigurationEventListener.java b/component-test/src/main/java/org/apache/fineract/cn/notification/listener/ConfigurationEventListener.java
index b4b5491..4039af6 100644
--- a/component-test/src/main/java/org/apache/fineract/cn/notification/listener/ConfigurationEventListener.java
+++ b/component-test/src/main/java/org/apache/fineract/cn/notification/listener/ConfigurationEventListener.java
@@ -108,6 +108,7 @@ public class ConfigurationEventListener {
public void onDeleteEmailConfiguration(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
final String payload) {
this.eventRecorder.event(tenant, NotificationEventConstants.DELETE_EMAIL_CONFIGURATION, payload, String.class);
+ logger.info("onDeleteEmailConfiguration received");
}
@JmsListener(
@@ -148,6 +149,6 @@ public class ConfigurationEventListener {
public void onPostTemplate(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
final String payload) {
this.eventRecorder.event(tenant, NotificationEventConstants.POST_TEMPLATE, payload, String.class);
- }
+ }
}
diff --git a/component-test/src/main/java/org/apache/fineract/cn/notification/listener/EventListener.java b/component-test/src/main/java/org/apache/fineract/cn/notification/listener/EventListener.java
new file mode 100644
index 0000000..f5f63f4
--- /dev/null
+++ b/component-test/src/main/java/org/apache/fineract/cn/notification/listener/EventListener.java
@@ -0,0 +1,77 @@
+/*
+ * 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.
+ */
+ /*
+ * 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.cn.notification.listener;
+
+import org.apache.fineract.cn.lang.config.TenantHeaderFilter;
+import org.apache.fineract.cn.notification.api.v1.events.NotificationEventConstants;
+import org.apache.fineract.cn.notification.service.ServiceConstants;
+import org.apache.fineract.cn.test.listener.EventRecorder;
+import org.slf4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.jms.annotation.JmsListener;
+import org.springframework.messaging.handler.annotation.Header;
+import org.springframework.stereotype.Component;
+
+import static org.apache.fineract.cn.notification.api.v1.events.NotificationEventConstants.SELECTOR_TEST;
+import static org.apache.fineract.cn.notification.api.v1.events.NotificationEventConstants.TEST;
+
+@SuppressWarnings("unused")
+@Component
+public class EventListener {
+ private final EventRecorder eventRecorder;
+ private final Logger logger;
+
+
+ @Autowired
+ public EventListener(final EventRecorder eventRecorder,
+ @Qualifier(ServiceConstants.LOGGER_NAME) final Logger logger) {
+ this.logger = logger;
+ this.eventRecorder = eventRecorder;
+ }
+ static int counter = 0;
+ @JmsListener(
+ destination = TEST,
+ selector = SELECTOR_TEST
+ )
+ public void jmsTest(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
+ final String payload) {
+ counter++;
+ logger.info("Received {}",counter);
+ this.eventRecorder.event(tenant, NotificationEventConstants.TEST, payload, String.class);
+ }
+}
diff --git a/component-test/src/main/java/org/apache/fineract/cn/notification/listener/TestJMS.java b/component-test/src/main/java/org/apache/fineract/cn/notification/listener/TestJMS.java
new file mode 100644
index 0000000..6784cdd
--- /dev/null
+++ b/component-test/src/main/java/org/apache/fineract/cn/notification/listener/TestJMS.java
@@ -0,0 +1,47 @@
+/*
+ * 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.cn.notification.listener;
+
+import org.apache.fineract.cn.notification.AbstractNotificationTest;
+import org.apache.fineract.cn.notification.service.internal.service.EventHelper;
+import org.junit.Assert;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.io.IOException;
+
+import static org.apache.fineract.cn.notification.api.v1.events.NotificationEventConstants.TEST;
+
+public class TestJMS extends AbstractNotificationTest {
+
+ @Autowired
+ EventHelper eventHelper;
+
+
+ public TestJMS() {
+ super();
+ }
+
+ @Test
+ public void testJMSConcurrency() throws InterruptedException,IOException {
+ this.logger.info("Send JMS event");
+ eventHelper.sendEvent(TEST,"test-tenant","payload");
+ Assert.assertTrue(eventRecorder.wait(TEST,"payload"));
+ }
+}
diff --git a/service/src/main/java/org/apache/fineract/cn/notification/service/internal/command/handler/EmailConfigurationCommandHandler.java b/service/src/main/java/org/apache/fineract/cn/notification/service/internal/command/handler/EmailConfigurationCommandHandler.java
index 3c7928d..40ff7e3 100644
--- a/service/src/main/java/org/apache/fineract/cn/notification/service/internal/command/handler/EmailConfigurationCommandHandler.java
+++ b/service/src/main/java/org/apache/fineract/cn/notification/service/internal/command/handler/EmailConfigurationCommandHandler.java
@@ -63,7 +63,7 @@ public class EmailConfigurationCommandHandler {
public String process(final UpdateEmailConfigurationCommand updateEmailConfigurationCommand) {
EmailConfiguration emailConfiguration = updateEmailConfigurationCommand.getEmailConfiguration();
final EmailGatewayConfigurationEntity newEntity = EmailConfigurationMapper.map(emailConfiguration);
- this.emailGatewayConfigurationRepository.deleteEmailGatewayConfigurationEntityBy(newEntity.getIdentifier());
+ this.emailGatewayConfigurationRepository.deleteEmailGatewayConfigurationEntityByIdentifier(newEntity.getIdentifier());
this.emailGatewayConfigurationRepository.save(newEntity);
return emailConfiguration.getIdentifier();
@@ -73,7 +73,7 @@ public class EmailConfigurationCommandHandler {
@Transactional
@EventEmitter(selectorName = NotificationEventConstants.SELECTOR_NAME, selectorValue = NotificationEventConstants.DELETE_EMAIL_CONFIGURATION)
public String process(final DeleteEmailConfigurationCommand deleteEmailConfigurationCommand) {
- this.emailGatewayConfigurationRepository.deleteEmailGatewayConfigurationEntityBy(deleteEmailConfigurationCommand.getIdentifier());
+ this.emailGatewayConfigurationRepository.deleteEmailGatewayConfigurationEntityByIdentifier(deleteEmailConfigurationCommand.getIdentifier());
return deleteEmailConfigurationCommand.getIdentifier();
}
}
diff --git a/service/src/main/java/org/apache/fineract/cn/notification/service/internal/command/handler/SMSConfigurationCommandHandler.java b/service/src/main/java/org/apache/fineract/cn/notification/service/internal/command/handler/SMSConfigurationCommandHandler.java
index e3234db..42337fb 100644
--- a/service/src/main/java/org/apache/fineract/cn/notification/service/internal/command/handler/SMSConfigurationCommandHandler.java
+++ b/service/src/main/java/org/apache/fineract/cn/notification/service/internal/command/handler/SMSConfigurationCommandHandler.java
@@ -60,7 +60,7 @@ public class SMSConfigurationCommandHandler {
@Transactional
public String process(final UpdateSMSConfigurationCommand updateSMSConfigurationCommand) {
final SMSGatewayConfigurationEntity newEntity = SMSConfigurationMapper.map(updateSMSConfigurationCommand.getSMSConfiguration());
- this.smsGatewayConfigurationRepository.deleteSMSGatewayConfigurationEntityBy(newEntity.getIdentifier());
+ this.smsGatewayConfigurationRepository.deleteSMSGatewayConfigurationEntityByIdentifier(newEntity.getIdentifier());
this.smsGatewayConfigurationRepository.save(newEntity);
return newEntity.getIdentifier();
@@ -70,7 +70,7 @@ public class SMSConfigurationCommandHandler {
@Transactional
@EventEmitter(selectorName = NotificationEventConstants.SELECTOR_NAME, selectorValue = NotificationEventConstants.DELETE_SMS_CONFIGURATION)
public String process(final DeleteSMSConfigurationCommand deleteSMSConfigurationCommand) {
- smsGatewayConfigurationRepository.deleteSMSGatewayConfigurationEntityBy(deleteSMSConfigurationCommand.getIdentifier());
+ smsGatewayConfigurationRepository.deleteSMSGatewayConfigurationEntityByIdentifier(deleteSMSConfigurationCommand.getIdentifier());
return deleteSMSConfigurationCommand.getIdentifier();
}
}
diff --git a/service/src/main/java/org/apache/fineract/cn/notification/service/internal/config/NotificationConfiguration.java b/service/src/main/java/org/apache/fineract/cn/notification/service/internal/config/NotificationConfiguration.java
index f237dff..c99b67c 100644
--- a/service/src/main/java/org/apache/fineract/cn/notification/service/internal/config/NotificationConfiguration.java
+++ b/service/src/main/java/org/apache/fineract/cn/notification/service/internal/config/NotificationConfiguration.java
@@ -18,6 +18,8 @@
*/
package org.apache.fineract.cn.notification.service.internal.config;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.command.ActiveMQTopic;
import org.apache.activemq.jms.pool.PooledConnectionFactory;
import org.apache.fineract.cn.anubis.config.EnableAnubis;
import org.apache.fineract.cn.async.config.EnableAsync;
@@ -25,6 +27,7 @@ import org.apache.fineract.cn.cassandra.config.EnableCassandra;
import org.apache.fineract.cn.command.config.EnableCommandProcessing;
import org.apache.fineract.cn.customer.api.v1.client.CustomerManager;
import org.apache.fineract.cn.identity.api.v1.client.IdentityManager;
+import org.apache.fineract.cn.lang.ApplicationName;
import org.apache.fineract.cn.lang.config.EnableServiceException;
import org.apache.fineract.cn.lang.config.EnableTenantContext;
import org.apache.fineract.cn.mariadb.config.EnableMariaDB;
@@ -100,19 +103,37 @@ public class NotificationConfiguration extends WebMvcConfigurerAdapter {
}
@Bean
+ public PooledConnectionFactory jmsFactory() {
+ PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory();
+ ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
+ activeMQConnectionFactory.setBrokerURL(this.environment.getProperty("activemq.brokerUrl", "vm://localhost?broker.persistent=false"));
+ pooledConnectionFactory.setConnectionFactory(activeMQConnectionFactory);
+ return pooledConnectionFactory;
+ }
+
+ @Bean
public JmsListenerContainerFactory jmsListenerContainerFactory(PooledConnectionFactory jmsFactory) {
- final DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
- factory.setConnectionFactory(jmsFactory);
+ DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setPubSubDomain(true);
factory.setConnectionFactory(jmsFactory);
factory.setErrorHandler(ex -> {
- loggerBean().warn(ex.getCause().toString());
+ loggerBean().error(ex.getCause().toString());
});
- factory.setConcurrency(this.environment.getProperty("activemq.concurrency","1-1"));
+ factory.setConcurrency(this.environment.getProperty("activemq.concurrency", "1"));
return factory;
}
@Bean
+ public JmsTemplate jmsTemplate(ApplicationName applicationName, PooledConnectionFactory jmsFactory) {
+ ActiveMQTopic activeMQTopic = new ActiveMQTopic(applicationName.toString());
+ JmsTemplate jmsTemplate = new JmsTemplate();
+ jmsTemplate.setPubSubDomain(true);
+ jmsTemplate.setConnectionFactory(jmsFactory);
+ jmsTemplate.setDefaultDestination(activeMQTopic);
+ return jmsTemplate;
+ }
+
+ @Bean
public SpringTemplateEngine springTemplateEngine() {
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.addTemplateResolver(htmlTemplateResolver());
@@ -120,7 +141,7 @@ public class NotificationConfiguration extends WebMvcConfigurerAdapter {
}
@Bean
- public SpringResourceTemplateResolver htmlTemplateResolver(){
+ public SpringResourceTemplateResolver htmlTemplateResolver() {
SpringResourceTemplateResolver emailTemplateResolver = new SpringResourceTemplateResolver();
emailTemplateResolver.setPrefix("classpath:/templates/");
emailTemplateResolver.setSuffix(".html");
diff --git a/service/src/main/java/org/apache/fineract/cn/notification/service/internal/repository/EmailGatewayConfigurationRepository.java b/service/src/main/java/org/apache/fineract/cn/notification/service/internal/repository/EmailGatewayConfigurationRepository.java
index 2b5ddcb..ee94b58 100644
--- a/service/src/main/java/org/apache/fineract/cn/notification/service/internal/repository/EmailGatewayConfigurationRepository.java
+++ b/service/src/main/java/org/apache/fineract/cn/notification/service/internal/repository/EmailGatewayConfigurationRepository.java
@@ -35,5 +35,6 @@ public interface EmailGatewayConfigurationRepository extends JpaRepository<Email
@Query("SELECT entity FROM EmailGatewayConfigurationEntity entity WHERE entity.identifier='DEFAULT'")
Optional<EmailGatewayConfigurationEntity> defaultGateway();
- void deleteEmailGatewayConfigurationEntityBy(String identifier);
+ void deleteEmailGatewayConfigurationEntityByIdentifier(String identifier);
+
}
diff --git a/service/src/main/java/org/apache/fineract/cn/notification/service/internal/repository/SMSGatewayConfigurationRepository.java b/service/src/main/java/org/apache/fineract/cn/notification/service/internal/repository/SMSGatewayConfigurationRepository.java
index 64e8427..0e2d642 100644
--- a/service/src/main/java/org/apache/fineract/cn/notification/service/internal/repository/SMSGatewayConfigurationRepository.java
+++ b/service/src/main/java/org/apache/fineract/cn/notification/service/internal/repository/SMSGatewayConfigurationRepository.java
@@ -35,5 +35,5 @@ public interface SMSGatewayConfigurationRepository extends JpaRepository<SMSGate
@Query("SELECT entity FROM SMSGatewayConfigurationEntity entity WHERE entity.identifier='DEFAULT'")
Optional<SMSGatewayConfigurationEntity> defaultGateway();
- void deleteSMSGatewayConfigurationEntityBy(String identifier);
+ void deleteSMSGatewayConfigurationEntityByIdentifier(String identifier);
}
diff --git a/service/src/main/java/org/apache/fineract/cn/notification/service/internal/service/EmailService.java b/service/src/main/java/org/apache/fineract/cn/notification/service/internal/service/EmailService.java
index 9290e91..655f6dc 100644
--- a/service/src/main/java/org/apache/fineract/cn/notification/service/internal/service/EmailService.java
+++ b/service/src/main/java/org/apache/fineract/cn/notification/service/internal/service/EmailService.java
@@ -18,7 +18,6 @@
*/
package org.apache.fineract.cn.notification.service.internal.service;
-import org.apache.fineract.cn.command.annotation.Aggregate;
import org.apache.fineract.cn.command.annotation.CommandHandler;
import org.apache.fineract.cn.command.annotation.CommandLogLevel;
import org.apache.fineract.cn.command.annotation.EventEmitter;
@@ -46,7 +45,6 @@ import java.util.Optional;
import java.util.Properties;
@Component
-@Aggregate
public class EmailService {
private final EmailGatewayConfigurationRepository emailGatewayConfigurationRepository;
@@ -113,9 +111,6 @@ public class EmailService {
return false;
}
- @CommandHandler(logStart = CommandLogLevel.INFO, logFinish = CommandLogLevel.INFO)
- @Transactional
- @EventEmitter(selectorName = NotificationEventConstants.SELECTOR_NAME, selectorValue = NotificationEventConstants.SEND_EMAIL_NOTIFICATION)
public String sendPlainEmail(String to, String subject, String message) {
SimpleMailMessage mail = new SimpleMailMessage();
@@ -123,7 +118,7 @@ public class EmailService {
mail.setTo(to);
mail.setSubject(subject);
mail.setText(message);
- //this.mailSender.send(mail);
+ this.mailSender.send(mail);
return to;
} catch (MailException exception) {
logger.debug("Caused by:" + exception.getCause().toString());
@@ -131,9 +126,6 @@ public class EmailService {
return to;
}
- @CommandHandler(logStart = CommandLogLevel.INFO, logFinish = CommandLogLevel.INFO)
- @Transactional
- @EventEmitter(selectorName = NotificationEventConstants.SELECTOR_NAME, selectorValue = NotificationEventConstants.SEND_EMAIL_NOTIFICATION)
public String sendFormattedEmail(String to,
String subject,
Map<String, Object> message,
@@ -146,7 +138,7 @@ public class EmailService {
messageHelper.setText(content, true);
};
try {
- //this.mailSender.send(messagePreparator);
+ this.mailSender.send(messagePreparator);
return to;
} catch (MailException e) {
logger.error("Failed to send Formatted email{}", e.getMessage());
diff --git a/service/src/main/java/org/apache/fineract/cn/notification/service/internal/service/NotificationService.java b/service/src/main/java/org/apache/fineract/cn/notification/service/internal/service/NotificationService.java
index 50bc1f9..6ca39b1 100644
--- a/service/src/main/java/org/apache/fineract/cn/notification/service/internal/service/NotificationService.java
+++ b/service/src/main/java/org/apache/fineract/cn/notification/service/internal/service/NotificationService.java
@@ -60,7 +60,7 @@ public class NotificationService {
return customerService.findCustomer(customerIdentifier);
}
- public String sendSMS(String receiver, String template) {
+ public int sendSMS(String receiver, String template) {
if (!this.smsService.isConfigured) this.smsService.configureServiceWithDefaultGateway();
return this.smsService.sendSMS(receiver, template);
}
diff --git a/service/src/main/java/org/apache/fineract/cn/notification/service/internal/service/SMSService.java b/service/src/main/java/org/apache/fineract/cn/notification/service/internal/service/SMSService.java
index 76ce3a0..42f01f1 100644
--- a/service/src/main/java/org/apache/fineract/cn/notification/service/internal/service/SMSService.java
+++ b/service/src/main/java/org/apache/fineract/cn/notification/service/internal/service/SMSService.java
@@ -106,15 +106,15 @@ public class SMSService {
@CommandHandler(logStart = CommandLogLevel.INFO, logFinish = CommandLogLevel.INFO)
@Transactional
@EventEmitter(selectorName = NotificationEventConstants.SELECTOR_NAME, selectorValue = NotificationEventConstants.SEND_SMS_NOTIFICATION)
- public String sendSMS(String receiver, String template) {
+ public int sendSMS(String receiver, String template) {
Twilio.init(this.accountSid, this.authToken);
MessageCreator messageCreator = Message.creator(this.accountSid,
new PhoneNumber(receiver),
new PhoneNumber(this.senderNumber),
template);
- //Message message = messageCreator.create();
+ Message message = messageCreator.create();
System.out.println("\n\n\nsent");
- return "";//message;
+ return message.hashCode();
}
}
diff --git a/service/src/main/java/org/apache/fineract/cn/notification/service/listener/CustomerEventListener.java b/service/src/main/java/org/apache/fineract/cn/notification/service/listener/CustomerEventListener.java
index 96524e4..2fcc300 100644
--- a/service/src/main/java/org/apache/fineract/cn/notification/service/listener/CustomerEventListener.java
+++ b/service/src/main/java/org/apache/fineract/cn/notification/service/listener/CustomerEventListener.java
@@ -98,7 +98,7 @@
)
public void customerUpdatedEvents(@Header(TenantHeaderFilter.TENANT_HEADER) final String tenant,
final String payload) {
- this.logger.info("{} has been invoked", "customerUpdatedEvents");
+ this.logger.info("{} has been invoked", "customerUpdatedEvent");
Customer customer = this.notificationService.findCustomer(payload, tenant).get();
customer.getContactDetails().forEach(contact -> {
@@ -117,7 +117,7 @@
// TODO: Pass message to template
notificationService.sendEmail(
emailAddress,
- "customerUpdatedEvents",
+ "customerUpdatedEvent",
payload);
}
});
diff --git a/service/src/main/resources/db/migrations/mariadb/V1__initial_setup.sql b/service/src/main/resources/db/migrations/mariadb/V1__initial_setup.sql
index 81fc5bf..03469b4 100644
--- a/service/src/main/resources/db/migrations/mariadb/V1__initial_setup.sql
+++ b/service/src/main/resources/db/migrations/mariadb/V1__initial_setup.sql
@@ -21,7 +21,7 @@
-- Table wada_sms_gateway_configurations
-- -----------------------------------------------------
CREATE TABLE wada_sms_gateway_configurations (
- id INT(45) NOT NULL AUTO_INCREMENT,
+ id INT NOT NULL AUTO_INCREMENT,
identifier VARCHAR(45) NULL DEFAULT NULL,
account_sid VARCHAR(255) NOT NULL,
auth_token VARCHAR(255) NOT NULL,
@@ -63,7 +63,7 @@ INSERT INTO wada_email_gateway_configurations VALUES ('1', 'DEFAULT', 'smtp.gmai
/*Insert default template for supported events*/
INSERT INTO wada_templates VALUES ('1','customerCreatedEvent','DEFAULT','Account created','Your account has been created','template');
-INSERT INTO wada_templates VALUES ('2','customerUpdatedEvents','DEFAULT','Account updated','Your account has been Updated','template');
+INSERT INTO wada_templates VALUES ('2','customerUpdatedEvent','DEFAULT','Account updated','Your account has been Updated','template');
INSERT INTO wada_templates VALUES ('3','customerActivatedEvent','DEFAULT','Account Activated','Your account has been Activated','template');
INSERT INTO wada_templates VALUES ('4','customerLockedEvent','DEFAULT','Account Locked','Your account has been Locked','template');
INSERT INTO wada_templates VALUES ('5','customerUnlockedEvent','DEFAULT','Account unlocked','Your account has been Unlocked','template');
@@ -73,3 +73,4 @@ INSERT INTO wada_templates VALUES ('8','contactDetailsChangedEvent','DEFAULT','C
INSERT INTO wada_templates VALUES ('9','addressChangedEvent','DEFAULT','Residence address has been changed','Your address has been changed successfully','template');
INSERT INTO wada_templates VALUES ('10','sample','DEFAULT','Test Subject','Talk is cheap! Show me the code','template');
+