From 8a463cc3e8b43cf8229ce89fdf64dc9aabbe9a73 Mon Sep 17 00:00:00 2001 From: Claudio Atzori Date: Mon, 15 May 2023 15:44:46 +0200 Subject: [PATCH] fixed organization id created when mapping APC affiliations. Factored out ROR constants in dhp-common --- .../src/main/java/eu/dnetlib/dhp/common/Constants.java | 6 ++++++ .../dhp/actionmanager/ror/GenerateRorActionSetJob.java | 9 ++++----- .../dhp/oa/graph/raw/AbstractMdRecordToOafMapper.java | 5 ++++- .../java/eu/dnetlib/dhp/oa/graph/raw/MappersTest.java | 5 ++++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/dhp-common/src/main/java/eu/dnetlib/dhp/common/Constants.java b/dhp-common/src/main/java/eu/dnetlib/dhp/common/Constants.java index a62a0ac79..4f2c6341e 100644 --- a/dhp-common/src/main/java/eu/dnetlib/dhp/common/Constants.java +++ b/dhp-common/src/main/java/eu/dnetlib/dhp/common/Constants.java @@ -10,6 +10,12 @@ public class Constants { public static final Map accessRightsCoarMap = Maps.newHashMap(); public static final Map coarCodeLabelMap = Maps.newHashMap(); + public static final String ROR_NS_PREFIX = "ror_________"; + + public static final String ROR_OPENAIRE_ID = "10|openaire____::993a7ae7a863813cf95028b50708e222"; + + public static final String ROR_DATASOURCE_NAME = "Research Organization Registry (ROR)"; + public static String COAR_ACCESS_RIGHT_SCHEMA = "http://vocabularies.coar-repositories.org/documentation/access_rights/"; private Constants() { diff --git a/dhp-workflows/dhp-aggregation/src/main/java/eu/dnetlib/dhp/actionmanager/ror/GenerateRorActionSetJob.java b/dhp-workflows/dhp-aggregation/src/main/java/eu/dnetlib/dhp/actionmanager/ror/GenerateRorActionSetJob.java index 6b5bed5b8..1be2a96fd 100644 --- a/dhp-workflows/dhp-aggregation/src/main/java/eu/dnetlib/dhp/actionmanager/ror/GenerateRorActionSetJob.java +++ b/dhp-workflows/dhp-aggregation/src/main/java/eu/dnetlib/dhp/actionmanager/ror/GenerateRorActionSetJob.java @@ -40,6 +40,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import eu.dnetlib.dhp.actionmanager.ror.model.ExternalIdType; import eu.dnetlib.dhp.actionmanager.ror.model.RorOrganization; import eu.dnetlib.dhp.application.ArgumentApplicationParser; +import eu.dnetlib.dhp.common.Constants; import eu.dnetlib.dhp.common.HdfsSupport; import eu.dnetlib.dhp.schema.action.AtomicAction; import eu.dnetlib.dhp.schema.common.ModelConstants; @@ -59,10 +60,8 @@ public class GenerateRorActionSetJob { private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); - private static final String ROR_NS_PREFIX = "ror_________"; - private static final List ROR_COLLECTED_FROM = listKeyValues( - "10|openaire____::993a7ae7a863813cf95028b50708e222", "ROR"); + Constants.ROR_OPENAIRE_ID, Constants.ROR_DATASOURCE_NAME); private static final DataInfo ROR_DATA_INFO = dataInfo( false, "", false, false, ENTITYREGISTRY_PROVENANCE_ACTION, "0.92"); @@ -126,7 +125,7 @@ public class GenerateRorActionSetJob { final Organization o = new Organization(); o.setId(calculateOpenaireId(r.getId())); - o.setOriginalId(Arrays.asList(String.format("%s::%s", ROR_NS_PREFIX, r.getId()))); + o.setOriginalId(Arrays.asList(String.format("%s::%s", Constants.ROR_NS_PREFIX, r.getId()))); o.setCollectedfrom(ROR_COLLECTED_FROM); o.setPid(pids(r)); o.setDateofcollection(now.toString()); @@ -170,7 +169,7 @@ public class GenerateRorActionSetJob { } private static String calculateOpenaireId(final String rorId) { - return String.format("20|%s::%s", ROR_NS_PREFIX, DHPUtils.md5(rorId)); + return String.format("20|%s::%s", Constants.ROR_NS_PREFIX, DHPUtils.md5(rorId)); } private static List pids(final RorOrganization r) { diff --git a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/AbstractMdRecordToOafMapper.java b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/AbstractMdRecordToOafMapper.java index cb9447b1b..504c9dd4c 100644 --- a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/AbstractMdRecordToOafMapper.java +++ b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/AbstractMdRecordToOafMapper.java @@ -20,6 +20,7 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; +import eu.dnetlib.dhp.common.Constants; import eu.dnetlib.dhp.common.vocabulary.VocabularyGroup; import eu.dnetlib.dhp.schema.common.ModelConstants; import eu.dnetlib.dhp.schema.common.ModelSupport; @@ -326,8 +327,10 @@ public abstract class AbstractMdRecordToOafMapper { String rorId = element.attributeValue("affiliationIdentifier"); if (StringUtils.isNotBlank(rorId)) { + String fullRorId = Constants.ROR_NS_PREFIX + "::" + rorId; + String resultId = entity.getId(); - String orgId = createOpenaireId("organization", rorId, true); + String orgId = createOpenaireId("organization", fullRorId, true); List properties = Lists.newArrayList(); diff --git a/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/raw/MappersTest.java b/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/raw/MappersTest.java index 81daeb373..a5a277470 100644 --- a/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/raw/MappersTest.java +++ b/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/raw/MappersTest.java @@ -23,6 +23,7 @@ import org.mockito.junit.jupiter.MockitoExtension; import com.fasterxml.jackson.databind.ObjectMapper; +import eu.dnetlib.dhp.common.Constants; import eu.dnetlib.dhp.common.vocabulary.VocabularyGroup; import eu.dnetlib.dhp.schema.common.ModelConstants; import eu.dnetlib.dhp.schema.oaf.*; @@ -922,7 +923,7 @@ class MappersTest { } @Test - void testOpenAPC() throws IOException, DocumentException { + void testOpenAPC() throws IOException { final String xml = IOUtils.toString(Objects.requireNonNull(getClass().getResourceAsStream("oaf_openapc.xml"))); final List list = new OafToOafMapper(vocs, true, true).processMdRecord(xml); @@ -955,6 +956,8 @@ class MappersTest { if (StringUtils.startsWith(source, "50")) { assertEquals(ModelConstants.HAS_AUTHOR_INSTITUTION, r.getRelClass()); } else if (StringUtils.startsWith(source, "20")) { + assertTrue(StringUtils.contains(source, "::")); + assertEquals("20|" + Constants.ROR_NS_PREFIX, StringUtils.substringBefore(source, "::")); assertEquals(ModelConstants.IS_AUTHOR_INSTITUTION_OF, r.getRelClass()); } else { throw new IllegalArgumentException("invalid source / target prefixes for affiliation relations");