From c7f944a53347762ad4f7f9a36b4e98c31e5c8a96 Mon Sep 17 00:00:00 2001 From: "miriam.baglioni" Date: Wed, 19 Aug 2020 10:01:26 +0200 Subject: [PATCH] refactoring due to compilation --- .../api/MissingConceptDoiException.java | 7 ++- .../dhp/common/api/ZenodoAPIClient.java | 57 ++++++++++--------- .../common/api/zenodo/ZenodoModelList.java | 1 + .../dump/oaf/community/CommunityInstance.java | 4 ++ .../schema/dump/oaf/graph/GraphResult.java | 4 ++ 5 files changed, 43 insertions(+), 30 deletions(-) create mode 100644 dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/dump/oaf/community/CommunityInstance.java create mode 100644 dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/dump/oaf/graph/GraphResult.java diff --git a/dhp-common/src/main/java/eu/dnetlib/dhp/common/api/MissingConceptDoiException.java b/dhp-common/src/main/java/eu/dnetlib/dhp/common/api/MissingConceptDoiException.java index f2160d4f2..b75872eb4 100644 --- a/dhp-common/src/main/java/eu/dnetlib/dhp/common/api/MissingConceptDoiException.java +++ b/dhp-common/src/main/java/eu/dnetlib/dhp/common/api/MissingConceptDoiException.java @@ -1,7 +1,8 @@ + package eu.dnetlib.dhp.common.api; public class MissingConceptDoiException extends Throwable { - public MissingConceptDoiException(String message) { - super(message); - } + public MissingConceptDoiException(String message) { + super(message); + } } 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 eebb14b17..2eec1eea9 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 @@ -12,14 +12,12 @@ import okhttp3.*; public class ZenodoAPIClient implements Serializable { - String urlString; String bucket; String deposition_id; String access_token; - public static final MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json; charset=utf-8"); private static final MediaType MEDIA_TYPE_ZIP = MediaType.parse("application/zip"); @@ -40,7 +38,9 @@ public class ZenodoAPIClient implements Serializable { this.bucket = bucket; } - public void setDeposition_id(String deposition_id){this.deposition_id = deposition_id;} + public void setDeposition_id(String deposition_id) { + this.deposition_id = deposition_id; + } public ZenodoAPIClient(String urlString, String access_token) throws IOException { @@ -50,6 +50,7 @@ public class ZenodoAPIClient implements Serializable { /** * Brand new deposition in Zenodo. It sets the deposition_id and the bucket where to store the files to upload + * * @return response code * @throws IOException */ @@ -86,6 +87,7 @@ public class ZenodoAPIClient implements Serializable { /** * Upload files in Zenodo. + * * @param is the inputStream for the file to upload * @param file_name the name of the file as it will appear on Zenodo * @param len the size of the file @@ -110,6 +112,7 @@ public class ZenodoAPIClient implements Serializable { /** * Associates metadata information to the current deposition + * * @param metadata the metadata * @return response code * @throws IOException @@ -140,6 +143,7 @@ public class ZenodoAPIClient implements Serializable { /** * To publish the current deposition. It works for both new deposition or new version of an old deposition + * * @return response code * @throws IOException */ @@ -166,11 +170,12 @@ public class ZenodoAPIClient implements Serializable { } /** - * To create a new version of an already published deposition. - * It sets the deposition_id and the bucket to be used for the new version. - * @param concept_rec_id the concept record id of the deposition for which to create a new version. It is - * the last part of the url for the DOI Zenodo suggests to use to cite all versions: - * DOI: 10.xxx/zenodo.656930 concept_rec_id = 656930 + * To create a new version of an already published deposition. It sets the deposition_id and the bucket to be used + * for the new version. + * + * @param concept_rec_id the concept record id of the deposition for which to create a new version. It is the last + * part of the url for the DOI Zenodo suggests to use to cite all versions: DOI: 10.xxx/zenodo.656930 + * concept_rec_id = 656930 * @return response code * @throws IOException * @throws MissingConceptDoiException @@ -182,10 +187,10 @@ public class ZenodoAPIClient implements Serializable { OkHttpClient httpClient = new OkHttpClient(); Request request = new Request.Builder() - .url(urlString + "/" + deposition_id + "/actions/newversion") - .addHeader("Authorization", "Bearer " + access_token) - .post(RequestBody.create(MEDIA_TYPE_JSON, json)) - .build(); + .url(urlString + "/" + deposition_id + "/actions/newversion") + .addHeader("Authorization", "Bearer " + access_token) + .post(RequestBody.create(MEDIA_TYPE_JSON, json)) + .build(); try (Response response = httpClient.newCall(request).execute()) { @@ -205,9 +210,9 @@ public class ZenodoAPIClient implements Serializable { ZenodoModelList zenodoModelList = new Gson().fromJson(getPrevDepositions(), ZenodoModelList.class); - for(ZenodoModel zm : zenodoModelList){ - if (zm.getConceptrecid().equals(concept_rec_id)){ - deposition_id = zm.getId(); + for (ZenodoModel zm : zenodoModelList) { + if (zm.getConceptrecid().equals(concept_rec_id)) { + deposition_id = zm.getId(); return; } } @@ -220,11 +225,11 @@ public class ZenodoAPIClient implements Serializable { OkHttpClient httpClient = new OkHttpClient(); Request request = new Request.Builder() - .url(urlString) - .addHeader("Content-Type", "application/json") // add request headers - .addHeader("Authorization", "Bearer " + access_token) - .get() - .build(); + .url(urlString) + .addHeader("Content-Type", "application/json") // add request headers + .addHeader("Authorization", "Bearer " + access_token) + .get() + .build(); try (Response response = httpClient.newCall(request).execute()) { @@ -241,11 +246,11 @@ public class ZenodoAPIClient implements Serializable { OkHttpClient httpClient = new OkHttpClient(); Request request = new Request.Builder() - .url(url) - .addHeader("Content-Type", "application/json") // add request headers - .addHeader("Authorization", "Bearer " + access_token) - .get() - .build(); + .url(url) + .addHeader("Content-Type", "application/json") // add request headers + .addHeader("Authorization", "Bearer " + access_token) + .get() + .build(); try (Response response = httpClient.newCall(request).execute()) { @@ -255,12 +260,10 @@ public class ZenodoAPIClient implements Serializable { // Get response body ZenodoModel zenodoModel = new Gson().fromJson(response.body().string(), ZenodoModel.class); - return zenodoModel.getLinks().getBucket(); } } - } diff --git a/dhp-common/src/main/java/eu/dnetlib/dhp/common/api/zenodo/ZenodoModelList.java b/dhp-common/src/main/java/eu/dnetlib/dhp/common/api/zenodo/ZenodoModelList.java index f2e02d6b7..b3b150714 100644 --- a/dhp-common/src/main/java/eu/dnetlib/dhp/common/api/zenodo/ZenodoModelList.java +++ b/dhp-common/src/main/java/eu/dnetlib/dhp/common/api/zenodo/ZenodoModelList.java @@ -1,3 +1,4 @@ + package eu.dnetlib.dhp.common.api.zenodo; import java.util.ArrayList; diff --git a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/dump/oaf/community/CommunityInstance.java b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/dump/oaf/community/CommunityInstance.java new file mode 100644 index 000000000..03c770e84 --- /dev/null +++ b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/dump/oaf/community/CommunityInstance.java @@ -0,0 +1,4 @@ +package eu.dnetlib.dhp.schema.dump.oaf.community; + +public class CommunityInstance { +} diff --git a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/dump/oaf/graph/GraphResult.java b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/dump/oaf/graph/GraphResult.java new file mode 100644 index 000000000..9b8fa0801 --- /dev/null +++ b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/dump/oaf/graph/GraphResult.java @@ -0,0 +1,4 @@ +package eu.dnetlib.dhp.schema.dump.oaf.graph; + +public class GraphResult { +}