Search in sources :

Example 6 with FREventSubscription

use of com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventSubscription in project openbanking-aspsp by OpenBankingToolkit.

the class EventSubscriptionApiControllerIT method updateEventSubscription_olderVersion.

@Test
public void updateEventSubscription_olderVersion() {
    // Given
    springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
    String eventSubsId = UUID.randomUUID().toString();
    OBEventSubscriptionResponse1 obEventSubscription1 = new OBEventSubscriptionResponse1().data(new OBEventSubscriptionResponse1Data().eventSubscriptionId(eventSubsId).callbackUrl("http://callback/update").version(OBVersion.v3_0.getCanonicalVersion()));
    FREventSubscription frEventSubscription = FREventSubscription.builder().id(eventSubsId).eventSubscription(FREventSubscriptionData.builder().callbackUrl("http://callback").version(OBVersion.v3_1_2.getCanonicalVersion()).build()).build();
    eventSubscriptionsRepository.save(frEventSubscription);
    // When
    HttpResponse<OBEventSubscriptionResponse1> response = Unirest.put(BASE_URL + port + RESOURCE_URI + "/" + eventSubsId).header(OBHeaders.AUTHORIZATION, "token").header("x-ob-client-id", clientId).header(OBHeaders.CONTENT_TYPE, "application/json; charset=utf-8").body(obEventSubscription1).asObject(OBEventSubscriptionResponse1.class);
    log.debug("Response: {} {} , {}", response.getStatus(), response.getStatusText(), response.getBody());
    // Then
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getBody().getLinks().getSelf()).contains("/event-subscriptions");
}
Also used : FREventSubscription(com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventSubscription) SpringSecForTest(com.forgerock.openbanking.integration.test.support.SpringSecForTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with FREventSubscription

use of com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventSubscription in project openbanking-aspsp by OpenBankingToolkit.

the class EventSubscriptionApiControllerIT method updateEventSubscription.

@Test
public void updateEventSubscription() {
    // Given
    springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
    String eventSubsId = UUID.randomUUID().toString();
    OBEventSubscriptionResponse1 obEventSubscription1 = new OBEventSubscriptionResponse1().data(new OBEventSubscriptionResponse1Data().eventSubscriptionId(eventSubsId).callbackUrl("http://callback/update").version(OBVersion.v3_1.getCanonicalVersion()));
    FREventSubscription frEventSubscription = FREventSubscription.builder().id(eventSubsId).eventSubscription(FREventSubscriptionData.builder().callbackUrl("http://callback").version(OBVersion.v3_1.getCanonicalVersion()).build()).build();
    eventSubscriptionsRepository.save(frEventSubscription);
    // When
    HttpResponse<OBEventSubscriptionResponse1> response = Unirest.put(BASE_URL + port + RESOURCE_URI + "/" + eventSubsId).header(OBHeaders.AUTHORIZATION, "token").header("x-ob-client-id", clientId).header(OBHeaders.CONTENT_TYPE, "application/json; charset=utf-8").body(obEventSubscription1).asObject(OBEventSubscriptionResponse1.class);
    log.debug("Response: {} {} , {}", response.getStatus(), response.getStatusText(), response.getBody());
    // Then
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getBody().getLinks().getSelf()).contains("/event-subscriptions");
    assertThat(response.getBody().getData().getCallbackUrl()).isEqualTo("http://callback/update");
    final Optional<FREventSubscription> byId = eventSubscriptionsRepository.findById(eventSubsId);
    assertThat(byId.orElseThrow(AssertionError::new).getEventSubscription().getCallbackUrl()).isEqualTo("http://callback/update");
}
Also used : FREventSubscription(com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventSubscription) SpringSecForTest(com.forgerock.openbanking.integration.test.support.SpringSecForTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with FREventSubscription

use of com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventSubscription in project openbanking-aspsp by OpenBankingToolkit.

the class EventSubscriptionApiControllerIT method deleteEventSubscription.

@Test
public void deleteEventSubscription() {
    // Given
    springSecForTest.mockAuthCollector.mockAuthorities(OBRIRole.ROLE_PISP);
    String eventSubsId = UUID.randomUUID().toString();
    FREventSubscription frEventSubscription = FREventSubscription.builder().eventSubscription(FREventSubscriptionData.builder().version(OBVersion.v3_1_2.getCanonicalVersion()).build()).id(eventSubsId).tppId(tpp.getId()).build();
    eventSubscriptionsRepository.save(frEventSubscription);
    // When
    HttpResponse response = Unirest.delete(BASE_URL + port + RESOURCE_URI + "/" + eventSubsId).header(OBHeaders.AUTHORIZATION, "token").header("x-ob-client-id", clientId).header(OBHeaders.CONTENT_TYPE, "application/json; charset=utf-8").asObject(String.class);
    // Then
    assertThat(response.getStatus()).isEqualTo(204);
    final Optional<FREventSubscription> byId = eventSubscriptionsRepository.findById(eventSubsId);
    assertThat(byId.isPresent()).isFalse();
}
Also used : HttpResponse(kong.unirest.HttpResponse) FREventSubscription(com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventSubscription) SpringSecForTest(com.forgerock.openbanking.integration.test.support.SpringSecForTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with FREventSubscription

use of com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventSubscription 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

FREventSubscription (com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventSubscription)9 SpringSecForTest (com.forgerock.openbanking.integration.test.support.SpringSecForTest)4 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 FREventNotification (com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification)2 OBErrorResponseException (com.forgerock.openbanking.exceptions.OBErrorResponseException)2 Tpp (com.forgerock.openbanking.model.Tpp)2 HttpResponse (kong.unirest.HttpResponse)2 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 EventSubject (com.forgerock.openbanking.common.services.notification.EventSubject)1 EventType (com.forgerock.openbanking.common.services.notification.EventType)1 URI (java.net.URI)1 Collection (java.util.Collection)1