From 80eba5b4977684a8846f30ddb0c64fe1bda1f218 Mon Sep 17 00:00:00 2001 From: Claudio Atzori Date: Mon, 7 Sep 2020 11:40:00 +0200 Subject: [PATCH 1/2] avoid to reformat javadoc comments --- .../src/main/resources/eclipse/formatter_dnet.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dhp-build/dhp-code-style/src/main/resources/eclipse/formatter_dnet.xml b/dhp-build/dhp-code-style/src/main/resources/eclipse/formatter_dnet.xml index fcba2c4b2..e4d85bf39 100644 --- a/dhp-build/dhp-code-style/src/main/resources/eclipse/formatter_dnet.xml +++ b/dhp-build/dhp-code-style/src/main/resources/eclipse/formatter_dnet.xml @@ -19,7 +19,7 @@ - + From 8a523474b73f64497b34ec94888569afd94ba073 Mon Sep 17 00:00:00 2001 From: Claudio Atzori Date: Mon, 7 Sep 2020 11:40:16 +0200 Subject: [PATCH 2/2] code formatting --- .../api/MissingConceptDoiException.java | 7 +- .../dhp/common/api/ZenodoAPIClient.java | 42 +++++------ .../common/api/zenodo/ZenodoModelList.java | 1 + .../dnetlib/dhp/schema/dump/oaf/Funder.java | 43 +++++------ .../dnetlib/dhp/schema/dump/oaf/Instance.java | 4 +- .../dnetlib/dhp/schema/dump/oaf/Project.java | 57 +++++++------- .../schema/dump/oaf/graph/Organization.java | 1 - .../dhp/oa/graph/dump/ResultMapper.java | 75 +++++++++---------- .../dhp/oa/graph/dump/SendToZenodoHDFS.java | 2 + .../graph/dump/graph/DumpGraphEntities.java | 4 +- .../dump/graph/SparkOrganizationRelation.java | 1 - .../oa/graph/dump/SplitForCommunityTest.java | 3 + .../graph/ExtractRelationFromEntityTest.java | 1 - 13 files changed, 122 insertions(+), 119 deletions(-) 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..f2dd4f0ac 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 { @@ -182,10 +182,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 +205,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 +220,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 +241,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 +255,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/Funder.java b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/dump/oaf/Funder.java index a49ca7aa4..16cab22cc 100644 --- a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/dump/oaf/Funder.java +++ b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/dump/oaf/Funder.java @@ -1,35 +1,36 @@ + package eu.dnetlib.dhp.schema.dump.oaf; import java.io.Serializable; public class Funder implements Serializable { - private String shortName; + private String shortName; - private String name; + private String name; - private String jurisdiction; + private String jurisdiction; - public String getJurisdiction() { - return jurisdiction; - } + public String getJurisdiction() { + return jurisdiction; + } - public void setJurisdiction(String jurisdiction) { - this.jurisdiction = jurisdiction; - } + public void setJurisdiction(String jurisdiction) { + this.jurisdiction = jurisdiction; + } - public String getShortName() { - return shortName; - } + public String getShortName() { + return shortName; + } - public void setShortName(String shortName) { - this.shortName = shortName; - } + public void setShortName(String shortName) { + this.shortName = shortName; + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public void setName(String name) { - this.name = name; - } + public void setName(String name) { + this.name = name; + } } diff --git a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/dump/oaf/Instance.java b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/dump/oaf/Instance.java index 3db9cbe91..4a09f5a86 100644 --- a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/dump/oaf/Instance.java +++ b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/dump/oaf/Instance.java @@ -30,11 +30,11 @@ public class Instance implements Serializable { private String type; - private KeyValue hostedby; + private KeyValue hostedby; private List url; - private KeyValue collectedfrom; + private KeyValue collectedfrom; private String publicationdate;// dateofacceptance; diff --git a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/dump/oaf/Project.java b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/dump/oaf/Project.java index 70a3fbfbd..f23d5a670 100644 --- a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/dump/oaf/Project.java +++ b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/dump/oaf/Project.java @@ -1,44 +1,45 @@ + package eu.dnetlib.dhp.schema.dump.oaf; import java.io.Serializable; public class Project implements Serializable { - protected String id;// OpenAIRE id - protected String code; + protected String id;// OpenAIRE id + protected String code; - protected String acronym; + protected String acronym; - protected String title; + protected String title; - public String getId() { - return id; - } + public String getId() { + return id; + } - public void setId(String id) { - this.id = id; - } + public void setId(String id) { + this.id = id; + } - public String getCode() { - return code; - } + public String getCode() { + return code; + } - public void setCode(String code) { - this.code = code; - } + public void setCode(String code) { + this.code = code; + } - public String getAcronym() { - return acronym; - } + public String getAcronym() { + return acronym; + } - public void setAcronym(String acronym) { - this.acronym = acronym; - } + public void setAcronym(String acronym) { + this.acronym = acronym; + } - public String getTitle() { - return title; - } + public String getTitle() { + return title; + } - public void setTitle(String title) { - this.title = title; - } + public void setTitle(String title) { + this.title = title; + } } diff --git a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/dump/oaf/graph/Organization.java b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/dump/oaf/graph/Organization.java index 317e66b85..579245c05 100644 --- a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/dump/oaf/graph/Organization.java +++ b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/dump/oaf/graph/Organization.java @@ -10,7 +10,6 @@ import eu.dnetlib.dhp.schema.dump.oaf.KeyValue; import eu.dnetlib.dhp.schema.dump.oaf.Qualifier; import eu.dnetlib.dhp.schema.dump.oaf.community.Project; - /** * To represent the generic organizaiton. It has the following parameters: * - private String legalshortname to store the legalshortname of the organizaiton diff --git a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/ResultMapper.java b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/ResultMapper.java index 32fa65bb7..41142d285 100644 --- a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/ResultMapper.java +++ b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/ResultMapper.java @@ -366,48 +366,47 @@ public class ResultMapper implements Serializable { private static Instance getInstance(eu.dnetlib.dhp.schema.oaf.Instance i, boolean graph) { - Instance instance = new Instance(); + Instance instance = new Instance(); - if(!graph){ + if (!graph) { + instance + .setCollectedfrom( + KeyValue + .newInstance(i.getCollectedfrom().getKey(), i.getCollectedfrom().getValue())); + instance + .setHostedby( + KeyValue.newInstance(i.getHostedby().getKey(), i.getHostedby().getValue())); + } + + Optional opAr = Optional + .ofNullable(i.getAccessright()); + if (opAr.isPresent()) { + if (Constants.accessRightsCoarMap.containsKey(opAr.get().getClassid())) { + String code = Constants.accessRightsCoarMap.get(opAr.get().getClassid()); instance - .setCollectedfrom( - KeyValue - .newInstance(i.getCollectedfrom().getKey(), i.getCollectedfrom().getValue())); - instance - .setHostedby( - KeyValue.newInstance(i.getHostedby().getKey(), i.getHostedby().getValue())); + .setAccessright( + AccessRight + .newInstance( + code, + Constants.coarCodeLabelMap.get(code), + Constants.COAR_ACCESS_RIGHT_SCHEMA)); } + } - Optional opAr = Optional - .ofNullable(i.getAccessright()); - if (opAr.isPresent()) { - if (Constants.accessRightsCoarMap.containsKey(opAr.get().getClassid())) { - String code = Constants.accessRightsCoarMap.get(opAr.get().getClassid()); - instance - .setAccessright( - AccessRight - .newInstance( - code, - Constants.coarCodeLabelMap.get(code), - Constants.COAR_ACCESS_RIGHT_SCHEMA)); - } - } - - - Optional - .ofNullable(i.getLicense()) - .ifPresent(value -> instance.setLicense(value.getValue())); - Optional - .ofNullable(i.getDateofacceptance()) - .ifPresent(value -> instance.setPublicationdate(value.getValue())); - Optional - .ofNullable(i.getRefereed()) - .ifPresent(value -> instance.setRefereed(value.getClassname())); - // .ifPresent(value -> instance.setRefereed(value.getValue())); - Optional - .ofNullable(i.getInstancetype()) - .ifPresent(value -> instance.setType(value.getClassname())); - Optional.ofNullable(i.getUrl()).ifPresent(value -> instance.setUrl(value)); + Optional + .ofNullable(i.getLicense()) + .ifPresent(value -> instance.setLicense(value.getValue())); + Optional + .ofNullable(i.getDateofacceptance()) + .ifPresent(value -> instance.setPublicationdate(value.getValue())); + Optional + .ofNullable(i.getRefereed()) + .ifPresent(value -> instance.setRefereed(value.getClassname())); + // .ifPresent(value -> instance.setRefereed(value.getValue())); + Optional + .ofNullable(i.getInstancetype()) + .ifPresent(value -> instance.setType(value.getClassname())); + Optional.ofNullable(i.getUrl()).ifPresent(value -> instance.setUrl(value)); return instance; } diff --git a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/SendToZenodoHDFS.java b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/SendToZenodoHDFS.java index 9ffc31399..23784cd66 100644 --- a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/SendToZenodoHDFS.java +++ b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/SendToZenodoHDFS.java @@ -3,11 +3,13 @@ package eu.dnetlib.dhp.oa.graph.dump; import java.io.Serializable; import java.util.Optional; + import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.*; + import eu.dnetlib.dhp.application.ArgumentApplicationParser; import eu.dnetlib.dhp.common.api.MissingConceptDoiException; import eu.dnetlib.dhp.common.api.ZenodoAPIClient; diff --git a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/graph/DumpGraphEntities.java b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/graph/DumpGraphEntities.java index 26359cca8..86421cff5 100644 --- a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/graph/DumpGraphEntities.java +++ b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/graph/DumpGraphEntities.java @@ -8,8 +8,6 @@ import java.io.StringReader; import java.util.*; import java.util.stream.Collectors; -import eu.dnetlib.dhp.schema.dump.oaf.graph.Funder; -import eu.dnetlib.dhp.schema.dump.oaf.graph.Project; import org.apache.spark.SparkConf; import org.apache.spark.sql.Encoders; import org.apache.spark.sql.SaveMode; @@ -24,6 +22,8 @@ import eu.dnetlib.dhp.oa.graph.dump.Utils; import eu.dnetlib.dhp.schema.common.ModelSupport; import eu.dnetlib.dhp.schema.dump.oaf.*; import eu.dnetlib.dhp.schema.dump.oaf.graph.*; +import eu.dnetlib.dhp.schema.dump.oaf.graph.Funder; +import eu.dnetlib.dhp.schema.dump.oaf.graph.Project; import eu.dnetlib.dhp.schema.oaf.Field; import eu.dnetlib.dhp.schema.oaf.Journal; import eu.dnetlib.dhp.schema.oaf.OafEntity; diff --git a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/graph/SparkOrganizationRelation.java b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/graph/SparkOrganizationRelation.java index 50b5771e4..f17e7c894 100644 --- a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/graph/SparkOrganizationRelation.java +++ b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/graph/SparkOrganizationRelation.java @@ -1,5 +1,4 @@ - package eu.dnetlib.dhp.oa.graph.dump.graph; import static eu.dnetlib.dhp.common.SparkSessionSupport.runWithSparkSession; diff --git a/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/dump/SplitForCommunityTest.java b/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/dump/SplitForCommunityTest.java index c1478d643..42ad5634a 100644 --- a/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/dump/SplitForCommunityTest.java +++ b/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/dump/SplitForCommunityTest.java @@ -4,6 +4,7 @@ package eu.dnetlib.dhp.oa.graph.dump; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; + import org.apache.commons.io.FileUtils; import org.apache.spark.SparkConf; import org.apache.spark.api.java.JavaRDD; @@ -16,7 +17,9 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import com.fasterxml.jackson.databind.ObjectMapper; + import eu.dnetlib.dhp.oa.graph.dump.community.CommunitySplit; import eu.dnetlib.dhp.schema.dump.oaf.community.CommunityResult; diff --git a/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/dump/graph/ExtractRelationFromEntityTest.java b/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/dump/graph/ExtractRelationFromEntityTest.java index 109458355..820a899ce 100644 --- a/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/dump/graph/ExtractRelationFromEntityTest.java +++ b/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/dump/graph/ExtractRelationFromEntityTest.java @@ -38,7 +38,6 @@ public class ExtractRelationFromEntityTest { private static final Logger log = LoggerFactory .getLogger(ExtractRelationFromEntityTest.class); - @BeforeAll public static void beforeAll() throws IOException { workingDir = Files