From 4c8d86493c03dae87e87ee0f6428d58dadc1cde8 Mon Sep 17 00:00:00 2001 From: "miriam.baglioni" Date: Tue, 7 Jul 2020 18:09:06 +0200 Subject: [PATCH] - --- .../dnetlib/dhp/oa/graph/dump/APIClient.java | 79 +++++++++---------- .../eu/dnetlib/dhp/oa/graph/dump/Mapper.java | 2 +- 2 files changed, 39 insertions(+), 42 deletions(-) diff --git a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/APIClient.java b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/APIClient.java index 23322f7fe..59f92d885 100644 --- a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/APIClient.java +++ b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/APIClient.java @@ -3,10 +3,11 @@ package eu.dnetlib.dhp.oa.graph.dump; import java.io.*; import java.io.IOException; -import okhttp3.*; -import com.google.gson.Gson; -import eu.dnetlib.dhp.oa.graph.dump.zenodo.ZenodoModel; +import com.google.gson.Gson; + +import eu.dnetlib.dhp.oa.graph.dump.zenodo.ZenodoModel; +import okhttp3.*; public class APIClient implements Serializable { @@ -16,11 +17,9 @@ public class APIClient implements Serializable { String deposition_id; String access_token; - public static final MediaType MEDIA_TYPE_JSON - = MediaType.parse("application/json; charset=utf-8"); + 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"); + private static final MediaType MEDIA_TYPE_ZIP = MediaType.parse("application/zip"); public String getUrlString() { return urlString; @@ -44,24 +43,23 @@ public class APIClient implements Serializable { this.access_token = access_token; } - public int connect() throws IOException{ + public int connect() throws IOException { String json = "{}"; OkHttpClient httpClient = new OkHttpClient(); - RequestBody body = RequestBody.create(json, MEDIA_TYPE_JSON); + RequestBody body = RequestBody.create(MEDIA_TYPE_JSON, json); Request request = new Request.Builder() - .url(urlString) - .addHeader("Content-Type", "application/json") // add request headers - .addHeader("Authorization", "Bearer " + access_token) - .post(body) - .build(); - - + .url(urlString) + .addHeader("Content-Type", "application/json") // add request headers + .addHeader("Authorization", "Bearer " + access_token) + .post(body) + .build(); try (Response response = httpClient.newCall(request).execute()) { - if (!response.isSuccessful()) throw new IOException("Unexpected code " + response + response.body().string()); + if (!response.isSuccessful()) + throw new IOException("Unexpected code " + response + response.body().string()); // Get response body json = response.body().string(); @@ -76,20 +74,20 @@ public class APIClient implements Serializable { } - - public int upload(File file, String file_name){ + public int upload(File file, String file_name) { OkHttpClient httpClient = new OkHttpClient(); Request request = new Request.Builder() - .url(bucket + "/" + file_name) - .addHeader("Content-Type", "application/zip") // add request headers - .addHeader("Authorization", "Bearer " + access_token) - .put(RequestBody.create(file, MEDIA_TYPE_ZIP)) - .build(); + .url(bucket + "/" + file_name) + .addHeader("Content-Type", "application/zip") // add request headers + .addHeader("Authorization", "Bearer " + access_token) + .put(RequestBody.create(MEDIA_TYPE_ZIP, file)) + .build(); try (Response response = httpClient.newCall(request).execute()) { - if (!response.isSuccessful()) throw new IOException("Unexpected code " + response + response.body().string()); + if (!response.isSuccessful()) + throw new IOException("Unexpected code " + response + response.body().string()); return response.code(); } catch (IOException e) { e.printStackTrace(); @@ -99,24 +97,23 @@ public class APIClient implements Serializable { return -1; } - public int sendMretadata(String metadata) throws IOException { OkHttpClient httpClient = new OkHttpClient(); - RequestBody body = RequestBody.create(metadata, MEDIA_TYPE_JSON); + RequestBody body = RequestBody.create(MEDIA_TYPE_JSON, metadata); Request request = new Request.Builder() - .url(urlString + "/" + deposition_id) - .addHeader("Content-Type", "application/json") // add request headers - .addHeader("Authorization", "Bearer " + access_token) - .put(body) - .build(); - + .url(urlString + "/" + deposition_id) + .addHeader("Content-Type", "application/json") // add request headers + .addHeader("Authorization", "Bearer " + access_token) + .put(body) + .build(); try (Response response = httpClient.newCall(request).execute()) { - if (!response.isSuccessful()) throw new IOException("Unexpected code " + response + response.body().string()); + if (!response.isSuccessful()) + throw new IOException("Unexpected code " + response + response.body().string()); return response.code(); @@ -130,23 +127,23 @@ public class APIClient implements Serializable { OkHttpClient httpClient = new OkHttpClient(); - Request request = new Request.Builder() - .url(urlString + "/" + deposition_id + "/actions/publish") - .addHeader("Authorization", "Bearer " + access_token) - .post(RequestBody.create(json, MEDIA_TYPE_JSON)) - .build(); + .url(urlString + "/" + deposition_id + "/actions/publish") + .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()); + if (!response.isSuccessful()) + throw new IOException("Unexpected code " + response + response.body().string()); return response.code(); } } - // public int connect() throws IOException { + // public int connect() throws IOException { // // String json = "{}"; // diff --git a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/Mapper.java b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/Mapper.java index 4be1cd048..effa8bcc5 100644 --- a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/Mapper.java +++ b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/Mapper.java @@ -137,7 +137,7 @@ public class Mapper implements Serializable { Optional oar = Optional.ofNullable(input.getBestaccessright()); if (oar.isPresent()) { if (Constants.accessRightsCoarMap.containsKey(oar.get().getClassid())) { - String code = Constants.accessRightsCoarMap.get(oar.get().getClassid()); + String code = Constants.accessRightsCoarMap.get(oar.get().getClassname()); out .setBestaccessright( AccessRight