mapping relationship from trasformed records based on oaf:relation #219

Merged
claudio.atzori merged 3 commits from oaf_relation_mapping into beta 2022-06-16 09:27:19 +02:00
2 changed files with 28 additions and 32 deletions
Showing only changes of commit 4c8e820ff0 - Show all commits

View File

@ -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");
Review

you here assume the attribute targetType will be in the result once this method will run. Is it correct?

you here assume the attribute targetType will be in the result once this method will run. Is it correct?
Review

We assume the presence of the targetType attribute is part of the oaf:relation specification, just like the other attributes. I suppose it is reasonable to assume to know, when defining the transformation rules, the main entity type at which a relationsh will refer to.

We assume the presence of the `targetType` attribute is part of the `oaf:relation` specification, just like the other attributes. I suppose it is reasonable to assume to know, when defining the transformation rules, the main entity type at which a relationsh will refer to.
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;
}

View File

@ -62,10 +62,12 @@
<oaf:refereed>0001</oaf:refereed>
<oaf:relation relClass="hasAuthorInstitution"
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"
relType="resultProject"
subRelType="outcome"
targetType="project"
validationDate="2020-01-01">corda_______::226852</oaf:relation>
</metadata>
<about xmlns:oai="http://www.openarchives.org/OAI/2.0/">