From c2997c3468bb17faf167d0b51d35e5bceddc8b33 Mon Sep 17 00:00:00 2001 From: Ashi1993 Date: Wed, 4 Dec 2024 14:45:22 +0530 Subject: [PATCH] Adding realtime notification code --- .../accelerator/common/util/HTTPClientUtils.java | 4 ++-- .../notifications/service/EventCreationService.java | 1 - .../service/RealtimeNotificationService.java | 3 +++ .../service/internal/EventNotificationComponent.java | 12 +++++++++--- .../service/EventNotificationProducerService.java | 1 + .../RealtimeEventNotificationSenderService.java | 2 -- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.common/src/main/java/org/wso2/financial/services/accelerator/common/util/HTTPClientUtils.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.common/src/main/java/org/wso2/financial/services/accelerator/common/util/HTTPClientUtils.java index b32578a4b..59cb27677 100644 --- a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.common/src/main/java/org/wso2/financial/services/accelerator/common/util/HTTPClientUtils.java +++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.common/src/main/java/org/wso2/financial/services/accelerator/common/util/HTTPClientUtils.java @@ -66,7 +66,7 @@ public class HTTPClientUtils { * @return Closeable https client * @throws FinancialServicesException FinancialServicesException exception */ - @Generated(message = "Ignoring because ServerConfiguration cannot be mocked") + @Generated(message = "Ignoring since method contains no logics") public static CloseableHttpClient getHttpsClient() throws FinancialServicesException { SSLConnectionSocketFactory sslsf = createSSLConnectionSocketFactory(); @@ -94,7 +94,7 @@ public static CloseableHttpClient getHttpsClient() throws FinancialServicesExcep * @return Closeable https client * @throws FinancialServicesException FinancialServicesException exception */ - @Generated(message = "Ignoring because ServerConfiguration cannot be mocked") + @Generated(message = "Ignoring since method contains no logics") public static CloseableHttpClient getHttpsClient(int maxTotal, int maxPerRoute) throws FinancialServicesException { SSLConnectionSocketFactory sslsf = createSSLConnectionSocketFactory(); diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/EventCreationService.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/EventCreationService.java index 852aeeb39..cd7e4d87c 100644 --- a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/EventCreationService.java +++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/EventCreationService.java @@ -66,7 +66,6 @@ public String publishEventNotification(NotificationCreationDTO notificationCreat eventResponse = eventCreationDAO.persistEventNotification(connection, notification, eventsList); DatabaseUtils.commitTransaction(connection); - //TODO: if (FinancialServicesConfigParser.getInstance().isRealtimeEventNotificationEnabled()) { new Thread(new EventNotificationProducerService(notification, eventsList)).start(); } diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/RealtimeNotificationService.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/RealtimeNotificationService.java index 6e6e46b45..43dc3feaf 100644 --- a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/RealtimeNotificationService.java +++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/RealtimeNotificationService.java @@ -67,6 +67,7 @@ public List getNotificationsByStatus(String status) DatabaseUtils.rollbackTransaction(connection); throw new FSEventNotificationException(EventNotificationConstants.ERROR_STORING_EVENT_SUBSCRIPTION, e); } finally { + log.debug(EventNotificationConstants.DATABASE_CONNECTION_CLOSE_LOG_MSG); DatabaseUtils.closeConnection(connection); } } @@ -100,6 +101,7 @@ public List getEventsByNotificationID(String notificationId) DatabaseUtils.rollbackTransaction(connection); throw new FSEventNotificationException(EventNotificationConstants.ERROR_STORING_EVENT_SUBSCRIPTION, e); } finally { + log.debug(EventNotificationConstants.DATABASE_CONNECTION_CLOSE_LOG_MSG); DatabaseUtils.closeConnection(connection); } } @@ -133,6 +135,7 @@ public void updateNotificationStatusById(String notificationId, String notificat DatabaseUtils.rollbackTransaction(connection); throw new FSEventNotificationException(e.getMessage(), e); } finally { + log.debug(EventNotificationConstants.DATABASE_CONNECTION_CLOSE_LOG_MSG); DatabaseUtils.closeConnection(connection); } } diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/internal/EventNotificationComponent.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/internal/EventNotificationComponent.java index d23a9bf01..53b6ff8a2 100644 --- a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/internal/EventNotificationComponent.java +++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/internal/EventNotificationComponent.java @@ -39,15 +39,21 @@ name = "org.wso2.financial.services.accelerator.event.notifications.service.internal.EventNotificationComponent", immediate = true) public class EventNotificationComponent { + private static final Log log = LogFactory.getLog(EventNotificationComponent.class); @Activate protected void activate(ComponentContext context) throws Exception { - log.info("Event Notification Service Component Activated"); + log.debug("Event Notification Service Component Activated"); // Check if realtime event notification enabled if (FinancialServicesConfigParser.getInstance().isRealtimeEventNotificationEnabled()) { - log.info("Realtime Event Notification Service Activated"); + /* + * Initialize the blocking queue for storing the realtime event notifications + * Initialize the quartz job for consuming the realtime event notifications + * Initialize the thread for producing the open state realtime event notifications + */ + log.debug("Realtime Event Notification Service Activated"); new Thread(new RealtimeEventNotificationLoaderService()).start(); new PeriodicalEventNotificationConsumerJobActivator().activate(); } @@ -56,6 +62,7 @@ protected void activate(ComponentContext context) throws Exception { /** * Setters for the descendent OSGI services of the EventNotificationComponent. * This is added to run the EventNotification OSGI component after the Common module + * @param configurationService FinancialServicesConfigurationService */ @Reference( service = FinancialServicesConfigurationService.class, @@ -81,7 +88,6 @@ public void unsetConfigService(FinancialServicesConfigurationService configurati policy = ReferencePolicy.DYNAMIC, unbind = "unsetOAuth2Service" ) - public void setOAuth2Service(OAuth2Service oAuth2Service) { } diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/realtime/service/EventNotificationProducerService.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/realtime/service/EventNotificationProducerService.java index 2ff5902e4..e86462f58 100644 --- a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/realtime/service/EventNotificationProducerService.java +++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/realtime/service/EventNotificationProducerService.java @@ -48,6 +48,7 @@ public class EventNotificationProducerService implements Runnable { public EventNotificationProducerService( Notification notification, List notificationEvents) { + this.notification = notification; this.notificationEvents = notificationEvents; } diff --git a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/realtime/service/RealtimeEventNotificationSenderService.java b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/realtime/service/RealtimeEventNotificationSenderService.java index c119bc1d2..6957423ed 100644 --- a/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/realtime/service/RealtimeEventNotificationSenderService.java +++ b/financial-services-accelerator/components/org.wso2.financial.services.accelerator.event.notifications.service/src/main/java/org/wso2/financial/services/accelerator/event/notifications/service/realtime/service/RealtimeEventNotificationSenderService.java @@ -199,8 +199,6 @@ private void postWithRetry() throws FSEventNotificationException { log.error("Real-time event notification with notificationId: " + notificationId.replaceAll("[\r\n]", "") + " sent failed", e); } - } - } }