From b0199b2e1091ce1e1a73a4f582340b2cd1568a05 Mon Sep 17 00:00:00 2001 From: Sandro La Bruzzo Date: Mon, 18 Oct 2021 17:14:23 +0200 Subject: [PATCH] Added missing datacite Relations into dhp-schemas --- .../dhp/schema/common/ModelConstants.java | 9 +++++++ .../dhp/schema/common/ModelSupport.java | 23 +++++++++++++++- .../dhp/schema/common/ModelSupportTest.java | 27 ++++++++++++++----- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/src/main/java/eu/dnetlib/dhp/schema/common/ModelConstants.java b/src/main/java/eu/dnetlib/dhp/schema/common/ModelConstants.java index e71cf6c..c4ae5cb 100644 --- a/src/main/java/eu/dnetlib/dhp/schema/common/ModelConstants.java +++ b/src/main/java/eu/dnetlib/dhp/schema/common/ModelConstants.java @@ -102,6 +102,15 @@ public class ModelConstants { public static final String IS_DERIVED_FROM = "IsDerivedFrom"; public static final String COMPILES = "Compiles"; public static final String IS_COMPILED_BY = "IsCompiledBy"; + public static final String DESCRIBES = "Describes"; + public static final String IS_DESCRIBE_DBY = "IsDescribedBy"; + public static final String IS_METADATA_FOR = "IsMetadataFor"; + public static final String IS_METADATA_OF = "IsMetadataOf"; + public static final String HAS_ASSOCIATION_WITH = "HasAssociationWith"; + public static final String IS_REQUIRED_BY = "IsRequiredBy"; + public static final String REQUIRES = "Requires"; + + public static final String CITATION = "citation"; // subreltype public static final String CITES = "Cites"; diff --git a/src/main/java/eu/dnetlib/dhp/schema/common/ModelSupport.java b/src/main/java/eu/dnetlib/dhp/schema/common/ModelSupport.java index 70c21b3..bf0eed1 100644 --- a/src/main/java/eu/dnetlib/dhp/schema/common/ModelSupport.java +++ b/src/main/java/eu/dnetlib/dhp/schema/common/ModelSupport.java @@ -125,6 +125,12 @@ public class ModelSupport { set(relationInverseMap, RESULT_RESULT, RELATIONSHIP, IS_RELATED_TO, IS_RELATED_TO); set(relationInverseMap, RESULT_RESULT, RELATIONSHIP, IS_COMPILED_BY, COMPILES); + set(relationInverseMap, RESULT_RESULT, RELATIONSHIP, IS_DESCRIBE_DBY, DESCRIBES); + set(relationInverseMap, RESULT_RESULT, RELATIONSHIP, IS_METADATA_FOR, IS_METADATA_OF); + set(relationInverseMap, RESULT_RESULT, RELATIONSHIP, HAS_ASSOCIATION_WITH, HAS_ASSOCIATION_WITH); + set(relationInverseMap, RESULT_RESULT, RELATIONSHIP, IS_REQUIRED_BY, REQUIRES); + + set(relationInverseMap, RESULT_RESULT, VERSION, IS_PREVIOUS_VERSION_OF, IS_NEW_VERSION_OF); set(relationInverseMap, RESULT_RESULT, VERSION, IS_VARIANT_FORM_OF, IS_ORIGINAL_FORM_OF); set(relationInverseMap, RESULT_RESULT, VERSION, IS_OBSOLETED_BY, OBSOLETES); @@ -152,6 +158,21 @@ public class ModelSupport { } } + /** + * Helper method: fina a relation filtering by a relation name + * @param relationName + * @return + */ + public static RelationInverse findRelation(final String relationName) { + return relationInverseMap.values() + .stream() + .filter(r -> relationName.equalsIgnoreCase(r.getRelClass())) + .findFirst() + .orElse(null); + + + } + /** * Helper method: combines the relation attributes * @param relType @@ -160,7 +181,7 @@ public class ModelSupport { * @return */ public static String rel(String relType, String subRelType, String relClass) { - return String.format("%-%-%", relType, subRelType, relClass); + return String.format("%s-%s-%s", relType, subRelType, relClass); } private static final String schemeTemplate = "dnet:%s_%s_relations"; diff --git a/src/test/java/eu/dnetlib/dhp/schema/common/ModelSupportTest.java b/src/test/java/eu/dnetlib/dhp/schema/common/ModelSupportTest.java index b40e119..8ff1947 100644 --- a/src/test/java/eu/dnetlib/dhp/schema/common/ModelSupportTest.java +++ b/src/test/java/eu/dnetlib/dhp/schema/common/ModelSupportTest.java @@ -1,15 +1,15 @@ package eu.dnetlib.dhp.schema.common; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; - import eu.dnetlib.dhp.schema.oaf.OafEntity; import eu.dnetlib.dhp.schema.oaf.Relation; import eu.dnetlib.dhp.schema.oaf.Result; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import java.io.IOException; + +import static org.junit.jupiter.api.Assertions.*; public class ModelSupportTest { @@ -34,4 +34,19 @@ public class ModelSupportTest { assertTrue(result); } } + + + @Nested + class InverseRelation { + + @Test + void findRelations() throws IOException { + assertNotNull(ModelSupport.findRelation("isMetadataFor")); + assertNotNull(ModelSupport.findRelation("ismetadatafor")); + assertNotNull(ModelSupport.findRelation("ISMETADATAFOR")); + assertNotNull(ModelSupport.findRelation("isRelatedTo")); + + + } + } }