fixed NPE

This commit is contained in:
Sandro La Bruzzo 2020-02-26 15:42:20 +01:00
parent a1a6fc8315
commit 071f5c3e52
5 changed files with 20 additions and 6 deletions

View File

@ -32,8 +32,8 @@ public class Scholix implements Serializable {
ScholixSummary scholixSummary = mapper.readValue(sourceSummaryJson, ScholixSummary.class); ScholixSummary scholixSummary = mapper.readValue(sourceSummaryJson, ScholixSummary.class);
Relation rel = mapper.readValue(relation, Relation.class); Relation rel = mapper.readValue(relation, Relation.class);
final Scholix s = new Scholix(); final Scholix s = new Scholix();
if (scholixSummary.getDate() != null) if (scholixSummary.getDate() != null && scholixSummary.getDate().size()>0)
s.setPublicationDate(scholixSummary.getDate().stream().findAny().orElse(null)); s.setPublicationDate(scholixSummary.getDate().get(0));
s.setLinkprovider(rel.getCollectedFrom().stream().map(cf -> s.setLinkprovider(rel.getCollectedFrom().stream().map(cf ->
new ScholixEntityId(cf.getValue(), Collections.singletonList( new ScholixEntityId(cf.getValue(), Collections.singletonList(
new ScholixIdentifier(cf.getKey(), "dnet_identifier") new ScholixIdentifier(cf.getKey(), "dnet_identifier")

View File

@ -35,8 +35,8 @@ public class ScholixResource implements Serializable {
resource.setObjectType(summary.getTypology().toString()); resource.setObjectType(summary.getTypology().toString());
if (summary.getTitle() != null) if (summary.getTitle() != null && summary.getTitle().size()>0)
resource.setTitle(summary.getTitle().stream().findAny().orElse(null)); resource.setTitle(summary.getTitle().get(0));
if (summary.getAuthor() != null) if (summary.getAuthor() != null)
resource.setCreator(summary.getAuthor().stream() resource.setCreator(summary.getAuthor().stream()
@ -44,8 +44,8 @@ public class ScholixResource implements Serializable {
.collect(Collectors.toList()) .collect(Collectors.toList())
); );
if (summary.getDate() != null) if (summary.getDate() != null && summary.getDate().size()>0)
resource.setPublicationDate(summary.getDate().stream().findAny().orElse(null)); resource.setPublicationDate(summary.getDate().get(0));
if (summary.getPublisher() != null) if (summary.getPublisher() != null)
resource.setPublisher(summary.getPublisher().stream() resource.setPublisher(summary.getPublisher().stream()
.map(p -> new ScholixEntityId(p, null)) .map(p -> new ScholixEntityId(p, null))

View File

@ -1,6 +1,7 @@
package eu.dnetlib.dhp.provision; package eu.dnetlib.dhp.provision;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.dhp.provision.scholix.Scholix;
import eu.dnetlib.dhp.provision.scholix.summary.ScholixSummary; import eu.dnetlib.dhp.provision.scholix.summary.ScholixSummary;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.junit.Ignore; 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 @Test
@Ignore @Ignore
public void testIndex() throws Exception { public void testIndex() throws Exception {

View File

@ -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}]}

View File

@ -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}