mapping relationship from trasformed records based on oaf:relation

This commit is contained in:
Claudio Atzori 2022-06-14 08:49:02 +02:00
parent 116902c028
commit 4c8e820ff0
2 changed files with 28 additions and 32 deletions

View File

@ -284,30 +284,23 @@ public abstract class AbstractMdRecordToOafMapper {
for (Object o : doc.selectNodes("//oaf:relation")) { for (Object o : doc.selectNodes("//oaf:relation")) {
Element element = (Element) o; Element element = (Element) o;
final Relation rel = new Relation(); final String target = StringUtils.trim(element.getText());
rel.setCollectedfrom(entity.getCollectedfrom()); final String relType = element.attributeValue("relType");
rel.setDataInfo(entity.getDataInfo()); final String subRelType = element.attributeValue("subRelType");
rel.setLastupdatetimestamp(entity.getLastupdatetimestamp()); final String relClass = element.attributeValue("relClass");
String relType = element.attributeValue("relType"); if (StringUtils.isNotBlank(target) && StringUtils.isNotBlank(relType) && StringUtils.isNotBlank(subRelType)
String subRelType = element.attributeValue("subRelType"); && StringUtils.isNotBlank(relClass)) {
String relClass = element.attributeValue("relClass");
String relClassInverse = ModelSupport final String relClassInverse = ModelSupport
.findInverse(ModelSupport.rel(relType, subRelType, relClass)) .findInverse(ModelSupport.rel(relType, subRelType, relClass))
.getInverseRelClass(); .getInverseRelClass();
rel.setSource(entity.getId());
String target = StringUtils.trim(element.getText());
final String validationdDate = ((Node) o).valueOf("@validationDate"); final String validationdDate = ((Node) o).valueOf("@validationDate");
if (StringUtils.isNotBlank(target)) { if (StringUtils.isNotBlank(target)) {
final String targetType = element.attributeValue("targetType");
// TODO discover the target entity type with a dedicated attribute, e.g. @targetType. if (StringUtils.isNotBlank(targetType)) {
final String[] parts = relType.split("(?=\\p{Upper})");
final String targetType = parts[1].toLowerCase();
final String targetId = createOpenaireId(targetType, target, true); final String targetId = createOpenaireId(targetType, target, true);
rels rels
.add( .add(
getRelation( getRelation(
@ -315,11 +308,12 @@ public abstract class AbstractMdRecordToOafMapper {
rels rels
.add( .add(
getRelation( getRelation(
targetId, entity.getId(), relType, subRelType, relClassInverse, entity, validationdDate)); targetId, entity.getId(), relType, subRelType, relClassInverse, entity,
validationdDate));
}
}
} }
} }
return rels; return rels;
} }

View File

@ -62,10 +62,12 @@
<oaf:refereed>0001</oaf:refereed> <oaf:refereed>0001</oaf:refereed>
<oaf:relation relClass="hasAuthorInstitution" <oaf:relation relClass="hasAuthorInstitution"
relType="resultOrganization" relType="resultOrganization"
subRelType="affiliation">ror_________::https://ror.org/02gdcn153</oaf:relation> subRelType="affiliation"
targetType="organization">ror_________::https://ror.org/02gdcn153</oaf:relation>
<oaf:relation relClass="isProducedBy" <oaf:relation relClass="isProducedBy"
relType="resultProject" relType="resultProject"
subRelType="outcome" subRelType="outcome"
targetType="project"
validationDate="2020-01-01">corda_______::226852</oaf:relation> validationDate="2020-01-01">corda_______::226852</oaf:relation>
</metadata> </metadata>
<about xmlns:oai="http://www.openarchives.org/OAI/2.0/"> <about xmlns:oai="http://www.openarchives.org/OAI/2.0/">