use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount in project openbanking-aspsp by OpenBankingToolkit.
the class AccountsApiController method getAccounts.
@Override
public ResponseEntity<OBReadAccount1> getAccounts(@RequestParam(value = "page", defaultValue = "0") int page, @RequestHeader(value = "x-fapi-financial-id", required = true) String xFapiFinancialId, @RequestHeader(value = "Authorization", required = true) String authorization, @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-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) {
LOGGER.info("Read all accounts {} with minimumPermissions {}", accountIds, permissions);
List<FRAccount> frAccounts = frAccountRepository.byAccountIds(accountIds, toFRExternalPermissionsCodeList(permissions));
List<OBAccount1> accounts = frAccounts.stream().map(a -> toOBAccount1(a.getAccount())).collect(toList());
return ResponseEntity.ok(new OBReadAccount1().data(new OBReadDataAccount1().account(accounts)).links(PaginationUtil.generateLinksOnePager(httpUrl)).meta(PaginationUtil.generateMetaData(1)));
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount in project openbanking-aspsp by OpenBankingToolkit.
the class AccountsApiController method getAccounts.
public ResponseEntity<OBReadAccount2> getAccounts(@ApiParam(value = "Page number.", required = false, defaultValue = "0") @RequestParam(value = "page", defaultValue = "0") String page, @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 = "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, @RequestHeader(value = "x-customer-user-agent", required = false) String xCustomerUserAgent, @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("Accounts from account ids {}", accountIds);
List<OBAccount2> accounts = frAccountRepository.byAccountIds(accountIds, toFRExternalPermissionsCodeList(permissions)).stream().map(FRAccount::getAccount).map(FRFinancialAccountConverter::toOBAccount2).collect(Collectors.toList());
return ResponseEntity.ok(new OBReadAccount2().data(new OBReadAccount2Data().account(accounts)).links(PaginationUtil.generateLinksOnePager(httpUrl)).meta(PaginationUtil.generateMetaData(1)));
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount in project openbanking-aspsp by OpenBankingToolkit.
the class DomesticVrpConsentsApiController method domesticVrpConsentsFundsConfirmation.
@Override
public ResponseEntity domesticVrpConsentsFundsConfirmation(String consentId, String authorization, String xJwsSignature, OBVRPFundsConfirmationRequest obVRPFundsConfirmationRequest, String xFapiAuthDate, String xFapiCustomerIpAddress, String xFapiInteractionId, String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
log.debug("(store) Request to get a VRP funds confirmation, consentId '{}', mode test '{}'", consentId, StringUtils.hasLength(request.getHeader(OpenBankingHttpHeaders.X_OB_MODE_TEST)));
boolean areFundsAvailable = false;
// check header 'x-ob-mode-test' to restrict the behaviour for test purposes
if (StringUtils.hasLength(request.getHeader(OpenBankingHttpHeaders.X_OB_MODE_TEST))) {
areFundsAvailable = true;
} else {
Optional<FRDomesticVRPConsent> optional = domesticVRPConsentRepository.findById(consentId);
if (!optional.isPresent()) {
log.warn("(store) Domestic VRP payment consent '{}' to confirm funds can't be found", consentId);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Domestic VRP payment consent '" + consentId + "' to confirm funds can't be found");
}
FRDomesticVRPConsent domesticVrpConsent = optional.get();
if (!domesticVrpConsent.getStatus().equals(ConsentStatusCode.AUTHORISED)) {
log.error("(store) Funds confirmation for VRP payment consent Id '{}, with status '{}' can't be requested" + " because the consent status hasn't '{}'", consentId, domesticVrpConsent.getStatus().getValue(), ConsentStatusCode.AUTHORISED.getValue());
throw new OBErrorResponseException(HttpStatus.BAD_REQUEST, OBRIErrorResponseCategory.REQUEST_INVALID, OBRIErrorType.CONSENT_STATUS_NOT_AUTHORISED.toOBError1(consentId));
}
// Check if funds are available on the account selected in consent
String accountIdentification = domesticVrpConsent.getVrpDetails().getData().getInitiation().getDebtorAccount().getIdentification();
Collection<FRAccount> accountsByUserID = accountRepository.findByUserID(Objects.requireNonNull(domesticVrpConsent.getUserId()));
Optional<FRAccount> accountOptional = accountsByUserID.stream().filter(account -> account.getAccount().getAccounts().stream().filter(a -> a.getIdentification().equals(accountIdentification)).findFirst().isPresent()).findFirst();
if (!accountOptional.isPresent()) {
log.warn("(store) VRP consent '{}', debtor account with identitication '{}' can't be found", consentId, accountIdentification);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("VRP consent '" + consentId + "', debtor account with identitication '" + accountIdentification + "' to confirm funds can't be found");
}
areFundsAvailable = fundsAvailabilityService.isFundsAvailable(accountOptional.get().getId(), obVRPFundsConfirmationRequest.getData().getInstructedAmount().getAmount());
}
OBVRPFundsConfirmationRequestData data = obVRPFundsConfirmationRequest.getData();
return ResponseEntity.status(HttpStatus.OK).body(new OBVRPFundsConfirmationResponse().data(new OBVRPFundsConfirmationResponseData().fundsConfirmationId(UUID.randomUUID().toString()).consentId(consentId).creationDateTime(DateTime.now()).reference(data.getReference()).fundsAvailableResult(new OBPAFundsAvailableResult1().fundsAvailable(areFundsAvailable ? OBPAFundsAvailableResult1.FundsAvailableEnum.AVAILABLE : OBPAFundsAvailableResult1.FundsAvailableEnum.NOTAVAILABLE).fundsAvailableDateTime(DateTime.now())).instructedAmount(data.getInstructedAmount())));
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount in project openbanking-aspsp by OpenBankingToolkit.
the class AccountStoreServiceImpl method findAccountByIdentification.
@Override
public Optional findAccountByIdentification(String identification) {
ParameterizedTypeReference<Optional<FRAccount>> ptr = new ParameterizedTypeReference<Optional<FRAccount>>() {
};
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(rsStoreRoot + "/api/accounts/search/findByIdentification");
builder.queryParam("identification", identification);
URI uri = builder.build().encode().toUri();
try {
ResponseEntity<Optional<FRAccount>> entity = restTemplate.exchange(uri, HttpMethod.GET, null, ptr);
return entity.getBody();
} catch (HttpClientErrorException e) {
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
return Optional.empty();
}
throw e;
}
}
use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount in project openbanking-aspsp by OpenBankingToolkit.
the class AccountStoreServiceImpl method getAccount.
@Override
public FRAccount getAccount(String accountId) {
ParameterizedTypeReference<FRAccount> ptr = new ParameterizedTypeReference<FRAccount>() {
};
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(rsStoreRoot + "/api/accounts/" + accountId);
URI uri = builder.build().encode().toUri();
ResponseEntity<FRAccount> entity = restTemplate.exchange(uri, HttpMethod.GET, null, ptr);
return entity.getBody();
}
Aggregations