use of com.forgerock.openbanking.common.services.notification.EventType in project openbanking-aspsp by OpenBankingToolkit.
the class EventNotificationService method notifyToEventSubscription.
private void notifyToEventSubscription(Tpp tpp, FREventSubscription eventSubscription, FREventNotification eventNotification, EventSubject eventSubject, EventType eventType) {
log.debug("Found event subscription {} for the PISP Id: {}", eventSubscription, tpp.getId());
FREventSubscriptionData eventSubscription1Data = eventSubscription.getEventSubscription();
List<String> eventTypesForTpp = eventSubscription1Data.getEventTypes();
// Check event type filter
if (eventTypesForTpp != null && eventTypesForTpp.stream().noneMatch(e -> e.equals(eventType.getEventName()))) {
log.debug("TPP {} has subscribed to event types: {} but this event is type: {}", tpp.getId(), eventTypesForTpp, eventType.getEventName());
return;
}
String callbackUrl = eventSubscription.getEventSubscription().getCallbackUrl();
if (!StringUtils.isEmpty(callbackUrl)) {
log.debug("Found event subscription callback URL for the PISP Id: {}", tpp.getId());
try {
doCallback(tpp, callbackUrl, eventNotification, eventSubject);
} catch (CallbackFailedException e) {
// Save failed attempt so it can be polled later
log.warn("Callback to event subscription callback URL: {} failed so saving event for future polling", callbackUrl);
aggregatedPollingService.createPendingEventNotification(eventNotification);
}
} else {
// No callback URL but TPP has an event subscription so save for polling
aggregatedPollingService.createPendingEventNotification(eventNotification);
log.info("Created a pending notification that can be polled by the TPP for payment id: '{}' for PISP: {}", eventSubject.getId(), tpp.getId());
}
}
Aggregations