From 755eade2fbbff15d212d5a2d3b39354cc04172c7 Mon Sep 17 00:00:00 2001 From: "michele.artini" Date: Wed, 4 Mar 2020 14:49:45 +0100 Subject: [PATCH] fix creation ids --- .../step1/MigrateDbEntitiesApplication.java | 20 ++++++++-------- .../step2/AbstractMdRecordToOafMapper.java | 6 ++--- .../dhp/migration/step2/OafToOafMapper.java | 4 ++-- .../dhp/migration/step2/OdfToOafMapper.java | 6 ++--- .../dhp/migration/utils/OafMapperUtils.java | 24 +++++++++++-------- 5 files changed, 32 insertions(+), 28 deletions(-) diff --git a/dhp-workflows/dhp-aggregation/src/main/java/eu/dnetlib/dhp/migration/step1/MigrateDbEntitiesApplication.java b/dhp-workflows/dhp-aggregation/src/main/java/eu/dnetlib/dhp/migration/step1/MigrateDbEntitiesApplication.java index b6ebc6b98..2d5c425a1 100644 --- a/dhp-workflows/dhp-aggregation/src/main/java/eu/dnetlib/dhp/migration/step1/MigrateDbEntitiesApplication.java +++ b/dhp-workflows/dhp-aggregation/src/main/java/eu/dnetlib/dhp/migration/step1/MigrateDbEntitiesApplication.java @@ -117,7 +117,7 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i final Datasource ds = new Datasource(); - ds.setId(createOpenaireId(10, rs.getString("datasourceid"))); + ds.setId(createOpenaireId(10, rs.getString("datasourceid"), true)); ds.setOriginalId(Arrays.asList(rs.getString("datasourceid"))); ds.setCollectedfrom(listKeyValues(rs.getString("collectedfromid"), rs.getString("collectedfromname"))); ds.setPid(new ArrayList<>()); @@ -224,7 +224,7 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i final Project p = new Project(); - p.setId(createOpenaireId(40, rs.getString("projectid"))); + p.setId(createOpenaireId(40, rs.getString("projectid"), true)); p.setOriginalId(Arrays.asList(rs.getString("projectid"))); p.setCollectedfrom(listKeyValues(rs.getString("collectedfromid"), rs.getString("collectedfromname"))); p.setPid(new ArrayList<>()); @@ -314,7 +314,7 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i final Organization o = new Organization(); - o.setId(createOpenaireId(20, rs.getString("organizationid"))); + o.setId(createOpenaireId(20, rs.getString("organizationid"), true)); o.setOriginalId(Arrays.asList(rs.getString("organizationid"))); o.setCollectedfrom(listKeyValues(rs.getString("collectedfromid"), rs.getString("collectedfromname"))); o.setPid(new ArrayList<>()); @@ -378,8 +378,8 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i try { final DataInfo info = prepareDataInfo(rs); - final String orgId = createOpenaireId(20, rs.getString("organization")); - final String dsId = createOpenaireId(10, rs.getString("datasource")); + final String orgId = createOpenaireId(20, rs.getString("organization"), true); + final String dsId = createOpenaireId(10, rs.getString("datasource"), true); final List collectedFrom = listKeyValues(rs.getString("collectedfromid"), rs.getString("collectedfromname")); final Relation r1 = new Relation(); @@ -427,8 +427,8 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i try { final DataInfo info = prepareDataInfo(rs); - final String orgId = createOpenaireId(20, rs.getString("resporganization")); - final String projectId = createOpenaireId(40, rs.getString("project")); + final String orgId = createOpenaireId(20, rs.getString("resporganization"), true); + final String projectId = createOpenaireId(40, rs.getString("project"), true); final List collectedFrom = listKeyValues(rs.getString("collectedfromid"), rs.getString("collectedfromname")); final Relation r1 = new Relation(); @@ -493,14 +493,14 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i } else { r = new Publication(); } - r.setId(createOpenaireId(50, rs.getString("target_id"))); + r.setId(createOpenaireId(50, rs.getString("target_id"), false)); r.setLastupdatetimestamp(lastUpdateTimestamp); r.setContext(prepareContext(rs.getString("source_id"), info)); r.setDataInfo(info); emitOaf(r); } else { - final String sourceId = createOpenaireId(rs.getString("source_type"), rs.getString("source_id")); - final String targetId = createOpenaireId(rs.getString("target_type"), rs.getString("target_id")); + final String sourceId = createOpenaireId(rs.getString("source_type"), rs.getString("source_id"), false); + final String targetId = createOpenaireId(rs.getString("target_type"), rs.getString("target_id"), false); final Relation r1 = new Relation(); final Relation r2 = new Relation(); diff --git a/dhp-workflows/dhp-aggregation/src/main/java/eu/dnetlib/dhp/migration/step2/AbstractMdRecordToOafMapper.java b/dhp-workflows/dhp-aggregation/src/main/java/eu/dnetlib/dhp/migration/step2/AbstractMdRecordToOafMapper.java index 245d53df0..7c3000fba 100644 --- a/dhp-workflows/dhp-aggregation/src/main/java/eu/dnetlib/dhp/migration/step2/AbstractMdRecordToOafMapper.java +++ b/dhp-workflows/dhp-aggregation/src/main/java/eu/dnetlib/dhp/migration/step2/AbstractMdRecordToOafMapper.java @@ -153,10 +153,10 @@ public abstract class AbstractMdRecordToOafMapper { final List res = new ArrayList<>(); - final String docId = createOpenaireId(50, doc.valueOf("//dri:objIdentifier")); + final String docId = createOpenaireId(50, doc.valueOf("//dri:objIdentifier"), false); for (final Object o : doc.selectNodes("//oaf:projectid")) { - final String projectId = createOpenaireId(40, ((Node) o).getText()); + final String projectId = createOpenaireId(40, ((Node) o).getText(), true); final Relation r1 = new Relation(); r1.setRelType("resultProject"); @@ -197,7 +197,7 @@ public abstract class AbstractMdRecordToOafMapper { final long lastUpdateTimestamp) { r.setDataInfo(info); r.setLastupdatetimestamp(lastUpdateTimestamp); - r.setId(createOpenaireId(50, doc.valueOf("//dri:objIdentifier"))); + r.setId(createOpenaireId(50, doc.valueOf("//dri:objIdentifier"), false)); r.setOriginalId(Arrays.asList(doc.valueOf("//dri:objIdentifier"))); r.setCollectedfrom(Arrays.asList(collectedFrom)); r.setPid(prepareListStructProps(doc, "//oaf:identifier", "@identifierType", "dnet:pid_types", "dnet:pid_types", info)); diff --git a/dhp-workflows/dhp-aggregation/src/main/java/eu/dnetlib/dhp/migration/step2/OafToOafMapper.java b/dhp-workflows/dhp-aggregation/src/main/java/eu/dnetlib/dhp/migration/step2/OafToOafMapper.java index 0ca13941d..110abc486 100644 --- a/dhp-workflows/dhp-aggregation/src/main/java/eu/dnetlib/dhp/migration/step2/OafToOafMapper.java +++ b/dhp-workflows/dhp-aggregation/src/main/java/eu/dnetlib/dhp/migration/step2/OafToOafMapper.java @@ -202,12 +202,12 @@ public class OafToOafMapper extends AbstractMdRecordToOafMapper { final KeyValue collectedFrom, final DataInfo info, final long lastUpdateTimestamp) { - final String docId = createOpenaireId(50, doc.valueOf("//dri:objIdentifier")); + final String docId = createOpenaireId(50, doc.valueOf("//dri:objIdentifier"), false); final List res = new ArrayList<>(); for (final Object o : doc.selectNodes("//*[local-name()='relatedDataset']")) { - final String otherId = createOpenaireId(50, ((Node) o).getText()); + final String otherId = createOpenaireId(50, ((Node) o).getText(), false); final Relation r1 = new Relation(); r1.setRelType("resultResult"); diff --git a/dhp-workflows/dhp-aggregation/src/main/java/eu/dnetlib/dhp/migration/step2/OdfToOafMapper.java b/dhp-workflows/dhp-aggregation/src/main/java/eu/dnetlib/dhp/migration/step2/OdfToOafMapper.java index 01c2d4b07..b4868b8f9 100644 --- a/dhp-workflows/dhp-aggregation/src/main/java/eu/dnetlib/dhp/migration/step2/OdfToOafMapper.java +++ b/dhp-workflows/dhp-aggregation/src/main/java/eu/dnetlib/dhp/migration/step2/OdfToOafMapper.java @@ -219,12 +219,12 @@ public class OdfToOafMapper extends AbstractMdRecordToOafMapper { @Override protected List addOtherResultRels(final Document doc, final KeyValue collectedFrom, final DataInfo info, final long lastUpdateTimestamp) { - final String docId = createOpenaireId(50, doc.valueOf("//dri:objIdentifier")); + final String docId = createOpenaireId(50, doc.valueOf("//dri:objIdentifier"), false); final List res = new ArrayList<>(); - for (final Object o : doc.selectNodes("//*[local-name() = 'resource']//*[local-name()='relatedIdentifier' and ./@relatedIdentifierType='OPENAIRE']")) { - final String otherId = createOpenaireId(50, ((Node) o).getText()); + for (final Object o : doc.selectNodes("//datacite:relatedIdentifier[@relatedIdentifierType='OPENAIRE']")) { + final String otherId = createOpenaireId(50, ((Node) o).getText(), false); final String type = ((Node) o).valueOf("@relationType"); if (type.equals("IsSupplementTo")) { diff --git a/dhp-workflows/dhp-aggregation/src/main/java/eu/dnetlib/dhp/migration/utils/OafMapperUtils.java b/dhp-workflows/dhp-aggregation/src/main/java/eu/dnetlib/dhp/migration/utils/OafMapperUtils.java index 89b344c68..8e51c1858 100644 --- a/dhp-workflows/dhp-aggregation/src/main/java/eu/dnetlib/dhp/migration/utils/OafMapperUtils.java +++ b/dhp-workflows/dhp-aggregation/src/main/java/eu/dnetlib/dhp/migration/utils/OafMapperUtils.java @@ -163,24 +163,28 @@ public class OafMapperUtils { return d; } - public static String createOpenaireId(final int prefix, final String originalId) { - final String nsPrefix = StringUtils.substringBefore(originalId, "::"); - final String rest = StringUtils.substringAfter(originalId, "::"); - return String.format("%s|%s::%s", prefix, nsPrefix, DHPUtils.md5(rest)); + public static String createOpenaireId(final int prefix, final String originalId, final boolean to_md5) { + if (to_md5) { + final String nsPrefix = StringUtils.substringBefore(originalId, "::"); + final String rest = StringUtils.substringAfter(originalId, "::"); + return String.format("%s|%s::%s", prefix, nsPrefix, DHPUtils.md5(rest)); + } else { + return String.format("%s|%s", prefix, originalId); + } } - public static String createOpenaireId(final String type, final String originalId) { + public static String createOpenaireId(final String type, final String originalId, final boolean to_md5) { switch (type) { case "datasource": - return createOpenaireId(10, originalId); + return createOpenaireId(10, originalId, to_md5); case "organization": - return createOpenaireId(20, originalId); + return createOpenaireId(20, originalId, to_md5); case "person": - return createOpenaireId(30, originalId); + return createOpenaireId(30, originalId, to_md5); case "project": - return createOpenaireId(40, originalId); + return createOpenaireId(40, originalId, to_md5); default: - return createOpenaireId(50, originalId); + return createOpenaireId(50, originalId, to_md5); } }