From 3e5497b33632c0919f5b856ee2bfa6c5b43e457d Mon Sep 17 00:00:00 2001 From: "miriam.baglioni" Date: Fri, 25 Sep 2020 16:33:15 +0200 Subject: [PATCH] added new method to handle an open deposition to which upload data --- .../dhp/common/api/ZenodoAPIClient.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/dhp-common/src/main/java/eu/dnetlib/dhp/common/api/ZenodoAPIClient.java b/dhp-common/src/main/java/eu/dnetlib/dhp/common/api/ZenodoAPIClient.java index 2eec1eea9..8bdd32976 100644 --- a/dhp-common/src/main/java/eu/dnetlib/dhp/common/api/ZenodoAPIClient.java +++ b/dhp-common/src/main/java/eu/dnetlib/dhp/common/api/ZenodoAPIClient.java @@ -206,6 +206,33 @@ public class ZenodoAPIClient implements Serializable { } } + public int uploadOpenDeposition(String deposition_id) throws IOException, MissingConceptDoiException { + + this.deposition_id = deposition_id; + + String json = "{}"; + + OkHttpClient httpClient = new OkHttpClient(); + + Request request = new Request.Builder() + .url(urlString + "/" + deposition_id) + .addHeader("Authorization", "Bearer " + access_token) + // .post(RequestBody.create(MEDIA_TYPE_JSON, json)) + .build(); + + try (Response response = httpClient.newCall(request).execute()) { + + if (!response.isSuccessful()) + throw new IOException("Unexpected code " + response + response.body().string()); + + ZenodoModel zenodoModel = new Gson().fromJson(response.body().string(), ZenodoModel.class); + bucket = zenodoModel.getLinks().getBucket(); + return response.code(); + + } + + } + private void setDepositionId(String concept_rec_id) throws IOException, MissingConceptDoiException { ZenodoModelList zenodoModelList = new Gson().fromJson(getPrevDepositions(), ZenodoModelList.class);