Search in sources :

Example 1 with OBReadAccount1

use of uk.org.openbanking.datamodel.account.OBReadAccount1 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 OBReadAccount1

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

the class AccountsApiController method getAccount.

@Override
public ResponseEntity<OBReadAccount1> getAccount(@ApiParam(value = "A unique identifier used to identify the account resource.", required = true) @PathVariable("AccountId") String accountId, @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, @ApiParam(value = "Indicates the user-agent that the PSU is using.") @RequestHeader(value = "x-customer-user-agent", required = false) String xCustomerUserAgent, HttpServletRequest request, Principal principal) throws OBErrorResponseException {
    return RSEndpointWrapperService.<OBReadAccount1>accountAndTransactionEndpoint().authorization(authorization).xFapiFinancialId(xFapiFinancialId).accountId(accountId).principal(principal).minimumPermissions(FRExternalPermissionsCode.READACCOUNTSBASIC, FRExternalPermissionsCode.READACCOUNTSDETAIL).execute((accountRequest, permissions, pageNumber) -> {
        HttpHeaders additionalHttpHeaders = new HttpHeaders();
        additionalHttpHeaders.addAll("x-ob-permissions", permissions.stream().map(FRExternalPermissionsCode::name).collect(Collectors.toList()));
        additionalHttpHeaders.add("x-ob-url", new ServletServerHttpRequest(request).getURI().toString());
        return rsStoreGateway.toRsStore(request, additionalHttpHeaders, OBReadAccount1.class);
    });
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ServletServerHttpRequest(org.springframework.http.server.ServletServerHttpRequest) FRExternalPermissionsCode(com.forgerock.openbanking.common.model.openbanking.domain.account.common.FRExternalPermissionsCode) OBReadAccount1(uk.org.openbanking.datamodel.account.OBReadAccount1)

Aggregations

OBReadAccount1 (uk.org.openbanking.datamodel.account.OBReadAccount1)2 FRAccountRepository (com.forgerock.openbanking.aspsp.rs.store.repository.accounts.accounts.FRAccountRepository)1 PaginationUtil (com.forgerock.openbanking.aspsp.rs.store.utils.PaginationUtil)1 FRExternalPermissionsCode (com.forgerock.openbanking.common.model.openbanking.domain.account.common.FRExternalPermissionsCode)1 FRAccount (com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccount)1 FRExternalPermissionsCodeConverter.toFRExternalPermissionsCodeList (com.forgerock.openbanking.common.services.openbanking.converter.account.FRExternalPermissionsCodeConverter.toFRExternalPermissionsCodeList)1 FRFinancialAccountConverter.toOBAccount1 (com.forgerock.openbanking.common.services.openbanking.converter.account.FRFinancialAccountConverter.toOBAccount1)1 HTTP_DATE_FORMAT (com.forgerock.openbanking.constants.OpenBankingConstants.HTTP_DATE_FORMAT)1 Collections (java.util.Collections)1 List (java.util.List)1 Collectors.toList (java.util.stream.Collectors.toList)1 DateTime (org.joda.time.DateTime)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 DateTimeFormat (org.springframework.format.annotation.DateTimeFormat)1 HttpHeaders (org.springframework.http.HttpHeaders)1 ResponseEntity (org.springframework.http.ResponseEntity)1 ServletServerHttpRequest (org.springframework.http.server.ServletServerHttpRequest)1 Controller (org.springframework.stereotype.Controller)1 PathVariable (org.springframework.web.bind.annotation.PathVariable)1