Search in sources :

Example 16 with FRAccountRequest

use of com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccountRequest in project openbanking-aspsp by OpenBankingToolkit.

the class AccountRequestsApiController method deleteAccountRequest.

@Override
public ResponseEntity deleteAccountRequest(@ApiParam(value = "Unique identification as assigned by the ASPSP to uniquely identify the account request resource.", required = true) @PathVariable("AccountRequestId") String accountRequestId, @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 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 = "Indicates the user-agent that the PSU is using.") @RequestHeader(value = "x-customer-user-agent", required = false) String xCustomerUserAgent) throws OBErrorResponseException {
    Optional<FRAccountRequest> accountRequest = frAccountRequestRepository.findByAccountRequestId(accountRequestId);
    if (!accountRequest.isPresent()) {
        return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Account request '" + accountRequestId + "' not found");
    }
    LOGGER.debug("Account request revoked with id {}", accountRequestId);
    FRAccountRequest frAccountRequest = accountRequest.get();
    frAccountRequest.getAccountRequest().getData().setStatus(FRExternalRequestStatusCode.REVOKED);
    consentMetricService.sendConsentActivity(new ConsentStatusEntry(frAccountRequest.getAccountRequest().getData().getAccountRequestId(), frAccountRequest.getAccountRequest().getData().getStatus().name()));
    frAccountRequestRepository.save(frAccountRequest);
    LOGGER.debug("Account request revoked");
    return ResponseEntity.ok("Account request '" + accountRequestId + "' deleted");
}
Also used : FRAccountRequest(com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccountRequest) ConsentStatusEntry(com.forgerock.openbanking.analytics.model.entries.ConsentStatusEntry)

Aggregations

FRAccountRequest (com.forgerock.openbanking.common.model.openbanking.persistence.account.FRAccountRequest)16 Test (org.junit.Test)6 Tpp (com.forgerock.openbanking.model.Tpp)4 OBErrorException (com.forgerock.openbanking.exceptions.OBErrorException)3 X509Authentication (com.forgerock.spring.security.multiauth.model.authentication.X509Authentication)3 Authentication (org.springframework.security.core.Authentication)3 ConsentStatusEntry (com.forgerock.openbanking.analytics.model.entries.ConsentStatusEntry)2 FRReadResponseConverter.toOBReadResponse1 (com.forgerock.openbanking.common.services.openbanking.converter.account.FRReadResponseConverter.toOBReadResponse1)1 URI (java.net.URI)1 Optional (java.util.Optional)1 ParameterizedTypeReference (org.springframework.core.ParameterizedTypeReference)1 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)1 OBReadDataResponse1 (uk.org.openbanking.datamodel.account.OBReadDataResponse1)1 OBReadResponse1 (uk.org.openbanking.datamodel.account.OBReadResponse1)1