From 5130eac24747237213a80ce552c891128adf6366 Mon Sep 17 00:00:00 2001 From: Claudio Atzori Date: Fri, 24 Jun 2022 17:16:42 +0200 Subject: [PATCH 1/2] mapping by participant project contribution --- .../dhp/schema/oaf/utils/OafMapperUtils.java | 58 +++++++ .../raw/AbstractMdRecordToOafMapper.java | 52 ++---- .../raw/MigrateDbEntitiesApplication.java | 155 +++++------------- .../oa/graph/sql/queryProjectOrganization.sql | 1 + 4 files changed, 114 insertions(+), 152 deletions(-) diff --git a/dhp-common/src/main/java/eu/dnetlib/dhp/schema/oaf/utils/OafMapperUtils.java b/dhp-common/src/main/java/eu/dnetlib/dhp/schema/oaf/utils/OafMapperUtils.java index ac9cfe330..6f452e846 100644 --- a/dhp-common/src/main/java/eu/dnetlib/dhp/schema/oaf/utils/OafMapperUtils.java +++ b/dhp-common/src/main/java/eu/dnetlib/dhp/schema/oaf/utils/OafMapperUtils.java @@ -419,4 +419,62 @@ public class OafMapperUtils { m.setUnit(Arrays.asList(newKeyValueInstance(key, value, dataInfo))); return m; } + + public static Relation getRelation(final String source, + final String target, + final String relType, + final String subRelType, + final String relClass, + final OafEntity entity) { + return getRelation(source, target, relType, subRelType, relClass, entity, null); + } + + public static Relation getRelation(final String source, + final String target, + final String relType, + final String subRelType, + final String relClass, + final OafEntity entity, + final String validationDate) { + return getRelation( + source, target, relType, subRelType, relClass, entity.getCollectedfrom(), entity.getDataInfo(), + entity.getLastupdatetimestamp(), validationDate, null); + } + + public static Relation getRelation(final String source, + final String target, + final String relType, + final String subRelType, + final String relClass, + final List collectedfrom, + final DataInfo dataInfo, + final Long lastupdatetimestamp) { + return getRelation( + source, target, relType, subRelType, relClass, collectedfrom, dataInfo, lastupdatetimestamp, null, null); + } + + public static Relation getRelation(final String source, + final String target, + final String relType, + final String subRelType, + final String relClass, + final List collectedfrom, + final DataInfo dataInfo, + final Long lastupdatetimestamp, + final String validationDate, + final List properties) { + final Relation rel = new Relation(); + rel.setRelType(relType); + rel.setSubRelType(subRelType); + rel.setRelClass(relClass); + rel.setSource(source); + rel.setTarget(target); + rel.setCollectedfrom(collectedfrom); + rel.setDataInfo(dataInfo); + rel.setLastupdatetimestamp(lastupdatetimestamp); + rel.setValidated(StringUtils.isNotBlank(validationDate)); + rel.setValidationDate(StringUtils.isNotBlank(validationDate) ? validationDate : null); + rel.setProperties(properties); + return rel; + } } 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 739be3df4..846440a69 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 @@ -267,10 +267,13 @@ public abstract class AbstractMdRecordToOafMapper { res .add( - getRelation( - docId, projectId, RESULT_PROJECT, OUTCOME, IS_PRODUCED_BY, entity, validationdDate)); + OafMapperUtils + .getRelation( + docId, projectId, RESULT_PROJECT, OUTCOME, IS_PRODUCED_BY, entity, validationdDate)); res - .add(getRelation(projectId, docId, RESULT_PROJECT, OUTCOME, PRODUCES, entity, validationdDate)); + .add( + OafMapperUtils + .getRelation(projectId, docId, RESULT_PROJECT, OUTCOME, PRODUCES, entity, validationdDate)); } } @@ -303,13 +306,16 @@ public abstract class AbstractMdRecordToOafMapper { final String targetId = createOpenaireId(targetType, target, true); rels .add( - getRelation( - entity.getId(), targetId, relType, subRelType, relClass, entity, validationdDate)); + OafMapperUtils + .getRelation( + entity.getId(), targetId, relType, subRelType, relClass, entity, + validationdDate)); rels .add( - getRelation( - targetId, entity.getId(), relType, subRelType, relClassInverse, entity, - validationdDate)); + OafMapperUtils + .getRelation( + targetId, entity.getId(), relType, subRelType, relClassInverse, entity, + validationdDate)); } } } @@ -317,36 +323,6 @@ public abstract class AbstractMdRecordToOafMapper { return rels; } - protected Relation getRelation(final String source, - final String target, - final String relType, - final String subRelType, - final String relClass, - final OafEntity entity) { - return getRelation(source, target, relType, subRelType, relClass, entity, null); - } - - protected Relation getRelation(final String source, - final String target, - final String relType, - final String subRelType, - final String relClass, - final OafEntity entity, - final String validationDate) { - final Relation rel = new Relation(); - rel.setRelType(relType); - rel.setSubRelType(subRelType); - rel.setRelClass(relClass); - rel.setSource(source); - rel.setTarget(target); - rel.setCollectedfrom(entity.getCollectedfrom()); - rel.setDataInfo(entity.getDataInfo()); - rel.setLastupdatetimestamp(entity.getLastupdatetimestamp()); - rel.setValidated(StringUtils.isNotBlank(validationDate)); - rel.setValidationDate(StringUtils.isNotBlank(validationDate) ? validationDate : null); - return rel; - } - protected abstract List addOtherResultRels( final Document doc, final OafEntity entity); 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 63fa8b7e0..8296e99cd 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 @@ -1,32 +1,7 @@ package eu.dnetlib.dhp.oa.graph.raw; -import static eu.dnetlib.dhp.schema.common.ModelConstants.DATASET_DEFAULT_RESULTTYPE; -import static eu.dnetlib.dhp.schema.common.ModelConstants.DATASOURCE_ORGANIZATION; -import static eu.dnetlib.dhp.schema.common.ModelConstants.DNET_PROVENANCE_ACTIONS; -import static eu.dnetlib.dhp.schema.common.ModelConstants.ENTITYREGISTRY_PROVENANCE_ACTION; -import static eu.dnetlib.dhp.schema.common.ModelConstants.HAS_PARTICIPANT; -import static eu.dnetlib.dhp.schema.common.ModelConstants.IS_MERGED_IN; -import static eu.dnetlib.dhp.schema.common.ModelConstants.IS_PARTICIPANT; -import static eu.dnetlib.dhp.schema.common.ModelConstants.IS_PRODUCED_BY; -import static eu.dnetlib.dhp.schema.common.ModelConstants.IS_PROVIDED_BY; -import static eu.dnetlib.dhp.schema.common.ModelConstants.IS_RELATED_TO; -import static eu.dnetlib.dhp.schema.common.ModelConstants.MERGES; -import static eu.dnetlib.dhp.schema.common.ModelConstants.ORG_ORG_RELTYPE; -import static eu.dnetlib.dhp.schema.common.ModelConstants.ORP_DEFAULT_RESULTTYPE; -import static eu.dnetlib.dhp.schema.common.ModelConstants.OUTCOME; -import static eu.dnetlib.dhp.schema.common.ModelConstants.PARTICIPATION; -import static eu.dnetlib.dhp.schema.common.ModelConstants.PRODUCES; -import static eu.dnetlib.dhp.schema.common.ModelConstants.PROJECT_ORGANIZATION; -import static eu.dnetlib.dhp.schema.common.ModelConstants.PROVIDES; -import static eu.dnetlib.dhp.schema.common.ModelConstants.PROVISION; -import static eu.dnetlib.dhp.schema.common.ModelConstants.PUBLICATION_DATASET; -import static eu.dnetlib.dhp.schema.common.ModelConstants.PUBLICATION_DEFAULT_RESULTTYPE; -import static eu.dnetlib.dhp.schema.common.ModelConstants.RELATIONSHIP; -import static eu.dnetlib.dhp.schema.common.ModelConstants.RESULT_PROJECT; -import static eu.dnetlib.dhp.schema.common.ModelConstants.RESULT_RESULT; -import static eu.dnetlib.dhp.schema.common.ModelConstants.SOFTWARE_DEFAULT_RESULTTYPE; -import static eu.dnetlib.dhp.schema.common.ModelConstants.USER_CLAIM; +import static eu.dnetlib.dhp.schema.common.ModelConstants.*; import static eu.dnetlib.dhp.schema.oaf.utils.OafMapperUtils.*; import java.io.Closeable; @@ -45,6 +20,8 @@ import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.collect.Lists; + import eu.dnetlib.dhp.application.ArgumentApplicationParser; import eu.dnetlib.dhp.common.DbClient; import eu.dnetlib.dhp.common.vocabulary.VocabularyGroup; @@ -68,6 +45,7 @@ import eu.dnetlib.dhp.schema.oaf.Relation; import eu.dnetlib.dhp.schema.oaf.Result; import eu.dnetlib.dhp.schema.oaf.Software; import eu.dnetlib.dhp.schema.oaf.StructuredProperty; +import eu.dnetlib.dhp.schema.oaf.utils.OafMapperUtils; import eu.dnetlib.dhp.utils.ISLookupClientFactory; public class MigrateDbEntitiesApplication extends AbstractMigrationApplication implements Closeable { @@ -437,25 +415,14 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i final List collectedFrom = listKeyValues( createOpenaireId(10, rs.getString("collectedfromid"), true), rs.getString("collectedfromname")); - final Relation r1 = new Relation(); - r1.setRelType(DATASOURCE_ORGANIZATION); - r1.setSubRelType(PROVISION); - r1.setRelClass(IS_PROVIDED_BY); - r1.setSource(dsId); - r1.setTarget(orgId); - r1.setCollectedfrom(collectedFrom); - r1.setDataInfo(info); - r1.setLastupdatetimestamp(lastUpdateTimestamp); + final Relation r1 = OafMapperUtils + .getRelation( + dsId, orgId, DATASOURCE_ORGANIZATION, PRODUCES, IS_PROVIDED_BY, collectedFrom, info, + lastUpdateTimestamp); - final Relation r2 = new Relation(); - r2.setRelType(DATASOURCE_ORGANIZATION); - r2.setSubRelType(PROVISION); - r2.setRelClass(PROVIDES); - r2.setSource(orgId); - r2.setTarget(dsId); - r2.setCollectedfrom(collectedFrom); - r2.setDataInfo(info); - r2.setLastupdatetimestamp(lastUpdateTimestamp); + final Relation r2 = OafMapperUtils + .getRelation( + orgId, dsId, DATASOURCE_ORGANIZATION, PRODUCES, PROVIDES, collectedFrom, info, lastUpdateTimestamp); return Arrays.asList(r1, r2); } catch (final Exception e) { @@ -471,25 +438,20 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i final List collectedFrom = listKeyValues( createOpenaireId(10, rs.getString("collectedfromid"), true), rs.getString("collectedfromname")); - final Relation r1 = new Relation(); - r1.setRelType(PROJECT_ORGANIZATION); - r1.setSubRelType(PARTICIPATION); - r1.setRelClass(HAS_PARTICIPANT); - r1.setSource(projectId); - r1.setTarget(orgId); - r1.setCollectedfrom(collectedFrom); - r1.setDataInfo(info); - r1.setLastupdatetimestamp(lastUpdateTimestamp); + final List properties = Lists + .newArrayList( + keyValue("contribution", String.valueOf(rs.getDouble("totalcost"))), + keyValue("currency", rs.getString("currency"))); - final Relation r2 = new Relation(); - r2.setRelType(PROJECT_ORGANIZATION); - r2.setSubRelType(PARTICIPATION); - r2.setRelClass(IS_PARTICIPANT); - r2.setSource(orgId); - r2.setTarget(projectId); - r2.setCollectedfrom(collectedFrom); - r2.setDataInfo(info); - r2.setLastupdatetimestamp(lastUpdateTimestamp); + final Relation r1 = OafMapperUtils + .getRelation( + projectId, orgId, PROJECT_ORGANIZATION, PARTICIPATION, HAS_PARTICIPANT, collectedFrom, info, + lastUpdateTimestamp, null, properties); + + final Relation r2 = OafMapperUtils + .getRelation( + orgId, projectId, PROJECT_ORGANIZATION, PARTICIPATION, IS_PARTICIPANT, collectedFrom, info, + lastUpdateTimestamp, null, properties); return Arrays.asList(r1, r2); } catch (final Exception e) { @@ -703,25 +665,12 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i final List collectedFrom = listKeyValues( createOpenaireId(10, rs.getString("collectedfromid"), true), rs.getString("collectedfromname")); - final Relation r1 = new Relation(); - r1.setRelType(ORG_ORG_RELTYPE); - r1.setSubRelType(ModelConstants.DEDUP); - r1.setRelClass(MERGES); - r1.setSource(orgId1); - r1.setTarget(orgId2); - r1.setCollectedfrom(collectedFrom); - r1.setDataInfo(info); - r1.setLastupdatetimestamp(lastUpdateTimestamp); + final Relation r1 = OafMapperUtils + .getRelation(orgId1, orgId2, ORG_ORG_RELTYPE, DEDUP, MERGES, collectedFrom, info, lastUpdateTimestamp); - final Relation r2 = new Relation(); - r2.setRelType(ORG_ORG_RELTYPE); - r2.setSubRelType(ModelConstants.DEDUP); - r2.setRelClass(IS_MERGED_IN); - r2.setSource(orgId2); - r2.setTarget(orgId1); - r2.setCollectedfrom(collectedFrom); - r2.setDataInfo(info); - r2.setLastupdatetimestamp(lastUpdateTimestamp); + final Relation r2 = OafMapperUtils + .getRelation( + orgId2, orgId1, ORG_ORG_RELTYPE, DEDUP, IS_MERGED_IN, collectedFrom, info, lastUpdateTimestamp); return Arrays.asList(r1, r2); } catch (final Exception e) { throw new RuntimeException(e); @@ -738,17 +687,12 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i final List collectedFrom = listKeyValues( createOpenaireId(10, rs.getString("collectedfromid"), true), rs.getString("collectedfromname")); - final Relation r = new Relation(); - r.setRelType(ORG_ORG_RELTYPE); - r.setSubRelType(ModelConstants.RELATIONSHIP); - r.setRelClass(rs.getString("type")); - r.setSource(orgId1); - r.setTarget(orgId2); - r.setCollectedfrom(collectedFrom); - r.setDataInfo(info); - r.setLastupdatetimestamp(lastUpdateTimestamp); - - return Arrays.asList(r); + return Arrays + .asList( + OafMapperUtils + .getRelation( + orgId1, orgId2, ORG_ORG_RELTYPE, RELATIONSHIP, rs.getString("type"), collectedFrom, info, + lastUpdateTimestamp)); } catch (final Exception e) { throw new RuntimeException(e); } @@ -765,29 +709,12 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i final List collectedFrom = listKeyValues( createOpenaireId(10, rs.getString("collectedfromid"), true), rs.getString("collectedfromname")); - final Relation r1 = new Relation(); - r1.setRelType(ORG_ORG_RELTYPE); - r1.setSubRelType(ModelConstants.DEDUP); - r1.setRelClass(relClass); - r1.setSource(orgId1); - r1.setTarget(orgId2); - r1.setCollectedfrom(collectedFrom); - r1.setDataInfo(info); - r1.setLastupdatetimestamp(lastUpdateTimestamp); - - // removed because there's no difference between two sides //TODO - // final Relation r2 = new Relation(); - // r2.setRelType(ORG_ORG_RELTYPE); - // r2.setSubRelType(ORG_ORG_SUBRELTYPE); - // r2.setRelClass(relClass); - // r2.setSource(orgId2); - // r2.setTarget(orgId1); - // r2.setCollectedfrom(collectedFrom); - // r2.setDataInfo(info); - // r2.setLastupdatetimestamp(lastUpdateTimestamp); - // return Arrays.asList(r1, r2); - - return Arrays.asList(r1); + return Arrays + .asList( + OafMapperUtils + .getRelation( + orgId1, orgId2, ORG_ORG_RELTYPE, DEDUP, relClass, collectedFrom, info, + lastUpdateTimestamp)); } catch (final Exception e) { throw new RuntimeException(e); } diff --git a/dhp-workflows/dhp-graph-mapper/src/main/resources/eu/dnetlib/dhp/oa/graph/sql/queryProjectOrganization.sql b/dhp-workflows/dhp-graph-mapper/src/main/resources/eu/dnetlib/dhp/oa/graph/sql/queryProjectOrganization.sql index d9a77427d..9a5133e4b 100644 --- a/dhp-workflows/dhp-graph-mapper/src/main/resources/eu/dnetlib/dhp/oa/graph/sql/queryProjectOrganization.sql +++ b/dhp-workflows/dhp-graph-mapper/src/main/resources/eu/dnetlib/dhp/oa/graph/sql/queryProjectOrganization.sql @@ -3,6 +3,7 @@ SELECT po.resporganization AS resporganization, po.participantnumber AS participantnumber, po.contribution AS contribution, + po.currency AS currency, NULL AS startdate, NULL AS enddate, false AS inferred, From 1dd1e4fe3a224935d3c021f09ae4284e2a22b29e Mon Sep 17 00:00:00 2001 From: Claudio Atzori Date: Thu, 28 Jul 2022 11:27:08 +0200 Subject: [PATCH 2/2] extended test for mapping project_organization relations --- .../raw/MigrateDbEntitiesApplication.java | 2 +- .../raw/MigrateDbEntitiesApplicationTest.java | 62 ++++++++++++++----- .../projectorganization_resultset_entry.json | 17 +++-- 3 files changed, 57 insertions(+), 24 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 8296e99cd..f40d3d19b 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 @@ -440,7 +440,7 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i final List properties = Lists .newArrayList( - keyValue("contribution", String.valueOf(rs.getDouble("totalcost"))), + keyValue("contribution", String.valueOf(rs.getDouble("contribution"))), keyValue("currency", rs.getString("currency"))); final Relation r1 = OafMapperUtils 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 9048a22ea..06947103a 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 @@ -1,9 +1,7 @@ package eu.dnetlib.dhp.oa.graph.raw; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.lenient; @@ -31,11 +29,12 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import eu.dnetlib.dhp.common.vocabulary.VocabularyGroup; +import eu.dnetlib.dhp.schema.common.ModelConstants; import eu.dnetlib.dhp.schema.oaf.*; import eu.dnetlib.dhp.schema.oaf.utils.OafMapperUtils; @ExtendWith(MockitoExtension.class) -public class MigrateDbEntitiesApplicationTest { +class MigrateDbEntitiesApplicationTest { private MigrateDbEntitiesApplication app; @@ -61,7 +60,7 @@ public class MigrateDbEntitiesApplicationTest { } @Test - public void testProcessService() throws Exception { + void testProcessService() throws Exception { final List fields = prepareMocks("services_resultset_entry.json"); final List list = app.processService(rs); @@ -74,7 +73,7 @@ public class MigrateDbEntitiesApplicationTest { .getCollectedfrom() .stream() .map(KeyValue::getKey) - .forEach(dsId -> assertValidId(dsId)); + .forEach(this::assertValidId); assertEquals(1, ds.getPid().size()); assertEquals("r3d100010218", ds.getPid().get(0).getValue()); @@ -163,14 +162,14 @@ public class MigrateDbEntitiesApplicationTest { .stream() .map(Qualifier::getSchemeid) .collect(Collectors.toCollection(HashSet::new)); - assertTrue(cpSchemeId.size() == 1); + assertEquals(1,cpSchemeId.size()); assertTrue(cpSchemeId.contains("eosc:contentpolicies")); HashSet cpSchemeName = ds .getContentpolicies() .stream() .map(Qualifier::getSchemename) .collect(Collectors.toCollection(HashSet::new)); - assertTrue(cpSchemeName.size() == 1); + assertEquals(1, cpSchemeName.size()); assertTrue(cpSchemeName.contains("eosc:contentpolicies")); assertEquals(2, ds.getContentpolicies().size()); assertEquals("Taxonomic classification", ds.getContentpolicies().get(0).getClassid()); @@ -193,7 +192,7 @@ public class MigrateDbEntitiesApplicationTest { } @Test - public void testProcessProject() throws Exception { + void testProcessProject() throws Exception { final List fields = prepareMocks("projects_resultset_entry.json"); final List list = app.processProject(rs); @@ -211,7 +210,7 @@ public class MigrateDbEntitiesApplicationTest { } @Test - public void testProcessOrganization() throws Exception { + void testProcessOrganization() throws Exception { final List fields = prepareMocks("organizations_resultset_entry.json"); final List list = app.processOrganization(rs); @@ -238,7 +237,7 @@ public class MigrateDbEntitiesApplicationTest { } @Test - public void testProcessDatasourceOrganization() throws Exception { + void testProcessDatasourceOrganization() throws Exception { final List fields = prepareMocks("datasourceorganization_resultset_entry.json"); final List list = app.processServiceOrganization(rs); @@ -255,7 +254,7 @@ public class MigrateDbEntitiesApplicationTest { } @Test - public void testProcessProjectOrganization() throws Exception { + void testProcessProjectOrganization() throws Exception { final List fields = prepareMocks("projectorganization_resultset_entry.json"); final List list = app.processProjectOrganization(rs); @@ -271,6 +270,38 @@ public class MigrateDbEntitiesApplicationTest { assertEquals(r2.getSource(), r1.getTarget()); assertValidId(r1.getCollectedfrom().get(0).getKey()); assertValidId(r2.getCollectedfrom().get(0).getKey()); + + assertEquals(ModelConstants.PROJECT_ORGANIZATION, r1.getRelType()); + assertEquals(ModelConstants.PROJECT_ORGANIZATION, r2.getRelType()); + + assertEquals(ModelConstants.PARTICIPATION, r1.getSubRelType()); + assertEquals(ModelConstants.PARTICIPATION, r2.getSubRelType()); + + if (r1.getSource().startsWith("40")) { + assertEquals(ModelConstants.HAS_PARTICIPANT, r1.getRelClass()); + assertEquals(ModelConstants.IS_PARTICIPANT, r2.getRelClass()); + } else if (r1.getSource().startsWith("20")) { + assertEquals(ModelConstants.IS_PARTICIPANT, r1.getRelClass()); + assertEquals(ModelConstants.HAS_PARTICIPANT, r2.getRelClass()); + } + + assertNotNull(r1.getProperties()); + checkProperty(r1, "contribution", "436754.0"); + checkProperty(r2, "contribution", "436754.0"); + + checkProperty(r1, "currency","EUR"); + checkProperty(r2, "currency", "EUR"); + } + + private void checkProperty(Relation r, String property, String value) { + final List p = r + .getProperties() + .stream() + .filter(kv -> kv.getKey().equals(property)) + .collect(Collectors.toList()); + assertFalse(p.isEmpty()); + assertEquals(1, p.size()); + assertEquals(value, p.get(0).getValue()); } @Test @@ -289,7 +320,7 @@ public class MigrateDbEntitiesApplicationTest { } @Test - public void testProcessClaims_rels() throws Exception { + void testProcessClaims_rels() throws Exception { final List fields = prepareMocks("claimsrel_resultset_entry.json"); final List list = app.processClaims(rs); @@ -320,9 +351,6 @@ public class MigrateDbEntitiesApplicationTest { assertValidId(r1.getCollectedfrom().get(0).getKey()); assertValidId(r2.getCollectedfrom().get(0).getKey()); - - // System.out.println(new ObjectMapper().writeValueAsString(r1)); - // System.out.println(new ObjectMapper().writeValueAsString(r2)); } private List prepareMocks(final String jsonFile) throws IOException, SQLException { @@ -385,7 +413,7 @@ public class MigrateDbEntitiesApplicationTest { final String[] values = ((List) tf.getValue()) .stream() .filter(Objects::nonNull) - .map(o -> o.toString()) + .map(Object::toString) .toArray(String[]::new); Mockito.when(arr.getArray()).thenReturn(values); diff --git a/dhp-workflows/dhp-graph-mapper/src/test/resources/eu/dnetlib/dhp/oa/graph/raw/projectorganization_resultset_entry.json b/dhp-workflows/dhp-graph-mapper/src/test/resources/eu/dnetlib/dhp/oa/graph/raw/projectorganization_resultset_entry.json index a3305926d..02cebae38 100644 --- a/dhp-workflows/dhp-graph-mapper/src/test/resources/eu/dnetlib/dhp/oa/graph/raw/projectorganization_resultset_entry.json +++ b/dhp-workflows/dhp-graph-mapper/src/test/resources/eu/dnetlib/dhp/oa/graph/raw/projectorganization_resultset_entry.json @@ -2,12 +2,12 @@ { "field": "project", "type": "string", - "value": "nsf_________::1700003" + "value": "corda__h2020::824273" }, { "field": "resporganization", "type": "string", - "value": "nsf_________::University_of_Notre_Dame" + "value": "corda__h2020::999945647" }, { "field": "participantnumber", @@ -16,8 +16,13 @@ }, { "field": "contribution", - "type": "not_used", - "value": null + "type": "double", + "value": 436754 + }, + { + "field": "currency", + "type": "string", + "value": "EUR" }, { "field": "startdate", @@ -52,12 +57,12 @@ { "field": "collectedfromid", "type": "string", - "value": "openaire____::nsf" + "value": "openaire____::corda_h2020" }, { "field": "collectedfromname", "type": "string", - "value": "NSF - National Science Foundation" + "value": "CORDA - COmmon Research DAta Warehouse - Horizon 2020" }, { "field": "semantics",