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