Skip to content

Commit

Permalink
Adding realtime event notification implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashi1993 committed Nov 4, 2024
1 parent 05b0bdb commit 605849f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ public EventSubscription getEventSubscriptionBySubscriptionId(Connection connect
eventTypes.add(eventType);
}
}
if (!eventTypes.isEmpty()) {
retrievedSubscription.setEventTypes(eventTypes);
}
retrievedSubscription.setEventTypes(eventTypes);
} else {
log.error("No event notification subscription found for the given subscription id.");
throw new FSEventNotificationException(
Expand Down Expand Up @@ -171,9 +169,7 @@ public List<EventSubscription> getEventSubscriptionsByClientId(Connection connec
break;
}
}
if (!eventTypes.isEmpty()) {
eventSubscription.setEventTypes(eventTypes);
}
eventSubscription.setEventTypes(eventTypes);
retrievedSubscriptions.add(eventSubscription);
}
log.debug("Retrieved the event notification subscriptions successfully.");
Expand Down Expand Up @@ -216,9 +212,7 @@ public List<EventSubscription> getEventSubscriptionsByEventType(Connection conne
break;
}
}
if (!eventTypes.isEmpty()) {
eventSubscription.setEventTypes(eventTypes);
}
eventSubscription.setEventTypes(eventTypes);
retrievedSubscriptions.add(eventSubscription);
}
log.debug("Retrieved the event notification subscriptions successfully.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.wso2.carbon.identity.oauth2.OAuth2Service;
import org.wso2.financial.services.accelerator.common.config.FinancialServicesConfigParser;
import org.wso2.financial.services.accelerator.common.config.FinancialServicesConfigurationService;
import org.wso2.financial.services.accelerator.event.notifications.service.realtime.service.RealtimeEventNotificationLoaderService;
import org.wso2.financial.services.accelerator.event.notifications.service.realtime.util.activator.PeriodicalEventNotificationConsumerJobActivator;

Expand Down Expand Up @@ -58,44 +53,4 @@ protected void activate(ComponentContext context) {
new PeriodicalEventNotificationConsumerJobActivator().activate();
}
}

/**
* Setters for the descendent OSGI services of the EventNotificationComponent.
* This is added to run the EventNotification OSGI component after the Common module
* @param configService OpenBankingConfigurationService
*/
@Reference(
service = FinancialServicesConfigurationService.class,
cardinality = ReferenceCardinality.MANDATORY,
policy = ReferencePolicy.DYNAMIC,
unbind = "unsetConfigService"
)
public void setConfigService(FinancialServicesConfigurationService configService) {
EventNotificationDataHolder.getInstance().setFinancialServicesConfigurationService(configService);
}

public void unsetConfigService(FinancialServicesConfigurationService configService) {
EventNotificationDataHolder.getInstance().setFinancialServicesConfigurationService(null);
}

/**
* Setters for the descendent OSGI services of the EventNotificationComponent.
* This is added to run the EventNotification OSGI component after the OAuth2Service
*/
@Reference(
service = OAuth2Service.class,
cardinality = ReferenceCardinality.MANDATORY,
policy = ReferencePolicy.DYNAMIC,
unbind = "unsetOAuth2Service"
)

/**
* Setters for the descendent OSGI services of the EventNotificationComponent.
* @param oAuth2Service OAuth2Service
*/
public void setOAuth2Service(OAuth2Service oAuth2Service) {
}

public void unsetOAuth2Service(OAuth2Service oAuth2Service) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.financial.services.accelerator.common.config.FinancialServicesConfigurationService;
import org.wso2.financial.services.accelerator.event.notifications.service.model.RealtimeEventNotification;

import java.util.concurrent.LinkedBlockingQueue;
Expand All @@ -32,7 +31,6 @@ public class EventNotificationDataHolder {
private static Log log = LogFactory.getLog(EventNotificationDataHolder.class);
private static volatile EventNotificationDataHolder instance;
private volatile LinkedBlockingQueue<RealtimeEventNotification> realtimeEventNotificationQueue;
private FinancialServicesConfigurationService configService;

private EventNotificationDataHolder() {
this.realtimeEventNotificationQueue = new LinkedBlockingQueue<>();
Expand All @@ -58,17 +56,6 @@ public LinkedBlockingQueue<RealtimeEventNotification> getRealtimeEventNotificati
return realtimeEventNotificationQueue;
}

public FinancialServicesConfigurationService getFinancialServicesConfigurationService() {

return configService;
}

public void setFinancialServicesConfigurationService(
FinancialServicesConfigurationService configService) {

this.configService = configService;
}

public void setRealtimeEventNotificationQueue(LinkedBlockingQueue<RealtimeEventNotification> queue) {
this.realtimeEventNotificationQueue = queue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public void run() {
allowedEvents.add(notificationEvent);
}
});

if (allowedEvents.isEmpty()) {
continue;
}

RealtimeEventNotification realtimeEventNotification = new RealtimeEventNotification();
realtimeEventNotification.setNotification(notification);
realtimeEventNotification.setCallbackUrl(subscription.getCallbackUrl());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public void run() {
}
});

if (allowedEvents.isEmpty()) {
continue;
}

NotificationResponse responseNotification = eventNotificationGenerator.
generateEventNotificationBody(notification, allowedEvents);
RealtimeEventNotification realtimeEventNotification = new RealtimeEventNotification();
Expand Down

0 comments on commit 605849f

Please sign in to comment.