Search in sources :

Example 1 with OBReadDataTransaction1

use of uk.org.openbanking.datamodel.account.OBReadDataTransaction1 in project openbanking-aspsp by OpenBankingToolkit.

the class TransactionsApiController method getTransactions.

public ResponseEntity<OBReadTransaction1> getTransactions(@ApiParam(value = "The unique id of the ASPSP to which the request is issued. " + "The unique id will be issued by OB.", required = true) @RequestHeader(value = "x-fapi-financial-id", required = true) String xFapiFinancialId, @ApiParam(value = "Page number.", required = false, defaultValue = "0") @RequestParam(value = "page", defaultValue = "0") int page, @ApiParam(value = "An Authorisation Token as per https://tools.ietf.org/html/rfc6750", required = true) @RequestHeader(value = "Authorization", required = true) String authorization, @ApiParam(value = "The time when the PSU last logged in with the TPP.  All dates in the HTTP headers are " + "represented as RFC 7231 Full Dates. An example is below:  Sun, 10 Sep 2017 19:43:31 UTC") @RequestHeader(value = "x-fapi-customer-last-logged-time", required = false) @DateTimeFormat(pattern = HTTP_DATE_FORMAT) DateTime xFapiCustomerLastLoggedTime, @ApiParam(value = "The PSU's IP address if the PSU is currently logged in with the TPP.") @RequestHeader(value = "x-fapi-customer-ip-address", required = false) String xFapiCustomerIpAddress, @ApiParam(value = "An RFC4122 UID used as a correlation id.") @RequestHeader(value = "x-fapi-interaction-id", required = false) String xFapiInteractionId, @ApiParam(value = "The UTC ISO 8601 Date Time to filter transactions FROM  NB Time component is optional " + "- set to 00:00:00 for just Date.   The parameter must NOT have a timezone set") @RequestParam(value = FROM_BOOKING_DATE_TIME, required = false) @DateTimeFormat(pattern = BOOKED_TIME_DATE_FORMAT) DateTime fromBookingDateTime, @ApiParam(value = "The UTC ISO 8601 Date Time to filter transactions TO  NB Time component is optional " + "- set to 00:00:00 for just Date.   The parameter must NOT have a timezone set") @RequestParam(value = TO_BOOKING_DATE_TIME, required = false) @DateTimeFormat(pattern = BOOKED_TIME_DATE_FORMAT) DateTime toBookingDateTime, @RequestHeader(value = "x-customer-user-agent", required = false) String xCustomerUserAgent, @RequestHeader(value = "x-ob-first-available-date", required = false) @DateTimeFormat(pattern = AVAILABLE_DATE_FORMAT) DateTime firstAvailableDate, @RequestHeader(value = "x-ob-last-available-date", required = false) @DateTimeFormat(pattern = AVAILABLE_DATE_FORMAT) DateTime lastAvailableDate, @RequestHeader(value = "x-ob-account-ids", required = true) List<String> accountIds, @RequestHeader(value = "x-ob-permissions", required = true) List<OBExternalPermissions1Code> permissions, @RequestHeader(value = "x-ob-url", required = true) String httpUrl) throws OBErrorResponseException {
    LOGGER.info("Read transactions for accounts {} with minimumPermissions {}", accountIds, permissions);
    LOGGER.info("Reading transations from account ids {}, fromBookingDate {} toBookingDate {} " + "minimumPermissions {} pageNumber {} ", accountIds, fromBookingDateTime, toBookingDateTime, permissions, page);
    if (toBookingDateTime == null) {
        toBookingDateTime = DateTime.now();
    }
    if (fromBookingDateTime == null) {
        fromBookingDateTime = toBookingDateTime.minusYears(100);
    }
    Page<FRTransaction> transactionsResponse = frTransactionRepository.byAccountIdInAndBookingDateTimeBetweenWithPermissions(accountIds, fromBookingDateTime, toBookingDateTime, toFRExternalPermissionsCodeList(permissions), PageRequest.of(page, PAGE_LIMIT_TRANSACTIONS, Sort.Direction.ASC, "bookingDateTime"));
    List<OBTransaction1> transactions = transactionsResponse.getContent().stream().map(t -> toOBTransaction1(t.getTransaction())).collect(Collectors.toList());
    int totalPages = transactionsResponse.getTotalPages();
    return ResponseEntity.ok(new OBReadTransaction1().data(new OBReadDataTransaction1().transaction(transactions)).links(PaginationUtil.generateLinks(httpUrl, page, totalPages)).meta(PaginationUtil.generateMetaData(totalPages, firstAvailableDate, lastAvailableDate)));
}
Also used : OpenBankingConstants(com.forgerock.openbanking.constants.OpenBankingConstants) PathVariable(org.springframework.web.bind.annotation.PathVariable) FROM_BOOKING_DATE_TIME(com.forgerock.openbanking.constants.OpenBankingConstants.ParametersFieldName.FROM_BOOKING_DATE_TIME) RequestParam(org.springframework.web.bind.annotation.RequestParam) LoggerFactory(org.slf4j.LoggerFactory) ApiParam(io.swagger.annotations.ApiParam) Autowired(org.springframework.beans.factory.annotation.Autowired) Controller(org.springframework.stereotype.Controller) FRTransaction(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRTransaction) DateTimeFormat(org.springframework.format.annotation.DateTimeFormat) FRExternalPermissionsCodeConverter.toFRExternalPermissionsCodeList(com.forgerock.openbanking.common.services.openbanking.converter.account.FRExternalPermissionsCodeConverter.toFRExternalPermissionsCodeList) Value(org.springframework.beans.factory.annotation.Value) OBReadDataTransaction1(uk.org.openbanking.datamodel.account.OBReadDataTransaction1) OBExternalPermissions1Code(uk.org.openbanking.datamodel.account.OBExternalPermissions1Code) OBReadTransaction1(uk.org.openbanking.datamodel.account.OBReadTransaction1) Sort(org.springframework.data.domain.Sort) FRTransactionConverter.toOBTransaction1(com.forgerock.openbanking.common.services.openbanking.converter.account.FRTransactionConverter.toOBTransaction1) PaginationUtil(com.forgerock.openbanking.aspsp.rs.store.utils.PaginationUtil) Logger(org.slf4j.Logger) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) DateTime(org.joda.time.DateTime) PageRequest(org.springframework.data.domain.PageRequest) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) List(java.util.List) FRTransactionRepository(com.forgerock.openbanking.aspsp.rs.store.repository.accounts.transactions.FRTransactionRepository) OBTransaction1(uk.org.openbanking.datamodel.account.OBTransaction1) ResponseEntity(org.springframework.http.ResponseEntity) RequestHeader(org.springframework.web.bind.annotation.RequestHeader) TO_BOOKING_DATE_TIME(com.forgerock.openbanking.constants.OpenBankingConstants.ParametersFieldName.TO_BOOKING_DATE_TIME) OBReadDataTransaction1(uk.org.openbanking.datamodel.account.OBReadDataTransaction1) FRTransaction(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRTransaction) OBReadTransaction1(uk.org.openbanking.datamodel.account.OBReadTransaction1) FRTransactionConverter.toOBTransaction1(com.forgerock.openbanking.common.services.openbanking.converter.account.FRTransactionConverter.toOBTransaction1) OBTransaction1(uk.org.openbanking.datamodel.account.OBTransaction1)

Example 2 with OBReadDataTransaction1

use of uk.org.openbanking.datamodel.account.OBReadDataTransaction1 in project openbanking-aspsp by OpenBankingToolkit.

the class TransactionsApiController method getAccountTransactions.

@Override
public ResponseEntity getAccountTransactions(@PathVariable("AccountId") String accountId, @RequestParam(value = "page", defaultValue = "0") int page, @RequestHeader(value = "x-fapi-financial-id", required = true) String xFapiFinancialId, @RequestHeader(value = "Authorization", required = true) String authorization, @RequestParam(value = FROM_BOOKING_DATE_TIME, required = false) @DateTimeFormat(pattern = BOOKED_TIME_DATE_FORMAT) DateTime fromBookingDateTime, @RequestParam(value = TO_BOOKING_DATE_TIME, required = false) @DateTimeFormat(pattern = BOOKED_TIME_DATE_FORMAT) DateTime toBookingDateTime, @RequestHeader(value = "x-fapi-customer-last-logged-time", required = false) @DateTimeFormat(pattern = HTTP_DATE_FORMAT) DateTime xFapiCustomerLastLoggedTime, @RequestHeader(value = "x-fapi-customer-ip-address", required = false) String xFapiCustomerIpAddress, @RequestHeader(value = "x-fapi-interaction-id", required = false) String xFapiInteractionId, @RequestHeader(value = "x-customer-user-agent", required = false) String xCustomerUserAgent, @RequestHeader(value = "x-ob-first-available-date", required = false) @DateTimeFormat(pattern = AVAILABLE_DATE_FORMAT) DateTime firstAvailableDate, @RequestHeader(value = "x-ob-last-available-date", required = false) @DateTimeFormat(pattern = AVAILABLE_DATE_FORMAT) DateTime lastAvailableDate, @RequestHeader(value = "x-ob-permissions", required = true) List<OBExternalPermissions1Code> permissions, @RequestHeader(value = "x-ob-url", required = true) String httpUrl) {
    LOGGER.info("Read transactions for account  {} with minimumPermissions {}", accountId, permissions);
    LOGGER.debug("transactionStore request transactionFrom {} transactionTo {} ", fromBookingDateTime, toBookingDateTime);
    if (toBookingDateTime == null) {
        toBookingDateTime = DateTime.now();
    }
    if (fromBookingDateTime == null) {
        fromBookingDateTime = toBookingDateTime.minusYears(100);
    }
    Page<FRTransaction> transactionsResponse = frTransactionRepository.byAccountIdAndBookingDateTimeBetweenWithPermissions(accountId, fromBookingDateTime, toBookingDateTime, toFRExternalPermissionsCodeList(permissions), PageRequest.of(page, PAGE_LIMIT_TRANSACTIONS, Sort.Direction.ASC, "bookingDateTime"));
    List<OBTransaction1> transactions = transactionsResponse.getContent().stream().map(t -> toOBTransaction1(t.getTransaction())).collect(Collectors.toList());
    int totalPages = transactionsResponse.getTotalPages();
    return ResponseEntity.ok(new OBReadTransaction1().data(new OBReadDataTransaction1().transaction(transactions)).links(PaginationUtil.generateLinks(httpUrl, page, totalPages)).meta(PaginationUtil.generateMetaData(totalPages, firstAvailableDate, lastAvailableDate)));
}
Also used : OpenBankingConstants(com.forgerock.openbanking.constants.OpenBankingConstants) PathVariable(org.springframework.web.bind.annotation.PathVariable) FROM_BOOKING_DATE_TIME(com.forgerock.openbanking.constants.OpenBankingConstants.ParametersFieldName.FROM_BOOKING_DATE_TIME) RequestParam(org.springframework.web.bind.annotation.RequestParam) LoggerFactory(org.slf4j.LoggerFactory) ApiParam(io.swagger.annotations.ApiParam) Autowired(org.springframework.beans.factory.annotation.Autowired) Controller(org.springframework.stereotype.Controller) FRTransaction(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRTransaction) DateTimeFormat(org.springframework.format.annotation.DateTimeFormat) FRExternalPermissionsCodeConverter.toFRExternalPermissionsCodeList(com.forgerock.openbanking.common.services.openbanking.converter.account.FRExternalPermissionsCodeConverter.toFRExternalPermissionsCodeList) Value(org.springframework.beans.factory.annotation.Value) OBReadDataTransaction1(uk.org.openbanking.datamodel.account.OBReadDataTransaction1) OBExternalPermissions1Code(uk.org.openbanking.datamodel.account.OBExternalPermissions1Code) OBReadTransaction1(uk.org.openbanking.datamodel.account.OBReadTransaction1) Sort(org.springframework.data.domain.Sort) FRTransactionConverter.toOBTransaction1(com.forgerock.openbanking.common.services.openbanking.converter.account.FRTransactionConverter.toOBTransaction1) PaginationUtil(com.forgerock.openbanking.aspsp.rs.store.utils.PaginationUtil) Logger(org.slf4j.Logger) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) DateTime(org.joda.time.DateTime) PageRequest(org.springframework.data.domain.PageRequest) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) List(java.util.List) FRTransactionRepository(com.forgerock.openbanking.aspsp.rs.store.repository.accounts.transactions.FRTransactionRepository) OBTransaction1(uk.org.openbanking.datamodel.account.OBTransaction1) ResponseEntity(org.springframework.http.ResponseEntity) RequestHeader(org.springframework.web.bind.annotation.RequestHeader) TO_BOOKING_DATE_TIME(com.forgerock.openbanking.constants.OpenBankingConstants.ParametersFieldName.TO_BOOKING_DATE_TIME) OBReadDataTransaction1(uk.org.openbanking.datamodel.account.OBReadDataTransaction1) FRTransaction(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRTransaction) OBReadTransaction1(uk.org.openbanking.datamodel.account.OBReadTransaction1) FRTransactionConverter.toOBTransaction1(com.forgerock.openbanking.common.services.openbanking.converter.account.FRTransactionConverter.toOBTransaction1) OBTransaction1(uk.org.openbanking.datamodel.account.OBTransaction1)

Aggregations

FRTransactionRepository (com.forgerock.openbanking.aspsp.rs.store.repository.accounts.transactions.FRTransactionRepository)2 PaginationUtil (com.forgerock.openbanking.aspsp.rs.store.utils.PaginationUtil)2 FRTransaction (com.forgerock.openbanking.common.model.openbanking.persistence.account.FRTransaction)2 FRExternalPermissionsCodeConverter.toFRExternalPermissionsCodeList (com.forgerock.openbanking.common.services.openbanking.converter.account.FRExternalPermissionsCodeConverter.toFRExternalPermissionsCodeList)2 FRTransactionConverter.toOBTransaction1 (com.forgerock.openbanking.common.services.openbanking.converter.account.FRTransactionConverter.toOBTransaction1)2 OpenBankingConstants (com.forgerock.openbanking.constants.OpenBankingConstants)2 FROM_BOOKING_DATE_TIME (com.forgerock.openbanking.constants.OpenBankingConstants.ParametersFieldName.FROM_BOOKING_DATE_TIME)2 TO_BOOKING_DATE_TIME (com.forgerock.openbanking.constants.OpenBankingConstants.ParametersFieldName.TO_BOOKING_DATE_TIME)2 OBErrorResponseException (com.forgerock.openbanking.exceptions.OBErrorResponseException)2 ApiParam (io.swagger.annotations.ApiParam)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 DateTime (org.joda.time.DateTime)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Value (org.springframework.beans.factory.annotation.Value)2 Page (org.springframework.data.domain.Page)2 PageRequest (org.springframework.data.domain.PageRequest)2 Sort (org.springframework.data.domain.Sort)2