From 0393cdce4254b912cdee89a52628b88c89d2f771 Mon Sep 17 00:00:00 2001 From: miconis Date: Tue, 20 Apr 2021 12:45:21 +0200 Subject: [PATCH] addition of alternative names in export queries --- .../dhp/oa/graph/raw/MigrateDbEntitiesApplication.java | 2 +- .../dhp/oa/graph/sql/queryOpenOrgsForOrgsDedup.sql | 4 ++-- .../dhp/oa/graph/sql/queryOpenOrgsForProvision.sql | 2 +- .../eu/dnetlib/dhp/oa/graph/sql/queryOrganizations.sql | 3 ++- .../oa/graph/raw/MigrateDbEntitiesApplicationTest.java | 9 +++++++++ .../dhp/oa/graph/raw/organizations_resultset_entry.json | 7 +++++++ 6 files changed, 22 insertions(+), 5 deletions(-) diff --git a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/MigrateDbEntitiesApplication.java b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/MigrateDbEntitiesApplication.java index 453efb433..c0d70c0ea 100644 --- a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/MigrateDbEntitiesApplication.java +++ b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/MigrateDbEntitiesApplication.java @@ -354,7 +354,7 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i o.setOaiprovenance(null); // Values not present in the DB o.setLegalshortname(field(rs.getString("legalshortname"), info)); o.setLegalname(field(rs.getString("legalname"), info)); - o.setAlternativeNames(new ArrayList<>()); // Values not returned by the SQL query + o.setAlternativeNames(prepareListFields(rs.getArray("alternativenames"), info)); o.setWebsiteurl(field(rs.getString("websiteurl"), info)); o.setLogourl(field(rs.getString("logourl"), info)); o.setEclegalbody(field(Boolean.toString(rs.getBoolean("eclegalbody")), info)); diff --git a/dhp-workflows/dhp-graph-mapper/src/main/resources/eu/dnetlib/dhp/oa/graph/sql/queryOpenOrgsForOrgsDedup.sql b/dhp-workflows/dhp-graph-mapper/src/main/resources/eu/dnetlib/dhp/oa/graph/sql/queryOpenOrgsForOrgsDedup.sql index 7089a7477..d9e4b855d 100644 --- a/dhp-workflows/dhp-graph-mapper/src/main/resources/eu/dnetlib/dhp/oa/graph/sql/queryOpenOrgsForOrgsDedup.sql +++ b/dhp-workflows/dhp-graph-mapper/src/main/resources/eu/dnetlib/dhp/oa/graph/sql/queryOpenOrgsForOrgsDedup.sql @@ -2,7 +2,7 @@ SELECT o.id AS organizationid, coalesce((array_agg(a.acronym))[1], o.name) AS legalshortname, o.name AS legalname, - array_agg(DISTINCT n.name) AS "alternativeNames", + array_remove(array_cat(array_agg(DISTINCT n.name), array_agg(DISTINCT a.acronym)), NULL) AS alternativenames, (array_agg(u.url))[1] AS websiteurl, '' AS logourl, o.creation_date AS dateofcollection, @@ -46,7 +46,7 @@ SELECT 'openorgsmesh'||substring(o.id, 13)||'-'||md5(n.name) AS organizationid, n.name AS legalshortname, n.name AS legalname, - ARRAY[]::text[] AS "alternativeNames", + ARRAY[]::text[] AS alternativenames, (array_agg(u.url))[1] AS websiteurl, '' AS logourl, o.creation_date AS dateofcollection, diff --git a/dhp-workflows/dhp-graph-mapper/src/main/resources/eu/dnetlib/dhp/oa/graph/sql/queryOpenOrgsForProvision.sql b/dhp-workflows/dhp-graph-mapper/src/main/resources/eu/dnetlib/dhp/oa/graph/sql/queryOpenOrgsForProvision.sql index 9588480ce..133b817d2 100644 --- a/dhp-workflows/dhp-graph-mapper/src/main/resources/eu/dnetlib/dhp/oa/graph/sql/queryOpenOrgsForProvision.sql +++ b/dhp-workflows/dhp-graph-mapper/src/main/resources/eu/dnetlib/dhp/oa/graph/sql/queryOpenOrgsForProvision.sql @@ -2,7 +2,7 @@ SELECT o.id AS organizationid, coalesce((array_agg(a.acronym))[1], o.name) AS legalshortname, o.name AS legalname, - array_agg(DISTINCT n.name) AS "alternativeNames", + array_remove(array_cat(array_agg(DISTINCT n.name), array_agg(DISTINCT a.acronym)), NULL) AS alternativenames, (array_agg(u.url))[1] AS websiteurl, '' AS logourl, o.creation_date AS dateofcollection, diff --git a/dhp-workflows/dhp-graph-mapper/src/main/resources/eu/dnetlib/dhp/oa/graph/sql/queryOrganizations.sql b/dhp-workflows/dhp-graph-mapper/src/main/resources/eu/dnetlib/dhp/oa/graph/sql/queryOrganizations.sql index 42ba0cf91..af690b215 100644 --- a/dhp-workflows/dhp-graph-mapper/src/main/resources/eu/dnetlib/dhp/oa/graph/sql/queryOrganizations.sql +++ b/dhp-workflows/dhp-graph-mapper/src/main/resources/eu/dnetlib/dhp/oa/graph/sql/queryOrganizations.sql @@ -23,8 +23,9 @@ SELECT d.id AS collectedfromid, d.officialname AS collectedfromname, o.country || '@@@dnet:countries' AS country, + array[]::text[] AS alternativenames, 'sysimport:crosswalk:entityregistry@@@dnet:provenance_actions' AS provenanceaction, - array_agg(DISTINCT i.pid || '###' || i.issuertype || '@@@dnet:pid_types') AS pid + array_agg(DISTINCT i.pid || '###' || i.issuertype || '@@@dnet:pid_types') AS pid FROM dsm_organizations o LEFT OUTER JOIN dsm_datasources d ON (d.id = o.collectedfrom) LEFT OUTER JOIN dsm_organizationpids p ON (p.organization = o.id) diff --git a/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/raw/MigrateDbEntitiesApplicationTest.java b/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/raw/MigrateDbEntitiesApplicationTest.java index b38da4569..203a2aae1 100644 --- a/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/raw/MigrateDbEntitiesApplicationTest.java +++ b/dhp-workflows/dhp-graph-mapper/src/test/java/eu/dnetlib/dhp/oa/graph/raw/MigrateDbEntitiesApplicationTest.java @@ -15,6 +15,7 @@ import java.sql.SQLException; import java.util.List; import java.util.Objects; +import com.google.common.collect.Lists; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.BeforeEach; @@ -118,6 +119,10 @@ public class MigrateDbEntitiesApplicationTest { assertEquals(getValueAsString("country", fields).split("@@@")[1], o.getCountry().getSchemeid()); assertEquals(getValueAsString("country", fields).split("@@@")[1], o.getCountry().getSchemename()); assertEquals(getValueAsString("collectedfromname", fields), o.getCollectedfrom().get(0).getValue()); + List alternativenames = getValueAsList("alternativenames", fields); + assertEquals(2, alternativenames.size()); + assertTrue(alternativenames.contains("Pippo")); + assertTrue(alternativenames.contains("Foo")); } @Test @@ -339,6 +344,10 @@ public class MigrateDbEntitiesApplicationTest { .findFirst() .get(); } + + private List getValueAsList(final String name, final List fields) { + return (List) getValueAs(name, fields); + } } class TypedField { diff --git a/dhp-workflows/dhp-graph-mapper/src/test/resources/eu/dnetlib/dhp/oa/graph/raw/organizations_resultset_entry.json b/dhp-workflows/dhp-graph-mapper/src/test/resources/eu/dnetlib/dhp/oa/graph/raw/organizations_resultset_entry.json index 811a9079f..cac6e5a32 100644 --- a/dhp-workflows/dhp-graph-mapper/src/test/resources/eu/dnetlib/dhp/oa/graph/raw/organizations_resultset_entry.json +++ b/dhp-workflows/dhp-graph-mapper/src/test/resources/eu/dnetlib/dhp/oa/graph/raw/organizations_resultset_entry.json @@ -123,5 +123,12 @@ "field": "provenanceaction", "type": "not_used", "value": "sysimport:crosswalk:entityregistry@@@dnet:provenance_actions" + }, + { + "field": "alternativenames", + "type": "array", + "value": [ + "Pippo", "Foo" + ] } ] \ No newline at end of file