From 071f5c3e52abc271c9c61edaf45985dc78a2610e Mon Sep 17 00:00:00 2001 From: Sandro La Bruzzo Date: Wed, 26 Feb 2020 15:42:20 +0100 Subject: [PATCH] fixed NPE --- .../eu/dnetlib/dhp/provision/scholix/Scholix.java | 4 ++-- .../dhp/provision/scholix/ScholixResource.java | 8 ++++---- .../eu/dnetlib/dhp/provision/ExtractInfoTest.java | 12 ++++++++++++ .../resources/eu/dnetlib/dhp/provision/relation.json | 1 + .../resources/eu/dnetlib/dhp/provision/summary.json | 1 + 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/dhp-workflows/dhp-graph-provision/src/main/java/eu/dnetlib/dhp/provision/scholix/Scholix.java b/dhp-workflows/dhp-graph-provision/src/main/java/eu/dnetlib/dhp/provision/scholix/Scholix.java index 3a6297df25..c6fc792aaa 100644 --- a/dhp-workflows/dhp-graph-provision/src/main/java/eu/dnetlib/dhp/provision/scholix/Scholix.java +++ b/dhp-workflows/dhp-graph-provision/src/main/java/eu/dnetlib/dhp/provision/scholix/Scholix.java @@ -32,8 +32,8 @@ public class Scholix implements Serializable { ScholixSummary scholixSummary = mapper.readValue(sourceSummaryJson, ScholixSummary.class); Relation rel = mapper.readValue(relation, Relation.class); final Scholix s = new Scholix(); - if (scholixSummary.getDate() != null) - s.setPublicationDate(scholixSummary.getDate().stream().findAny().orElse(null)); + if (scholixSummary.getDate() != null && scholixSummary.getDate().size()>0) + s.setPublicationDate(scholixSummary.getDate().get(0)); s.setLinkprovider(rel.getCollectedFrom().stream().map(cf -> new ScholixEntityId(cf.getValue(), Collections.singletonList( new ScholixIdentifier(cf.getKey(), "dnet_identifier") diff --git a/dhp-workflows/dhp-graph-provision/src/main/java/eu/dnetlib/dhp/provision/scholix/ScholixResource.java b/dhp-workflows/dhp-graph-provision/src/main/java/eu/dnetlib/dhp/provision/scholix/ScholixResource.java index a08a2cd9b5..abcb398b55 100644 --- a/dhp-workflows/dhp-graph-provision/src/main/java/eu/dnetlib/dhp/provision/scholix/ScholixResource.java +++ b/dhp-workflows/dhp-graph-provision/src/main/java/eu/dnetlib/dhp/provision/scholix/ScholixResource.java @@ -35,8 +35,8 @@ public class ScholixResource implements Serializable { resource.setObjectType(summary.getTypology().toString()); - if (summary.getTitle() != null) - resource.setTitle(summary.getTitle().stream().findAny().orElse(null)); + if (summary.getTitle() != null && summary.getTitle().size()>0) + resource.setTitle(summary.getTitle().get(0)); if (summary.getAuthor() != null) resource.setCreator(summary.getAuthor().stream() @@ -44,8 +44,8 @@ public class ScholixResource implements Serializable { .collect(Collectors.toList()) ); - if (summary.getDate() != null) - resource.setPublicationDate(summary.getDate().stream().findAny().orElse(null)); + if (summary.getDate() != null && summary.getDate().size()>0) + resource.setPublicationDate(summary.getDate().get(0)); if (summary.getPublisher() != null) resource.setPublisher(summary.getPublisher().stream() .map(p -> new ScholixEntityId(p, null)) diff --git a/dhp-workflows/dhp-graph-provision/src/test/java/eu/dnetlib/dhp/provision/ExtractInfoTest.java b/dhp-workflows/dhp-graph-provision/src/test/java/eu/dnetlib/dhp/provision/ExtractInfoTest.java index d4b185fdfd..a41413d00c 100644 --- a/dhp-workflows/dhp-graph-provision/src/test/java/eu/dnetlib/dhp/provision/ExtractInfoTest.java +++ b/dhp-workflows/dhp-graph-provision/src/test/java/eu/dnetlib/dhp/provision/ExtractInfoTest.java @@ -1,6 +1,7 @@ package eu.dnetlib.dhp.provision; import com.fasterxml.jackson.databind.ObjectMapper; +import eu.dnetlib.dhp.provision.scholix.Scholix; import eu.dnetlib.dhp.provision.scholix.summary.ScholixSummary; import org.apache.commons.io.IOUtils; import org.junit.Ignore; @@ -31,6 +32,17 @@ public class ExtractInfoTest { } + @Test + public void testScholix() throws Exception { + final String jsonSummary = IOUtils.toString(getClass().getResourceAsStream("summary.json")); + final String jsonRelation = IOUtils.toString(getClass().getResourceAsStream("relation.json")); + + Scholix.generateScholixWithSource(jsonSummary, jsonRelation); + + + } + + @Test @Ignore public void testIndex() throws Exception { diff --git a/dhp-workflows/dhp-graph-provision/src/test/resources/eu/dnetlib/dhp/provision/relation.json b/dhp-workflows/dhp-graph-provision/src/test/resources/eu/dnetlib/dhp/provision/relation.json index e69de29bb2..e627c994ce 100644 --- a/dhp-workflows/dhp-graph-provision/src/test/resources/eu/dnetlib/dhp/provision/relation.json +++ b/dhp-workflows/dhp-graph-provision/src/test/resources/eu/dnetlib/dhp/provision/relation.json @@ -0,0 +1 @@ +{"dataInfo":{"invisible":false,"inferred":null,"deletedbyinference":false,"trust":"0.9","inferenceprovenance":null,"provenanceaction":null},"lastupdatetimestamp":null,"relType":"cites","subRelType":null,"relClass":"datacite","source":"50|4916f842ad1567aed2ec220001081d22","target":"60|829a8bf6b014d9bab2d24e42ed395723","collectedFrom":[{"key":"dli_________::r3d100010255","value":"ICPSR","dataInfo":null}]} \ No newline at end of file diff --git a/dhp-workflows/dhp-graph-provision/src/test/resources/eu/dnetlib/dhp/provision/summary.json b/dhp-workflows/dhp-graph-provision/src/test/resources/eu/dnetlib/dhp/provision/summary.json index e69de29bb2..b0f8976849 100644 --- a/dhp-workflows/dhp-graph-provision/src/test/resources/eu/dnetlib/dhp/provision/summary.json +++ b/dhp-workflows/dhp-graph-provision/src/test/resources/eu/dnetlib/dhp/provision/summary.json @@ -0,0 +1 @@ +{"id":"50|4916f842ad1567aed2ec220001081d22","localIdentifier":[{"id":"43379","type":"ICPSR"}],"typology":"publication","title":["Racial differences in patterns of wealth accumulation"],"author":["Gittleman, Maury","Wolff, Edward, N."],"date":[null],"subject":[],"publisher":null,"relatedPublications":0,"relatedDatasets":1,"relatedUnknown":0,"datasources":[{"datasourceName":"ICPSR","datasourceId":"dli_________::r3d100010255","completionStatus":"complete"}],"abstract":null}