use of uk.org.openbanking.datamodel.account.OBTransaction6 in project openbanking-aspsp by OpenBankingToolkit.
the class TransactionsApiController method getTransactions.
@Override
public ResponseEntity<OBReadTransaction6> getTransactions(int page, String authorization, DateTime xFapiAuthDate, DateTime fromBookingDateTime, DateTime toBookingDateTime, DateTime firstAvailableDate, DateTime lastAvailableDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, List<String> accountIds, List<OBExternalPermissions1Code> permissions, String httpUrl) throws OBErrorResponseException {
log.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> body = FRTransactionRepository.byAccountIdInAndBookingDateTimeBetweenWithPermissions(accountIds, fromBookingDateTime, toBookingDateTime, toFRExternalPermissionsCodeList(permissions), PageRequest.of(page, pageLimitTransactions, Sort.Direction.ASC, "bookingDateTime"));
List<OBTransaction6> transactions = body.getContent().stream().map(FRTransaction::getTransaction).map(FRTransactionConverter::toOBTransaction6).map(t -> accountDataInternalIdFilter.apply(t)).collect(Collectors.toList());
// Package the answer
int totalPages = body.getTotalPages();
return ResponseEntity.ok(new OBReadTransaction6().data(new OBReadDataTransaction6().transaction(transactions)).links(PaginationUtil.generateLinks(httpUrl, page, totalPages)).meta(PaginationUtil.generateMetaData(totalPages, firstAvailableDate, lastAvailableDate)));
}
use of uk.org.openbanking.datamodel.account.OBTransaction6 in project openbanking-aspsp by OpenBankingToolkit.
the class DataCreator method createTransactions.
List<FRTransaction> createTransactions(FRAccountData accountData, Set<String> accountIds) {
List<FRTransaction> transactions = new ArrayList<>();
for (OBTransaction6 obTransaction : accountData.getTransactions()) {
String accountId = obTransaction.getAccountId() != null ? obTransaction.getAccountId() : accountData.getAccount().getAccountId();
if (!accountIds.contains(accountId)) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Must specify and own the account ID to update");
}
obTransaction.setAccountId(accountId);
obTransaction.setTransactionId(UUID.randomUUID().toString());
FRTransaction transaction = new FRTransaction();
transaction.setAccountId(obTransaction.getAccountId());
transaction.setBookingDateTime(obTransaction.getBookingDateTime());
transaction.setTransaction(toFRTransactionData(obTransaction));
transaction.setId(obTransaction.getTransactionId());
transactions.add(transaction);
}
if (transactionRepository.countByAccountIdIn(accountIds) + transactions.size() > documentLimit) {
throw new ResponseStatusException(HttpStatus.PAYLOAD_TOO_LARGE, String.format("Cannot add transactions as it has exceeded maximum limit of %s", documentLimit));
}
return transactionRepository.saveAll(transactions);
}
use of uk.org.openbanking.datamodel.account.OBTransaction6 in project openbanking-aspsp by OpenBankingToolkit.
the class TransactionsApiController method getAccountTransactions.
@Override
public ResponseEntity<OBReadTransaction6> getAccountTransactions(String accountId, int page, String authorization, DateTime xFapiAuthDate, DateTime fromBookingDateTime, DateTime toBookingDateTime, DateTime firstAvailableDate, DateTime lastAvailableDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, List<OBExternalPermissions1Code> permissions, String httpUrl) throws OBErrorResponseException {
log.info("Read transactions for account {} with minimumPermissions {}", accountId, permissions);
log.debug("transactionStore request transactionFrom {} transactionTo {} ", fromBookingDateTime, toBookingDateTime);
if (toBookingDateTime == null) {
toBookingDateTime = DateTime.now();
}
if (fromBookingDateTime == null) {
fromBookingDateTime = toBookingDateTime.minusYears(100);
}
Page<FRTransaction> response = FRTransactionRepository.byAccountIdAndBookingDateTimeBetweenWithPermissions(accountId, fromBookingDateTime, toBookingDateTime, toFRExternalPermissionsCodeList(permissions), PageRequest.of(page, pageLimitTransactions, Sort.Direction.ASC, "bookingDateTime"));
List<OBTransaction6> transactions = response.getContent().stream().map(FRTransaction::getTransaction).map(FRTransactionConverter::toOBTransaction6).map(t -> accountDataInternalIdFilter.apply(t)).collect(Collectors.toList());
// Package the answer
int totalPages = response.getTotalPages();
return ResponseEntity.ok(new OBReadTransaction6().data(new OBReadDataTransaction6().transaction(transactions)).links(PaginationUtil.generateLinks(httpUrl, page, totalPages)).meta(PaginationUtil.generateMetaData(totalPages, firstAvailableDate, lastAvailableDate)));
}
use of uk.org.openbanking.datamodel.account.OBTransaction6 in project openbanking-aspsp by OpenBankingToolkit.
the class TransactionsApiController method getAccountStatementTransactions.
@Override
public ResponseEntity<OBReadTransaction6> getAccountStatementTransactions(String statementId, String accountId, int page, String authorization, DateTime xFapiAuthDate, DateTime fromBookingDateTime, DateTime toBookingDateTime, DateTime firstAvailableDate, DateTime lastAvailableDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, List<OBExternalPermissions1Code> permissions, String httpUrl) throws OBErrorResponseException {
log.info("Reading transations from account id {}, statement id {}, fromBookingDate {} toBookingDate {} " + "minimumPermissions {} pageNumber {} ", accountId, statementId, fromBookingDateTime, toBookingDateTime, permissions, page);
if (toBookingDateTime == null) {
toBookingDateTime = DateTime.now();
}
if (fromBookingDateTime == null) {
fromBookingDateTime = toBookingDateTime.minusYears(100);
}
Page<FRTransaction> response = FRTransactionRepository.byAccountIdAndStatementIdAndBookingDateTimeBetweenWithPermissions(accountId, statementId, fromBookingDateTime, toBookingDateTime, toFRExternalPermissionsCodeList(permissions), PageRequest.of(page, pageLimitTransactions, Sort.Direction.ASC, "bookingDateTime"));
List<OBTransaction6> transactions = response.getContent().stream().map(FRTransaction::getTransaction).map(FRTransactionConverter::toOBTransaction6).map(t -> accountDataInternalIdFilter.apply(t)).collect(Collectors.toList());
// Package the answer
int totalPages = response.getTotalPages();
return ResponseEntity.ok(new OBReadTransaction6().data(new OBReadDataTransaction6().transaction(transactions)).links(PaginationUtil.generateLinks(httpUrl, page, totalPages)).meta(PaginationUtil.generateMetaData(totalPages, firstAvailableDate, lastAvailableDate)));
}
Aggregations