Search in sources :

Example 11 with FREventNotification

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

the class AggregatedPollingApiControllerIT method pollEvents_twoEvents_allRequested.

@Test
public void pollEvents_twoEvents_allRequested() {
    // Given
    OBEventPolling1 obEventPolling = new OBEventPolling1().maxEvents(// All
    null).returnImmediately(true);
    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(2);
}
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 12 with FREventNotification

use of com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification 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");
}
Also used : FREventNotification(com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification) FREventPolling(com.forgerock.openbanking.common.model.openbanking.domain.event.FREventPolling) Test(org.junit.Test)

Example 13 with FREventNotification

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

the class DataEventsApiController method updateEvents.

/**
 * Update events
 * @param eventsToUpdate list of {@link FREventNotification} to update
 * @param frDataEvent the entity body {@link FRDataEvent}
 * @throws {@link OBErrorResponseException}
 */
private void updateEvents(List<FREventNotification> eventsToUpdate, FRDataEvent frDataEvent) throws OBErrorResponseException {
    try {
        frDataEvent.getObEventNotification2List().forEach(fde -> {
            Optional<FREventNotification> optionalFREventNotification = eventsToUpdate.stream().filter(e -> e.getJti().equals(fde.getJti())).findFirst();
            if (optionalFREventNotification.isEmpty()) {
                log.error("Error updating the events, the jti set in the request not match with any existing event");
                throw new RuntimeException(new OBErrorResponseException(OBRIErrorType.DATA_INVALID_REQUEST.getHttpStatus(), OBRIErrorResponseCategory.REQUEST_INVALID, OBRIErrorType.DATA_INVALID_REQUEST.toOBError1("The jti set in the request not match with any existing event")));
            }
            try {
                FREventNotification frEventNotification = optionalFREventNotification.get();
                frEventNotification.setSignedJwt(signPayload(fde));
                frPendingEventsRepository.save(frEventNotification);
            } catch (OBErrorException obErrorException) {
                throw new RuntimeException(obErrorException);
            }
        });
    } catch (RuntimeException exception) {
        throw handleError(exception);
    }
}
Also used : RequestParam(org.springframework.web.bind.annotation.RequestParam) java.util(java.util) AMOpenBankingConfiguration(com.forgerock.openbanking.am.config.AMOpenBankingConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) JWTClaimsSet(com.nimbusds.jwt.JWTClaimsSet) Autowired(org.springframework.beans.factory.annotation.Autowired) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) OBRIErrorType(com.forgerock.openbanking.model.error.OBRIErrorType) Controller(org.springframework.stereotype.Controller) FRPendingEventsRepository(com.forgerock.openbanking.aspsp.rs.store.repository.events.FRPendingEventsRepository) OBErrorException(com.forgerock.openbanking.exceptions.OBErrorException) RequestBody(org.springframework.web.bind.annotation.RequestBody) JSONObjectUtils(com.nimbusds.jose.util.JSONObjectUtils) HttpStatus(org.springframework.http.HttpStatus) Slf4j(lombok.extern.slf4j.Slf4j) OBEventNotification2(com.forgerock.openbanking.common.model.data.OBEventNotification2) CryptoApiClient(com.forgerock.openbanking.jwt.services.CryptoApiClient) FRDataEvent(com.forgerock.openbanking.common.model.data.FRDataEvent) ResponseEntity(org.springframework.http.ResponseEntity) FREventNotification(com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification) ParseException(java.text.ParseException) OBRIErrorResponseCategory(com.forgerock.openbanking.model.error.OBRIErrorResponseCategory) FREventNotification(com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) OBErrorException(com.forgerock.openbanking.exceptions.OBErrorException)

Example 14 with FREventNotification

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

the class DataEventsApiController method createEvents.

/**
 * Create new events
 * @param frDataEvent the entity body {@link FRDataEvent}
 */
private void createEvents(FRDataEvent frDataEvent) {
    frDataEvent.getObEventNotification2List().forEach(e -> {
        try {
            FREventNotification frEventNotification = FREventNotification.builder().jti(UUID.randomUUID().toString()).signedJwt(signPayload(e)).tppId(frDataEvent.getTppId()).build();
            log.debug("Create event notification {}", frEventNotification);
            frPendingEventsRepository.save(frEventNotification);
            frDataEvent.setJti(frEventNotification.getJti());
        } catch (OBErrorException obErrorException) {
            throw new RuntimeException(obErrorException);
        }
    });
}
Also used : FREventNotification(com.forgerock.openbanking.common.model.openbanking.persistence.event.FREventNotification) OBErrorException(com.forgerock.openbanking.exceptions.OBErrorException)

Example 15 with FREventNotification

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

the class AggregatedPollingApiControllerIT method pollEvents_twoEvents_twoRequested.

@Test
public void pollEvents_twoEvents_twoRequested() {
    // Given
    OBEventPolling1 obEventPolling = new OBEventPolling1().maxEvents(2);
    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(2);
}
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