Search in sources :

Example 1 with FREventSubscriptionData

use of com.forgerock.openbanking.common.model.openbanking.domain.event.FREventSubscriptionData 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());
    }
}
Also used : EventSubject(com.forgerock.openbanking.common.services.notification.EventSubject) EventType(com.forgerock.openbanking.common.services.notification.EventType) Tpp(com.forgerock.openbanking.model.Tpp) EventSubscriptionService(com.forgerock.openbanking.aspsp.rs.simulator.event.store.EventSubscriptionService) FREventSubscriptionData(com.forgerock.openbanking.common.model.openbanking.domain.event.FREventSubscriptionData) DateTime(org.joda.time.DateTime) AggregatedPollingService(com.forgerock.openbanking.aspsp.rs.simulator.event.store.AggregatedPollingService) CallBackCounterEntry(com.forgerock.openbanking.analytics.model.entries.callback.CallBackCounterEntry) CallBackResponseStatus(com.forgerock.openbanking.analytics.model.entries.callback.CallBackResponseStatus) FREventSubscription(com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventSubscription) CallbackUrlsService(com.forgerock.openbanking.aspsp.rs.simulator.event.store.CallbackUrlsService) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Service(org.springframework.stereotype.Service) CallBackCountersKPIService(com.forgerock.openbanking.analytics.services.CallBackCountersKPIService) FRCallbackUrl(com.forgerock.openbanking.common.model.openbanking.persistence.event.FRCallbackUrl) Optional(java.util.Optional) FREventNotification(com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification) Collections(java.util.Collections) StringUtils(org.springframework.util.StringUtils) FREventSubscriptionData(com.forgerock.openbanking.common.model.openbanking.domain.event.FREventSubscriptionData)

Aggregations

CallBackCounterEntry (com.forgerock.openbanking.analytics.model.entries.callback.CallBackCounterEntry)1 CallBackResponseStatus (com.forgerock.openbanking.analytics.model.entries.callback.CallBackResponseStatus)1 CallBackCountersKPIService (com.forgerock.openbanking.analytics.services.CallBackCountersKPIService)1 AggregatedPollingService (com.forgerock.openbanking.aspsp.rs.simulator.event.store.AggregatedPollingService)1 CallbackUrlsService (com.forgerock.openbanking.aspsp.rs.simulator.event.store.CallbackUrlsService)1 EventSubscriptionService (com.forgerock.openbanking.aspsp.rs.simulator.event.store.EventSubscriptionService)1 FREventSubscriptionData (com.forgerock.openbanking.common.model.openbanking.domain.event.FREventSubscriptionData)1 FRCallbackUrl (com.forgerock.openbanking.common.model.openbanking.persistence.event.FRCallbackUrl)1 FREventNotification (com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification)1 FREventSubscription (com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventSubscription)1 EventSubject (com.forgerock.openbanking.common.services.notification.EventSubject)1 EventType (com.forgerock.openbanking.common.services.notification.EventType)1 Tpp (com.forgerock.openbanking.model.Tpp)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 Slf4j (lombok.extern.slf4j.Slf4j)1 DateTime (org.joda.time.DateTime)1 Service (org.springframework.stereotype.Service)1 StringUtils (org.springframework.util.StringUtils)1