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);
}
}
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);
}
}
Aggregations