Search in sources :

Example 1 with LinkType

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

the class BerlinGroupPIS method startAuthorisation.

@Override
public /*
     * BerlinGroup 1.2: the authorisationId of an Authorisation Resource is not a json key in the start SCA Request
     * Therefore we take it out of an authorisation link that contains this id
     */
SCA startAuthorisation(SCARequest xs2ARequest) throws BankRequestFailedException {
    this.setUrl(this.url + xs2ARequest.getServicePath());
    this.createBody(RequestType.POST, JSON, xs2ARequest);
    this.createHeaders(xs2ARequest);
    try (Response response = this.execute();
        Jsonb jsonb = JsonbBuilder.create()) {
        String responseBody = extractResponseBody(response, 201);
        SCA sca = jsonb.fromJson(responseBody, SCA.class);
        SCAUtils.parseSCAApproach(sca, response);
        // extract the authorisation id out of an Href Object that contains the authorisations/... route
        for (Map.Entry<LinkType, Links.Href> entry : sca.getLinks().getUrlMapping().entrySet()) {
            if (entry.getValue().getUrl().contains("authorisations/")) {
                String[] routeParts = entry.getValue().getUrl().split("/");
                sca.setAuthorisationId(routeParts[routeParts.length - 1]);
                break;
            }
        }
        return sca;
    } catch (Exception e) {
        throw new BankRequestFailedException(e.getMessage(), e);
    }
}
Also used : Response(okhttp3.Response) SCA(net.petafuel.styx.core.xs2a.entities.SCA) Jsonb(javax.json.bind.Jsonb) LinkType(net.petafuel.styx.core.xs2a.entities.LinkType) Map(java.util.Map) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException)

Example 2 with LinkType

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

the class BerlinGroupCS method startAuthorisation.

@Override
public /*
     * BerlinGroup 1.2: the authorisationId of an Authorisation Resource is not a json key in the start SCA Request
     * Therefore we take it out of an authorisation link that contains this id
     */
SCA startAuthorisation(SCARequest xs2ARequest) throws BankRequestFailedException {
    this.setUrl(this.url + xs2ARequest.getServicePath());
    this.createBody(RequestType.POST, JSON, xs2ARequest);
    this.createHeaders(xs2ARequest);
    try (Response response = this.execute();
        Jsonb jsonb = JsonbBuilder.create()) {
        String responseBody = extractResponseBody(response, 201);
        SCA sca = jsonb.fromJson(responseBody, SCA.class);
        SCAUtils.parseSCAApproach(sca, response);
        // extract the authorisation id out of an Href Object that contains the authorisations/... route
        for (Map.Entry<LinkType, Links.Href> entry : sca.getLinks().getUrlMapping().entrySet()) {
            if (entry.getValue().getUrl().contains("authorisations/")) {
                String[] routeParts = entry.getValue().getUrl().split("/");
                sca.setAuthorisationId(routeParts[routeParts.length - 1]);
                break;
            }
        }
        return sca;
    } catch (Exception e) {
        throw new BankRequestFailedException(e.getMessage(), e);
    }
}
Also used : Response(okhttp3.Response) SCA(net.petafuel.styx.core.xs2a.entities.SCA) Jsonb(javax.json.bind.Jsonb) LinkType(net.petafuel.styx.core.xs2a.entities.LinkType) Map(java.util.Map) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException) BankRequestFailedException(net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException)

Example 3 with LinkType

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

the class HrefTypeDeserializer method deserialize.

@Override
public Links.Href deserialize(JsonParser parser, DeserializationContext ctx, Type rtType) {
    JsonValue parsedValue = parser.getValue();
    Links.Href href = new Links.Href();
    if (parsedValue instanceof JsonObject) {
        try (Jsonb jsonb = JsonbBuilder.create()) {
            href = jsonb.fromJson(parsedValue.toString(), Links.Href.class);
        } catch (Exception e) {
            LOG.error("Error trying to deserialize Href", e);
        }
    } else {
        LinkType linkType = null;
        if (parser instanceof JsonbParser) {
            JsonbParser jsonbParser = (JsonbParser) parser;
            linkType = LinkType.getByString(jsonbParser.getCurrentLevel().getLastKeyName());
        }
        href = new Links.Href(parsedValue.toString().replace("\"", ""), linkType);
    }
    return href;
}
Also used : JsonbParser(org.eclipse.yasson.internal.JsonbParser) Jsonb(javax.json.bind.Jsonb) JsonValue(javax.json.JsonValue) Links(net.petafuel.styx.core.xs2a.entities.Links) JsonObject(javax.json.JsonObject) LinkType(net.petafuel.styx.core.xs2a.entities.LinkType)

Aggregations

Jsonb (javax.json.bind.Jsonb)3 LinkType (net.petafuel.styx.core.xs2a.entities.LinkType)3 Map (java.util.Map)2 SCA (net.petafuel.styx.core.xs2a.entities.SCA)2 BankRequestFailedException (net.petafuel.styx.core.xs2a.exceptions.BankRequestFailedException)2 Response (okhttp3.Response)2 JsonObject (javax.json.JsonObject)1 JsonValue (javax.json.JsonValue)1 Links (net.petafuel.styx.core.xs2a.entities.Links)1 JsonbParser (org.eclipse.yasson.internal.JsonbParser)1