Search in sources :

Example 16 with Consent

use of net.petafuel.styx.core.xs2a.entities.Consent in project styx by petafuel.

the class BerlinGroupCS method getConsent.

@Override
public Consent getConsent(AISRequest consentGetRequest) throws BankRequestFailedException {
    this.setUrl(this.url + consentGetRequest.getServicePath());
    this.createBody(RequestType.GET);
    this.createHeaders(consentGetRequest);
    try (Response response = this.execute();
        Jsonb jsonb = JsonbBuilder.create()) {
        String responseBody = extractResponseBody(response, 200);
        Consent consentFromResponse = jsonb.fromJson(responseBody, Consent.class);
        consentFromResponse.setId(consentGetRequest.getConsentId());
        Consent consentFromDatabase = new PersistentConsent().get(consentFromResponse);
        consentFromDatabase.setAccess(consentFromResponse.getAccess());
        consentFromDatabase.setRecurringIndicator(consentFromResponse.isRecurringIndicator());
        consentFromDatabase.setValidUntil(consentFromResponse.getValidUntil());
        consentFromDatabase.setFrequencyPerDay(consentFromResponse.getFrequencyPerDay());
        consentFromDatabase.setState(consentFromResponse.getState());
        consentFromDatabase.setLastAction(consentFromResponse.getLastAction());
        return new PersistentConsent().update(consentFromDatabase);
    } catch (Exception e) {
        throw new BankRequestFailedException(e.getMessage(), e);
    }
}
Also used : Response(okhttp3.Response) Jsonb(javax.json.bind.Jsonb) Consent(net.petafuel.styx.core.xs2a.entities.Consent) PersistentConsent(net.petafuel.styx.core.persistence.layers.PersistentConsent) PersistentConsent(net.petafuel.styx.core.persistence.layers.PersistentConsent) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException) IOException(java.io.IOException) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException)

Example 17 with Consent

use of net.petafuel.styx.core.xs2a.entities.Consent in project styx by petafuel.

the class BerlinGroupCS method createConsent.

public Consent createConsent(AISRequest consentRequest) throws BankRequestFailedException {
    this.setUrl(this.url + consentRequest.getServicePath());
    this.createBody(RequestType.POST, JSON, consentRequest);
    this.createHeaders(consentRequest);
    JsonbConfig config = new JsonbConfig().withPropertyNamingStrategy(PropertyNamingStrategy.CASE_INSENSITIVE);
    try (Response response = this.execute();
        Jsonb jsonb = JsonbBuilder.create(config)) {
        String responseBody = extractResponseBody(response, 201);
        Consent consent = jsonb.fromJson(responseBody, Consent.class);
        consent.setxRequestId(UUID.fromString(consentRequest.getHeaders().get("x-request-id")));
        consent.setPsu(consentRequest.getPsu());
        // if the sca method was not set by previously parsing the body, use the bank supplied header
        consent.getSca().setApproach(SCAUtils.parseSCAApproach(consent.getLinks(), response));
        consent.setAccess(consentRequest.getConsent().getAccess());
        new PersistentConsent().create(consent);
        return consent;
    } catch (BankRequestFailedException e) {
        throw e;
    } catch (Exception e) {
        throw new BankRequestFailedException(e.getMessage(), e);
    }
}
Also used : Response(okhttp3.Response) JsonbConfig(javax.json.bind.JsonbConfig) Jsonb(javax.json.bind.Jsonb) Consent(net.petafuel.styx.core.xs2a.entities.Consent) PersistentConsent(net.petafuel.styx.core.persistence.layers.PersistentConsent) PersistentConsent(net.petafuel.styx.core.persistence.layers.PersistentConsent) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException) IOException(java.io.IOException)

Aggregations

Consent (net.petafuel.styx.core.xs2a.entities.Consent)17 PersistentConsent (net.petafuel.styx.core.persistence.layers.PersistentConsent)12 Test (org.junit.jupiter.api.Test)6 BankRequestFailedException (net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException)5 Order (org.junit.jupiter.api.Order)5 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)5 IOException (java.io.IOException)4 Jsonb (javax.json.bind.Jsonb)4 Response (okhttp3.Response)4 AISRequest (net.petafuel.styx.core.xs2a.contracts.AISRequest)3 ApplicationPath (javax.ws.rs.ApplicationPath)2 Path (javax.ws.rs.Path)2 AcceptsPreStepAuth (net.petafuel.styx.api.filter.authentication.boundary.AcceptsPreStepAuth)2 IOProcessor (net.petafuel.styx.core.ioprocessing.IOProcessor)2 PSU (net.petafuel.styx.core.xs2a.entities.PSU)2 AISRequestFactory (net.petafuel.styx.core.xs2a.factory.AISRequestFactory)2 XS2AFactoryInput (net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput)2 SQLException (java.sql.SQLException)1 UUID (java.util.UUID)1 JsonbConfig (javax.json.bind.JsonbConfig)1