From 11938dac5e39ba083842e6cd2401e1ddee29a196 Mon Sep 17 00:00:00 2001 From: Claudio Atzori Date: Mon, 4 May 2020 16:47:07 +0200 Subject: [PATCH] this commit adds: validated/validationDate to relationships; measure type and simple unit test to indicate the relative serialization --- .../eu/dnetlib/dhp/schema/oaf/Measure.java | 52 +++++++++++++++++++ .../eu/dnetlib/dhp/schema/oaf/Relation.java | 40 ++++++++++++++ .../eu/dnetlib/dhp/schema/oaf/Result.java | 12 +++++ .../dnetlib/dhp/schema/oaf/MeasureTest.java | 37 +++++++++++++ 4 files changed, 141 insertions(+) diff --git a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Measure.java b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Measure.java index 98adffd2a..c37e76061 100644 --- a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Measure.java +++ b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Measure.java @@ -1,4 +1,56 @@ package eu.dnetlib.dhp.schema.oaf; +import com.google.common.base.Objects; + +import java.util.List; + +/** + * Represent a measure, must be further described by a system available resource providing name and descriptions. + */ public class Measure { + + /** + * Unique measure identifier. + */ + private String id; + + /** + * List of units associated with this measure. KeyValue provides a pair to store the laber (key) and the value, + * plus common provenance information. + */ + private List unit; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public List getUnit() { + return unit; + } + + public void setUnit(List unit) { + this.unit = unit; + } + + public void mergeFrom(Measure m) { + //TODO + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Measure measure = (Measure) o; + return Objects.equal(id, measure.id) && + Objects.equal(unit, measure.unit); + } + + @Override + public int hashCode() { + return Objects.hashCode(id, unit); + } } diff --git a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Relation.java b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Relation.java index 76503f885..d77bd7d73 100644 --- a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Relation.java +++ b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Relation.java @@ -40,6 +40,21 @@ public class Relation extends Oaf { */ private String target; + /** + * Was this relationship authoritatively validated? + */ + private Boolean validated; + + /** + * When was this relationship authoritatively validated. + */ + private String validationDate; + + /** + * List of relation specific properties. Values include 'similarityLevel', indicating the similarity score between a pair of publications. + */ + private List properties = new ArrayList<>(); + public String getRelType() { return relType; } @@ -80,6 +95,30 @@ public class Relation extends Oaf { this.target = target; } + public List getProperties() { + return properties; + } + + public void setProperties(List properties) { + this.properties = properties; + } + + public Boolean getValidated() { + return validated; + } + + public void setValidated(Boolean validated) { + this.validated = validated; + } + + public String getValidationDate() { + return validationDate; + } + + public void setValidationDate(String validationDate) { + this.validationDate = validationDate; + } + public void mergeFrom(final Relation r) { checkArgument(Objects.equals(getSource(), r.getSource()), "source ids must be equal"); @@ -122,4 +161,5 @@ public class Relation extends Oaf { public int hashCode() { return Objects.hash(relType, subRelType, relClass, source, target, collectedfrom); } + } diff --git a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Result.java b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Result.java index 711b1ca68..11316f36e 100644 --- a/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Result.java +++ b/dhp-schemas/src/main/java/eu/dnetlib/dhp/schema/oaf/Result.java @@ -7,6 +7,8 @@ import java.util.List; public class Result extends OafEntity implements Serializable { + private List measures; + private List author; // resulttype allows subclassing results into publications | datasets | software @@ -51,6 +53,14 @@ public class Result extends OafEntity implements Serializable { private List instance; + public List getMeasures() { + return measures; + } + + public void setMeasures(List measures) { + this.measures = measures; + } + public List getAuthor() { return author; } @@ -229,6 +239,8 @@ public class Result extends OafEntity implements Serializable { Result r = (Result) e; + //TODO consider merging also Measures + instance = mergeLists(instance, r.getInstance()); if (r.getBestaccessright() != null && compareTrust(this, r) < 0) diff --git a/dhp-schemas/src/test/java/eu/dnetlib/dhp/schema/oaf/MeasureTest.java b/dhp-schemas/src/test/java/eu/dnetlib/dhp/schema/oaf/MeasureTest.java index 26376349c..25d929db2 100644 --- a/dhp-schemas/src/test/java/eu/dnetlib/dhp/schema/oaf/MeasureTest.java +++ b/dhp-schemas/src/test/java/eu/dnetlib/dhp/schema/oaf/MeasureTest.java @@ -1,4 +1,41 @@ package eu.dnetlib.dhp.schema.oaf; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.Lists; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + public class MeasureTest { + + public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper() + .setSerializationInclusion(JsonInclude.Include.NON_NULL); + + @Test + public void testMeasureSerialization() throws IOException { + + Measure m = new Measure(); + + m.setId("popularity"); + m.setUnit(Lists.newArrayList( + unit("score", "0.5"))); + + String s = OBJECT_MAPPER.writeValueAsString(m); + System.out.println(s); + + Measure mm = OBJECT_MAPPER.readValue(s, Measure.class); + + Assertions.assertNotNull(mm); + } + + private KeyValue unit(String key, String value) { + KeyValue unit = new KeyValue(); + unit.setKey(key); + unit.setValue(value); + return unit; + } + }