From d2374e3b9e451ed28b565f42f4ef9d446c90e154 Mon Sep 17 00:00:00 2001 From: "miriam.baglioni" Date: Tue, 27 Oct 2020 16:15:21 +0100 Subject: [PATCH] added code to handle cases where the funding tree is not existing --- .../community/SparkPrepareResultProject.java | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/community/SparkPrepareResultProject.java b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/community/SparkPrepareResultProject.java index 6e0e059f3..5cb9d5bc3 100644 --- a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/community/SparkPrepareResultProject.java +++ b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/community/SparkPrepareResultProject.java @@ -122,26 +122,31 @@ public class SparkPrepareResultProject implements Serializable { private static Project getProject(eu.dnetlib.dhp.schema.oaf.Project op) { Project p = Project - .newInstance( - op.getId(), - op.getCode().getValue(), - Optional - .ofNullable(op.getAcronym()) - .map(a -> a.getValue()) - .orElse(null), - Optional - .ofNullable(op.getTitle()) - .map(v -> v.getValue()) - .orElse(null), - Optional - .ofNullable(op.getFundingtree()) - .map( - value -> value - .stream() - .map(ft -> getFunder(ft.getValue())) - .collect(Collectors.toList()) - .get(0)) - .orElse(null)); + .newInstance( + op.getId(), + op.getCode().getValue(), + Optional + .ofNullable(op.getAcronym()) + .map(a -> a.getValue()) + .orElse(null), + Optional + .ofNullable(op.getTitle()) + .map(v -> v.getValue()) + .orElse(null), + Optional + .ofNullable(op.getFundingtree()) + .map(value -> { + List tmp = value + .stream() + .map(ft -> getFunder(ft.getValue())) + .collect(Collectors.toList()); + if (tmp.size() > 0) { + return tmp.get(0); + } else { + return null; + } + }) + .orElse(null)); Optional di = Optional.ofNullable(op.getDataInfo()); Provenance provenance = new Provenance();