Search in sources :

Example 1 with FRAccount

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)));
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) PaginationUtil(com.forgerock.openbanking.aspsp.rs.store.utils.PaginationUtil) Logger(org.slf4j.Logger) FRAccountRepository(com.forgerock.openbanking.aspsp.rs.store.repository.accounts.accounts.FRAccountRepository) DateTime(org.joda.time.DateTime) LoggerFactory(org.slf4j.LoggerFactory) Controller(org.springframework.stereotype.Controller) OBReadDataAccount1(uk.org.openbanking.datamodel.account.OBReadDataAccount1) DateTimeFormat(org.springframework.format.annotation.DateTimeFormat) FRExternalPermissionsCodeConverter.toFRExternalPermissionsCodeList(com.forgerock.openbanking.common.services.openbanking.converter.account.FRExternalPermissionsCodeConverter.toFRExternalPermissionsCodeList) FRFinancialAccountConverter.toOBAccount1(com.forgerock.openbanking.common.services.openbanking.converter.account.FRFinancialAccountConverter.toOBAccount1) OBReadAccount1(uk.org.openbanking.datamodel.account.OBReadAccount1) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) OBExternalPermissions1Code(uk.org.openbanking.datamodel.account.OBExternalPermissions1Code) OBAccount1(uk.org.openbanking.datamodel.account.OBAccount1) HTTP_DATE_FORMAT(com.forgerock.openbanking.constants.OpenBankingConstants.HTTP_DATE_FORMAT) ResponseEntity(org.springframework.http.ResponseEntity) RequestHeader(org.springframework.web.bind.annotation.RequestHeader) Collections(java.util.Collections) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) OBReadDataAccount1(uk.org.openbanking.datamodel.account.OBReadDataAccount1) FRFinancialAccountConverter.toOBAccount1(com.forgerock.openbanking.common.services.openbanking.converter.account.FRFinancialAccountConverter.toOBAccount1) OBAccount1(uk.org.openbanking.datamodel.account.OBAccount1) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) OBReadAccount1(uk.org.openbanking.datamodel.account.OBReadAccount1)

Example 2 with FRAccount

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)));
}
Also used : FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) OBReadAccount2Data(uk.org.openbanking.datamodel.account.OBReadAccount2Data) FRFinancialAccountConverter.toOBAccount2(com.forgerock.openbanking.common.services.openbanking.converter.account.FRFinancialAccountConverter.toOBAccount2) OBAccount2(uk.org.openbanking.datamodel.account.OBAccount2) OBReadAccount2(uk.org.openbanking.datamodel.account.OBReadAccount2)

Example 3 with FRAccount

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())));
}
Also used : IntentType(com.forgerock.openbanking.common.model.openbanking.IntentType) Tpp(com.forgerock.openbanking.model.Tpp) Controller(org.springframework.stereotype.Controller) ConsentStatusEntry(com.forgerock.openbanking.analytics.model.entries.ConsentStatusEntry) FRDomesticVRPConsentConverter.toOBDomesticVRPConsentResponse(com.forgerock.openbanking.common.services.openbanking.converter.vrp.FRDomesticVRPConsentConverter.toOBDomesticVRPConsentResponse) TppRepository(com.forgerock.openbanking.repositories.TppRepository) uk.org.openbanking.datamodel.vrp(uk.org.openbanking.datamodel.vrp) HttpServletRequest(javax.servlet.http.HttpServletRequest) ConsentStatusCode(com.forgerock.openbanking.common.model.openbanking.persistence.payment.ConsentStatusCode) FRDomesticVRPConsentDetails(com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsentDetails) FRDomesticVRPConsentConverter.toFRDomesticVRPConsentDetails(com.forgerock.openbanking.common.services.openbanking.converter.vrp.FRDomesticVRPConsentConverter.toFRDomesticVRPConsentDetails) OBRIErrorResponseCategory(com.forgerock.openbanking.model.error.OBRIErrorResponseCategory) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) FundsAvailabilityService(com.forgerock.openbanking.common.services.openbanking.FundsAvailabilityService) DiscoveryConfigurationProperties(com.forgerock.openbanking.common.conf.discovery.DiscoveryConfigurationProperties) IdempotencyService.validateIdempotencyRequest(com.forgerock.openbanking.common.services.openbanking.IdempotencyService.validateIdempotencyRequest) Collection(java.util.Collection) FRAccountRepository(com.forgerock.openbanking.aspsp.rs.store.repository.accounts.accounts.FRAccountRepository) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException) DateTime(org.joda.time.DateTime) VersionPathExtractor(com.forgerock.openbanking.aspsp.rs.store.utils.VersionPathExtractor) OBRIErrorType(com.forgerock.openbanking.model.error.OBRIErrorType) UUID(java.util.UUID) Objects(java.util.Objects) HttpStatus(org.springframework.http.HttpStatus) Slf4j(lombok.extern.slf4j.Slf4j) OBDiscoveryAPILinksVrpPayment(uk.org.openbanking.datamodel.discovery.OBDiscoveryAPILinksVrpPayment) Principal(java.security.Principal) OpenBankingHttpHeaders(com.forgerock.openbanking.common.constants.OpenBankingHttpHeaders) FRDomesticVRPConsent(com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent) DomesticVRPConsentRepository(com.forgerock.openbanking.aspsp.rs.store.repository.vrp.DomesticVRPConsentRepository) Optional(java.util.Optional) ResponseEntity(org.springframework.http.ResponseEntity) ConsentMetricService(com.forgerock.openbanking.analytics.services.ConsentMetricService) ResourceLinkService(com.forgerock.openbanking.common.conf.discovery.ResourceLinkService) StringUtils(org.springframework.util.StringUtils) FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) FRDomesticVRPConsent(com.forgerock.openbanking.common.model.openbanking.persistence.vrp.FRDomesticVRPConsent) OBErrorResponseException(com.forgerock.openbanking.exceptions.OBErrorResponseException)

Example 4 with FRAccount

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;
    }
}
Also used : FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) Optional(java.util.Optional) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) URI(java.net.URI)

Example 5 with FRAccount

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();
}
Also used : FRAccount(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) URI(java.net.URI)

Aggregations

FRAccount (com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount)48 Test (org.junit.Test)31 Collections (java.util.Collections)26 Optional (java.util.Optional)25 AccountStoreService (com.forgerock.openbanking.common.services.store.account.AccountStoreService)24 FRAmount (com.forgerock.openbanking.common.model.openbanking.domain.common.FRAmount)23 RunWith (org.junit.runner.RunWith)23 InjectMocks (org.mockito.InjectMocks)23 Mock (org.mockito.Mock)23 MockitoJUnitRunner (org.mockito.junit.MockitoJUnitRunner)23 MoneyService (com.forgerock.openbanking.aspsp.rs.simulator.service.MoneyService)22 PaymentNotificationFacade (com.forgerock.openbanking.aspsp.rs.simulator.service.PaymentNotificationFacade)22 FRCreditDebitIndicator (com.forgerock.openbanking.common.model.openbanking.domain.account.common.FRCreditDebitIndicator)22 FRAccountIdentifier (com.forgerock.openbanking.common.model.openbanking.domain.common.FRAccountIdentifier)22 CurrencyConverterException (com.tunyk.currencyconverter.api.CurrencyConverterException)22 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)22 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)22 ArgumentMatchers.eq (org.mockito.ArgumentMatchers.eq)22 BDDMockito.given (org.mockito.BDDMockito.given)22 Mockito.doThrow (org.mockito.Mockito.doThrow)22