From d8bfaa3687efccb62d0e8c4c98b143a2c4e394d6 Mon Sep 17 00:00:00 2001 From: Claudio Atzori Date: Thu, 24 Oct 2019 17:04:13 +0200 Subject: [PATCH] added mapping for relations --- .../src/main/java/eu/dnetlib/dhp/schema/oaf/Oaf.java | 3 --- .../java/eu/dnetlib/dhp/graph/ProtoConverter.java | 12 ++++++++---- .../main/java/eu/dnetlib/dhp/graph/ProtoUtils.java | 7 +------ 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Oaf.java b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Oaf.java index a47fe71740..352ebbc6e3 100644 --- a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Oaf.java +++ b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Oaf.java @@ -8,9 +8,6 @@ public abstract class Oaf implements Serializable { private Long lastupdatetimestamp; - -// protected abstract T fromJson(final String json); - public DataInfo getDataInfo() { return dataInfo; } diff --git a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/graph/ProtoConverter.java b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/graph/ProtoConverter.java index cc5ba181cf..fd402369ff 100644 --- a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/graph/ProtoConverter.java +++ b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/graph/ProtoConverter.java @@ -7,6 +7,7 @@ import eu.dnetlib.dhp.schema.oaf.*; import java.io.Serializable; import java.util.stream.Collectors; +import static eu.dnetlib.dhp.graph.ProtoUtils.mapDataInfo; import static eu.dnetlib.dhp.graph.ProtoUtils.mapKV; public class ProtoConverter implements Serializable { @@ -26,17 +27,20 @@ public class ProtoConverter implements Serializable { } private static Relation convertRelation(OafProtos.Oaf oaf) { - final Relation rel = new Relation(); final OafProtos.OafRel r = oaf.getRel(); + final Relation rel = new Relation(); + rel.setDataInfo(mapDataInfo(oaf.getDataInfo())); + rel.setLastupdatetimestamp(oaf.getLastupdatetimestamp()); return rel .setSource(r.getSource()) .setTarget(r.getTarget()) .setRelType(r.getRelType().toString()) .setSubRelType(r.getSubRelType().toString()) .setRelClass(r.getRelClass()) - .setCollectedFrom(r.getCollectedfromList().stream() - .map(kv -> mapKV(kv)) - .collect(Collectors.toList())); + .setCollectedFrom(r.getCollectedfromCount() > 0 ? + r.getCollectedfromList().stream() + .map(kv -> mapKV(kv)) + .collect(Collectors.toList()) : null); } private static OafEntity convertEntity(OafProtos.Oaf oaf) { diff --git a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/graph/ProtoUtils.java b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/graph/ProtoUtils.java index 0c8ffda302..8cbd280e0e 100644 --- a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/graph/ProtoUtils.java +++ b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/graph/ProtoUtils.java @@ -3,12 +3,7 @@ package eu.dnetlib.dhp.graph; import com.googlecode.protobuf.format.JsonFormat; import eu.dnetlib.data.proto.FieldTypeProtos; import eu.dnetlib.data.proto.OafProtos; -import eu.dnetlib.dhp.schema.oaf.DataInfo; -import eu.dnetlib.dhp.schema.oaf.KeyValue; -import eu.dnetlib.dhp.schema.oaf.Qualifier; -import eu.dnetlib.dhp.schema.oaf.StructuredProperty; - -import java.util.List; +import eu.dnetlib.dhp.schema.oaf.*; public class ProtoUtils {