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);
}
}
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());
}
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();
}
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);
}
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();
}
Aggregations