Search in sources :

Example 6 with FREventNotification

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

the class EventNotificationService method createAndSendNotification.

public void createAndSendNotification(EventSubject eventSubject, Tpp tpp, EventType eventType) throws CallbackFailedException {
    // Create a notification
    FREventNotification eventNotification = signedJwtEventBuilder.build(tpp, eventSubject, eventType);
    if (eventNotification == null || StringUtils.isEmpty(eventNotification.getSignedJwt())) {
        log.error("Failed to generate JWT for event notification due to null or empty JWT: {}. Aborting the callback to TPPs", eventNotification);
        throw new CallbackFailedException("Failed to generate JWT for event notification due to null or empty JWT");
    }
    log.debug("Built an event notification with signed jwt: {}", eventNotification);
    // Check event subscription exists
    Optional<FREventSubscription> eventSubscriptions = eventSubscriptionService.findByTppId(tpp.getId()).stream().findFirst();
    if (eventSubscriptions.isPresent()) {
        // Event subscription exists to use this to notify
        notifyToEventSubscription(tpp, eventSubscriptions.get(), eventNotification, eventSubject, eventType);
    } else {
        // Event subscription does not exist to try legacy callback URL if present
        notifyToLegacyCallbackUrl(tpp, eventNotification, eventSubject, eventType);
    }
}
Also used : FREventNotification(com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification) FREventSubscription(com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventSubscription)

Example 7 with FREventNotification

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

the class DataEventsApiControllerIT method whenValidInput_thenReturnEventsUpdated.

@Test
public void whenValidInput_thenReturnEventsUpdated() throws Exception {
    MvcResult result = mockMvc.perform(post(URL_CONTEXT).contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(createFRDataEvent()))).andExpect(status().isCreated()).andExpect(jsonPath("$[0].tppId").value(TPP)).andReturn();
    String jti = objectMapper.readValue(result.getResponse().getContentAsString(), FREventNotification[].class)[0].getJti();
    FRDataEvent frDataEvent = createFRDataEvent();
    frDataEvent.getObEventNotification2List().get(0).setJti(jti);
    mockMvc.perform(put(URL_CONTEXT).contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(frDataEvent))).andExpect(status().isOk()).andExpect(jsonPath("$[0].tppId").value(TPP));
    // delete event created
    mockMvc.perform(delete(URL_CONTEXT).contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(new FRDataEvent().tppId(TPP)))).andExpect(status().isNoContent());
}
Also used : FREventNotification(com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification) MvcResult(org.springframework.test.web.servlet.MvcResult) FRDataEvent(com.forgerock.openbanking.common.model.data.FRDataEvent) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with FREventNotification

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

the class AggregatedPollingApiControllerIT method pollEvents_ackExistingEvent_requestOneMore.

@Test
public void pollEvents_ackExistingEvent_requestOneMore() {
    OBEventPolling1 obEventPolling = new OBEventPolling1().maxEvents(1).ack(Collections.singletonList("jti1"));
    FREventNotification frEventNotification1 = FREventNotification.builder().jti("jti1").signedJwt("e23239709rdg790").tppId(tpp.getId()).build();
    frPendingEventsRepository.save(frEventNotification1);
    FREventNotification frEventNotification2 = FREventNotification.builder().jti("jti2").signedJwt("o78o7tefkwjg").tppId(tpp.getId()).build();
    frPendingEventsRepository.save(frEventNotification2);
    // When
    HttpResponse<OBEventPollingResponse1> response = Unirest.post(BASE_URL + port + RESOURCE_URI).header(OBHeaders.AUTHORIZATION, "token").header("x-ob-client-id", clientId).header(OBHeaders.CONTENT_TYPE, "application/json; charset=utf-8").body(obEventPolling).asObject(OBEventPollingResponse1.class);
    log.debug("Response: {} {} , {}", response.getStatus(), response.getStatusText(), response.getBody());
    // Then
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getBody().isMoreAvailable()).isFalse();
    assertThat(response.getBody().getSets().size()).isEqualTo(1);
    // Check acknowledged is deleted
    assertThat(frPendingEventsRepository.findByTppIdAndJti(tpp.getId(), frEventNotification1.getJti()).isEmpty()).isTrue();
}
Also used : FREventNotification(com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification) OBEventPollingResponse1(uk.org.openbanking.datamodel.event.OBEventPollingResponse1) OBEventPolling1(uk.org.openbanking.datamodel.event.OBEventPolling1) SpringSecForTest(com.forgerock.openbanking.integration.test.support.SpringSecForTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with FREventNotification

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

the class AggregatedPollingApiControllerIT method pollEvents_oneEvents_twoRequested_moreAvailable.

@Test
public void pollEvents_oneEvents_twoRequested_moreAvailable() {
    // Given
    OBEventPolling1 obEventPolling = new OBEventPolling1().maxEvents(1);
    FREventNotification frEventNotification1 = FREventNotification.builder().jti("jti1").signedJwt("e23239709rdg790").tppId(tpp.getId()).build();
    frPendingEventsRepository.save(frEventNotification1);
    FREventNotification frEventNotification2 = FREventNotification.builder().jti("jti2").signedJwt("o78o7tefkwjg").tppId(tpp.getId()).build();
    frPendingEventsRepository.save(frEventNotification2);
    // When
    HttpResponse<OBEventPollingResponse1> response = Unirest.post(BASE_URL + port + RESOURCE_URI).header(OBHeaders.AUTHORIZATION, "token").header("x-ob-client-id", clientId).header(OBHeaders.CONTENT_TYPE, "application/json; charset=utf-8").body(obEventPolling).asObject(OBEventPollingResponse1.class);
    log.debug("Response: {} {} , {}", response.getStatus(), response.getStatusText(), response.getBody());
    // Then
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getBody().isMoreAvailable()).isTrue();
    assertThat(response.getBody().getSets().size()).isEqualTo(1);
}
Also used : FREventNotification(com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification) OBEventPollingResponse1(uk.org.openbanking.datamodel.event.OBEventPollingResponse1) OBEventPolling1(uk.org.openbanking.datamodel.event.OBEventPolling1) SpringSecForTest(com.forgerock.openbanking.integration.test.support.SpringSecForTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with FREventNotification

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

the class AggregatedPollingApiControllerIT method pollEvents_ackExistingEvent_requestNone.

@Test
public void pollEvents_ackExistingEvent_requestNone() {
    OBEventPolling1 obEventPolling = new OBEventPolling1().maxEvents(0).ack(Collections.singletonList("jti1"));
    FREventNotification frEventNotification1 = FREventNotification.builder().jti("jti1").signedJwt("e23239709rdg790").tppId(tpp.getId()).build();
    frPendingEventsRepository.save(frEventNotification1);
    FREventNotification frEventNotification2 = FREventNotification.builder().jti("jti2").signedJwt("o78o7tefkwjg").tppId(tpp.getId()).build();
    frPendingEventsRepository.save(frEventNotification2);
    // When
    HttpResponse<OBEventPollingResponse1> response = Unirest.post(BASE_URL + port + RESOURCE_URI).header(OBHeaders.AUTHORIZATION, "token").header("x-ob-client-id", clientId).header(OBHeaders.CONTENT_TYPE, "application/json; charset=utf-8").body(obEventPolling).asObject(OBEventPollingResponse1.class);
    log.debug("Response: {} {} , {}", response.getStatus(), response.getStatusText(), response.getBody());
    // Then
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(response.getBody().getSets().isEmpty()).isTrue();
    // Check acknowledged is deleted
    assertThat(frPendingEventsRepository.findByTppIdAndJti(tpp.getId(), frEventNotification1.getJti()).isEmpty()).isTrue();
}
Also used : FREventNotification(com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification) OBEventPollingResponse1(uk.org.openbanking.datamodel.event.OBEventPollingResponse1) OBEventPolling1(uk.org.openbanking.datamodel.event.OBEventPolling1) SpringSecForTest(com.forgerock.openbanking.integration.test.support.SpringSecForTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

FREventNotification (com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification)21 Test (org.junit.Test)17 EventSubject (com.forgerock.openbanking.common.services.notification.EventSubject)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 SpringSecForTest (com.forgerock.openbanking.integration.test.support.SpringSecForTest)6 OBEventPolling1 (uk.org.openbanking.datamodel.event.OBEventPolling1)6 OBEventPollingResponse1 (uk.org.openbanking.datamodel.event.OBEventPollingResponse1)6 FREventPolling (com.forgerock.openbanking.common.model.openbanking.domain.event.FREventPolling)3 FRDataEvent (com.forgerock.openbanking.common.model.data.FRDataEvent)2 FREventSubscription (com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventSubscription)2 OBErrorException (com.forgerock.openbanking.exceptions.OBErrorException)2 Slf4j (lombok.extern.slf4j.Slf4j)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 AMOpenBankingConfiguration (com.forgerock.openbanking.am.config.AMOpenBankingConfiguration)1 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