From 4c8e820ff0af53cb2b86d6553281afb2839d1699 Mon Sep 17 00:00:00 2001 From: Claudio Atzori Date: Tue, 14 Jun 2022 08:49:02 +0200 Subject: [PATCH] mapping relationship from trasformed records based on oaf:relation --- .../raw/AbstractMdRecordToOafMapper.java | 56 +++++++++---------- .../dnetlib/dhp/oa/graph/raw/oaf_record.xml | 4 +- 2 files changed, 28 insertions(+), 32 deletions(-) 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 bf337e6c9..739be3df4 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 @@ -284,42 +284,36 @@ public abstract class AbstractMdRecordToOafMapper { for (Object o : doc.selectNodes("//oaf:relation")) { Element element = (Element) o; - final Relation rel = new Relation(); - rel.setCollectedfrom(entity.getCollectedfrom()); - rel.setDataInfo(entity.getDataInfo()); - rel.setLastupdatetimestamp(entity.getLastupdatetimestamp()); + final String target = StringUtils.trim(element.getText()); + final String relType = element.attributeValue("relType"); + final String subRelType = element.attributeValue("subRelType"); + final String relClass = element.attributeValue("relClass"); - String relType = element.attributeValue("relType"); - String subRelType = element.attributeValue("subRelType"); - String relClass = element.attributeValue("relClass"); - String relClassInverse = ModelSupport - .findInverse(ModelSupport.rel(relType, subRelType, relClass)) - .getInverseRelClass(); + if (StringUtils.isNotBlank(target) && StringUtils.isNotBlank(relType) && StringUtils.isNotBlank(subRelType) + && StringUtils.isNotBlank(relClass)) { - rel.setSource(entity.getId()); - String target = StringUtils.trim(element.getText()); + final String relClassInverse = ModelSupport + .findInverse(ModelSupport.rel(relType, subRelType, relClass)) + .getInverseRelClass(); + final String validationdDate = ((Node) o).valueOf("@validationDate"); - final String validationdDate = ((Node) o).valueOf("@validationDate"); - - if (StringUtils.isNotBlank(target)) { - - // TODO discover the target entity type with a dedicated attribute, e.g. @targetType. - final String[] parts = relType.split("(?=\\p{Upper})"); - final String targetType = parts[1].toLowerCase(); - final String targetId = createOpenaireId(targetType, target, true); - - rels - .add( - getRelation( - entity.getId(), targetId, relType, subRelType, relClass, entity, validationdDate)); - rels - .add( - getRelation( - targetId, entity.getId(), relType, subRelType, relClassInverse, entity, validationdDate)); + if (StringUtils.isNotBlank(target)) { + final String targetType = element.attributeValue("targetType"); + if (StringUtils.isNotBlank(targetType)) { + final String targetId = createOpenaireId(targetType, target, true); + rels + .add( + getRelation( + entity.getId(), targetId, relType, subRelType, relClass, entity, validationdDate)); + rels + .add( + getRelation( + targetId, entity.getId(), relType, subRelType, relClassInverse, entity, + validationdDate)); + } + } } - } - return rels; } diff --git a/dhp-workflows/dhp-graph-mapper/src/test/resources/eu/dnetlib/dhp/oa/graph/raw/oaf_record.xml b/dhp-workflows/dhp-graph-mapper/src/test/resources/eu/dnetlib/dhp/oa/graph/raw/oaf_record.xml index 2946ba0b5..277578185 100644 --- a/dhp-workflows/dhp-graph-mapper/src/test/resources/eu/dnetlib/dhp/oa/graph/raw/oaf_record.xml +++ b/dhp-workflows/dhp-graph-mapper/src/test/resources/eu/dnetlib/dhp/oa/graph/raw/oaf_record.xml @@ -62,10 +62,12 @@ 0001 ror_________::https://ror.org/02gdcn153 + subRelType="affiliation" + targetType="organization">ror_________::https://ror.org/02gdcn153 corda_______::226852