use of com.forgerock.openbanking.common.model.openbanking.domain.event.FREventPolling in project openbanking-aspsp by OpenBankingToolkit.
the class AggregatedPollingApiController method pollEvents.
@Override
public ResponseEntity pollEvents(@ApiParam(value = "Default", required = true) @Valid @RequestBody OBEventPolling1 obEventPolling, @ApiParam(value = "An Authorisation Token as per https://tools.ietf.org/html/rfc6750", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, @ApiParam(value = "An RFC4122 UID used as a correlation id.") @RequestHeader(value = "x-fapi-interaction-id", required = false) String xFapiInteractionId, @ApiParam(value = "The PISP Client ID") @RequestHeader(value = "x-ob-client-id", required = true) String clientId, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
final Optional<Tpp> isTpp = Optional.ofNullable(tppRepository.findByClientId(clientId));
if (isTpp.isEmpty()) {
log.warn("No TPP found for client id '{}'", clientId);
throw new OBErrorResponseException(HttpStatus.NOT_FOUND, OBRIErrorResponseCategory.REQUEST_INVALID, OBRIErrorType.TPP_NOT_FOUND.toOBError1(clientId));
}
final String tppId = isTpp.get().getId();
FREventPolling frEventPolling = toFREventPolling(obEventPolling);
log.debug("TPP '{}' sent aggregated polling request: {}", tppId, obEventPolling);
eventPollingService.acknowledgeEvents(frEventPolling, tppId);
eventPollingService.recordTppEventErrors(frEventPolling, tppId);
Map<String, String> allEventNotifications = eventPollingService.fetchNewEvents(frEventPolling, tppId);
// Apply limit on returned events
Map<String, String> truncatedEventNotifications = eventPollingService.truncateEvents(obEventPolling.getMaxEvents(), allEventNotifications, tppId);
boolean moreAvailable = truncatedEventNotifications.size() < allEventNotifications.size();
ResponseEntity<OBEventPollingResponse1> response = ResponseEntity.ok(new OBEventPollingResponse1().sets(truncatedEventNotifications).moreAvailable((truncatedEventNotifications.isEmpty()) ? null : moreAvailable));
log.debug("TPP '{}' aggregated polling response: {}", tppId, response.getBody());
return response;
}
use of com.forgerock.openbanking.common.model.openbanking.domain.event.FREventPolling in project openbanking-aspsp by OpenBankingToolkit.
the class AggregatedPollingApiController method pollEvents.
@Override
public ResponseEntity pollEvents(@ApiParam(value = "Default", required = true) @Valid @RequestBody OBEventPolling1 obEventPolling, @ApiParam(value = "An Authorisation Token as per https://tools.ietf.org/html/rfc6750", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, @ApiParam(value = "An RFC4122 UID used as a correlation id.") @RequestHeader(value = "x-fapi-interaction-id", required = false) String xFapiInteractionId, @ApiParam(value = "The PISP Client ID") @RequestHeader(value = "x-ob-client-id", required = true) String clientId, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
final Optional<Tpp> isTpp = Optional.ofNullable(tppRepository.findByClientId(clientId));
if (isTpp.isEmpty()) {
log.warn("No TPP found for client id '{}'", clientId);
throw new OBErrorResponseException(HttpStatus.NOT_FOUND, OBRIErrorResponseCategory.REQUEST_INVALID, OBRIErrorType.TPP_NOT_FOUND.toOBError1(clientId));
}
final String tppId = isTpp.get().getId();
FREventPolling frEventPolling = toFREventPolling(obEventPolling);
log.debug("TPP '{}' sent aggregated polling request: {}", tppId, obEventPolling);
eventPollingService.acknowledgeEvents(frEventPolling, tppId);
eventPollingService.recordTppEventErrors(frEventPolling, tppId);
Map<String, String> allEventNotifications = eventPollingService.fetchNewEvents(frEventPolling, tppId);
// Apply limit on returned events
Map<String, String> truncatedEventNotifications = eventPollingService.truncateEvents(obEventPolling.getMaxEvents(), allEventNotifications, tppId);
boolean moreAvailable = truncatedEventNotifications.size() < allEventNotifications.size();
ResponseEntity<OBEventPollingResponse1> response = ResponseEntity.ok(new OBEventPollingResponse1().sets(truncatedEventNotifications).moreAvailable((truncatedEventNotifications.isEmpty()) ? null : moreAvailable));
log.debug("TPP '{}' aggregated polling response: {}", tppId, response.getBody());
return response;
}
use of com.forgerock.openbanking.common.model.openbanking.domain.event.FREventPolling in project openbanking-aspsp by OpenBankingToolkit.
the class EventPollingServiceTest method recordTppEventErrors_notificationDoesNotExist_doNothing.
@Test
public void recordTppEventErrors_notificationDoesNotExist_doNothing() {
// Given
FREventPolling pollingRequest = FREventPolling.builder().setErrs(Collections.singletonMap("11111", FREventPollingError.builder().error("err1").description("error msg").build())).build();
when(mockRepo.findByTppIdAndJti(any(), any())).thenReturn(Optional.empty());
// When
eventPollingService.recordTppEventErrors(pollingRequest, TPP_ID);
// Then
verify(mockRepo, times(0)).save(any());
}
use of com.forgerock.openbanking.common.model.openbanking.domain.event.FREventPolling in project openbanking-aspsp by OpenBankingToolkit.
the class EventPollingServiceTest method fetchNewEvents_excludeEventsWithErrorsFromResults.
@Test
public void fetchNewEvents_excludeEventsWithErrorsFromResults() throws Exception {
// Given
final FREventNotification existingNotificationWithoutError = FREventNotification.builder().id("1").jti("11111").signedJwt("test111").build();
final FREventNotification existingNotificationWithError = FREventNotification.builder().id("2").jti("22222").signedJwt("test222").errors(FREventPollingError.builder().error("err1").description("error").build()).build();
when(mockRepo.findByTppId(eq(TPP_ID))).thenReturn(ImmutableList.of(existingNotificationWithoutError, existingNotificationWithError));
// When
FREventPolling pollingRequest = FREventPolling.builder().maxEvents(// Do not restrict
null).returnImmediately(true).build();
Map<String, String> eventNotifications = eventPollingService.fetchNewEvents(pollingRequest, TPP_ID);
// Then
assertThat(eventNotifications.size()).isEqualTo(1);
assertThat(eventNotifications.get("11111")).isEqualTo("test111");
}
use of com.forgerock.openbanking.common.model.openbanking.domain.event.FREventPolling in project openbanking-aspsp by OpenBankingToolkit.
the class EventPollingServiceTest method fetchNewEvents_zeroEventsRequested_returnNothing.
@Test
public void fetchNewEvents_zeroEventsRequested_returnNothing() throws Exception {
// When
FREventPolling pollingRequest = FREventPolling.builder().maxEvents(0).returnImmediately(true).build();
Map<String, String> eventNotifications = eventPollingService.fetchNewEvents(pollingRequest, TPP_ID);
// Then
assertThat(eventNotifications.size()).isEqualTo(0);
verifyZeroInteractions(mockRepo);
}
Aggregations