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