From ba380f5826dc24ec96f0de31d08dda9a9d9eb570 Mon Sep 17 00:00:00 2001 From: Sandro La Bruzzo Date: Tue, 9 May 2023 12:23:42 +0200 Subject: [PATCH] Makes the code compilable --- .../dhp/schema/oaf/common/ModelSupport.java | 11 ++++-- .../orcidnodoi/util/DumpToActionsUtility.java | 15 ++++---- .../dhp/oa/graph/clean/CleaningRuleMap.java | 8 ++--- .../graph/clean/GetDatasourceFromCountry.java | 2 +- .../raw/MigrateDbEntitiesApplication.java | 34 +++++++++---------- .../dhp/oa/graph/raw/OafToOafMapper.java | 2 +- .../dhp/oa/graph/raw/OdfToOafMapper.java | 9 ++--- .../dhp/oa/provision/model/RelatedEntity.java | 11 +++--- .../provision/model/SortableRelationKey.java | 7 ++-- .../oa/provision/utils/XmlRecordFactory.java | 10 +++--- 10 files changed, 58 insertions(+), 51 deletions(-) diff --git a/dhp-common/src/main/java/eu/dnetlib/dhp/schema/oaf/common/ModelSupport.java b/dhp-common/src/main/java/eu/dnetlib/dhp/schema/oaf/common/ModelSupport.java index 2ce34f147..6d51e44d2 100644 --- a/dhp-common/src/main/java/eu/dnetlib/dhp/schema/oaf/common/ModelSupport.java +++ b/dhp-common/src/main/java/eu/dnetlib/dhp/schema/oaf/common/ModelSupport.java @@ -92,6 +92,13 @@ public class ModelSupport { idPrefixEntity.put("50", "result"); } + public static String getEntityTypeFromId(final String id) { + //TODO We should create a class which define the identifier and parse it + if (StringUtils.isBlank(id)) + return null; + return idPrefixEntity.get(id.substring(0,2)); + } + /** * Helper method: combines the relation attributes * @param relType @@ -105,9 +112,7 @@ public class ModelSupport { /** * Helper method: deserialize the relation attributes serialized with rel - * @param relType - * @param subRelType - * @param relClass + * @param deserialization * @return */ public static RelationLabel unRel(String deserialization) { diff --git a/dhp-workflows/dhp-doiboost/src/main/java/eu/dnetlib/doiboost/orcidnodoi/util/DumpToActionsUtility.java b/dhp-workflows/dhp-doiboost/src/main/java/eu/dnetlib/doiboost/orcidnodoi/util/DumpToActionsUtility.java index c5a7a281b..938a935a4 100644 --- a/dhp-workflows/dhp-doiboost/src/main/java/eu/dnetlib/doiboost/orcidnodoi/util/DumpToActionsUtility.java +++ b/dhp-workflows/dhp-doiboost/src/main/java/eu/dnetlib/doiboost/orcidnodoi/util/DumpToActionsUtility.java @@ -4,6 +4,7 @@ package eu.dnetlib.doiboost.orcidnodoi.util; import java.text.SimpleDateFormat; import java.util.*; +import eu.dnetlib.dhp.schema.oaf.Result; import org.apache.commons.lang3.StringUtils; import com.google.gson.JsonArray; @@ -66,15 +67,16 @@ public class DumpToActionsUtility { return result.substring(0, result.length() - 2) + ":" + result.substring(result.length() - 2); } - public static String getDefaultResulttype(final String cobjcategory) { + //TODO CHECK IF WE CAN USE VOCABULARYGROUP + public static Result.RESULTTYPE getDefaultResulttype(final String cobjcategory) { switch (cobjcategory) { case "0029": - return "software"; + return Result.RESULTTYPE.software; case "0021": case "0024": case "0025": case "0030": - return "dataset"; + return Result.RESULTTYPE.dataset; case "0000": case "0010": case "0018": @@ -85,7 +87,7 @@ public class DumpToActionsUtility { case "0027": case "0028": case "0037": - return "other"; + return Result.RESULTTYPE.otherresearchproduct; case "0001": case "0002": case "0004": @@ -104,9 +106,10 @@ public class DumpToActionsUtility { case "0019": case "0031": case "0032": - return "publication"; + return Result.RESULTTYPE.publication; default: - return "publication"; + //TODO is it correct?? + return Result.RESULTTYPE.publication; } } diff --git a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/clean/CleaningRuleMap.java b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/clean/CleaningRuleMap.java index 6805a4772..2691fd535 100644 --- a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/clean/CleaningRuleMap.java +++ b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/clean/CleaningRuleMap.java @@ -64,12 +64,12 @@ public class CleaningRuleMap extends HashMap, SerializableConsumer) value -> OBJECT_MAPPER.readValue(value, Relation.class), Encoders.bean(Relation.class)) .filter( - (FilterFunction) rel -> rel.getRelClass().equalsIgnoreCase(Relation.RELCLASS.isProvidedBy)); + (FilterFunction) rel -> Relation.RELCLASS.isProvidedBy == rel.getRelClass()); organization .joinWith(relation, organization.col("id").equalTo(relation.col("target"))) 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 7de2b6e4c..717b4ce12 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 @@ -405,7 +405,7 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i final List provenance = getProvenance(collectedFrom, info); return Arrays.asList(OafMapperUtils .getRelation( - orgId, dsId, DATASOURCE_ORGANIZATION, PROVISION, PROVIDES, provenance)); + orgId, dsId, Relation.RELTYPE.datasourceOrganization, Relation.SUBRELTYPE.provision, Relation.RELCLASS.provides, provenance)); } catch (final Exception e) { throw new RuntimeException(e); } @@ -428,7 +428,7 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i return Arrays.asList( OafMapperUtils.getRelation( - orgId, projectId, PROJECT_ORGANIZATION, PARTICIPATION, IS_PARTICIPANT, provenance, properties)); + orgId, projectId, Relation.RELTYPE.projectOrganization, Relation.SUBRELTYPE.participation, Relation.RELCLASS.isParticipant, provenance, properties)); } catch (final Exception e) { throw new RuntimeException(e); @@ -444,16 +444,16 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i if (targetType.equals("dataset")) { r = new Dataset(); - r.setResulttype(DATASET_DEFAULT_RESULTTYPE.getClassid()); + r.setResulttype(Result.RESULTTYPE.dataset); } else if (targetType.equals("software")) { r = new Software(); - r.setResulttype(SOFTWARE_DEFAULT_RESULTTYPE.getClassid()); + r.setResulttype(Result.RESULTTYPE.software); } else if (targetType.equals("other")) { r = new OtherResearchProduct(); - r.setResulttype(ORP_DEFAULT_RESULTTYPE.getClassid()); + r.setResulttype(Result.RESULTTYPE.otherresearchproduct); } else { r = new Publication(); - r.setResulttype(PUBLICATION_DEFAULT_RESULTTYPE.getClassid()); + r.setResulttype(Result.RESULTTYPE.publication); } r.setId(createOpenaireId(50, rs.getString("target_id"), false)); r.setLastupdatetimestamp(lastUpdateTimestamp); @@ -473,8 +473,8 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i final String semantics = rs.getString("semantics"); switch (semantics) { - case "resultResult_relationship_isRelatedTo": - rel = setRelationSemantic(rel, RESULT_RESULT, RELATIONSHIP, IS_RELATED_TO); + case "resultResult_Relation.SUBRELTYPE.relationship_isRelatedTo": + rel = setRelationSemantic(rel, Relation.RELTYPE.resultResult, Relation.SUBRELTYPE.relationship, Relation.RELCLASS.IsRelatedTo); break; case "resultProject_outcome_produces": if (!"project".equals(sourceType)) { @@ -484,10 +484,10 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i "invalid claim, sourceId: %s, targetId: %s, semantics: %s", sourceId, targetId, semantics)); } - rel = setRelationSemantic(rel, RESULT_PROJECT, OUTCOME, PRODUCES); + rel = setRelationSemantic(rel, Relation.RELTYPE.resultProject, Relation.SUBRELTYPE.outcome, Relation.RELCLASS.produces); break; case "resultResult_publicationDataset_isRelatedTo": - rel = setRelationSemantic(rel, RESULT_RESULT, PUBLICATION_DATASET, IS_RELATED_TO); + rel = setRelationSemantic(rel, Relation.RELTYPE.resultResult, PUBLICATION_DATASET, IS_RELATED_TO); break; default: throw new IllegalArgumentException("claim semantics not managed: " + semantics); @@ -512,8 +512,8 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i return r; } - private Relation setRelationSemantic(final Relation r, final String relType, final String subRelType, - final String relClass) { + private Relation setRelationSemantic(final Relation r, final Relation.RELTYPE relType, final Relation.SUBRELTYPE subRelType, + final Relation.RELCLASS relClass) { r.setRelType(relType); r.setSubRelType(subRelType); r.setRelClass(relClass); @@ -641,7 +641,7 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i createOpenaireId(10, rs.getString("collectedfromid"), true), rs.getString("collectedfromname")); final List provenance = getProvenance(collectedFrom, info); - return Arrays.asList(getRelation(orgId1, orgId2, ORG_ORG_RELTYPE, DEDUP, MERGES, provenance)); + return Arrays.asList(getRelation(orgId1, orgId2, Relation.RELTYPE.organizationOrganization, Relation.SUBRELTYPE.dedup, Relation.RELCLASS.merges, provenance)); } catch (final Exception e) { throw new RuntimeException(e); } @@ -659,8 +659,8 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i final List provenance = getProvenance(collectedFrom, info); - final String relClass = rs.getString("type"); - return Arrays.asList(getRelation(orgId1, orgId2, ORG_ORG_RELTYPE, RELATIONSHIP, relClass, provenance)); + final Relation.RELCLASS relClass = Relation.RELCLASS.lookUp(rs.getString("type")); + return Arrays.asList(getRelation(orgId1, orgId2, Relation.RELTYPE.organizationOrganization, Relation.SUBRELTYPE.relationship, relClass, provenance)); } catch (final Exception e) { throw new RuntimeException(e); } @@ -672,14 +672,14 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i final String orgId1 = createOpenaireId(20, rs.getString("id1"), true); final String orgId2 = createOpenaireId(20, rs.getString("id2"), true); - final String relClass = rs.getString("relclass"); + final Relation.RELCLASS relClass = Relation.RELCLASS.lookUp(rs.getString("relclass")); final List collectedFrom = listKeyValues( createOpenaireId(10, rs.getString("collectedfromid"), true), rs.getString("collectedfromname")); final List provenance = getProvenance(collectedFrom, info); - return Arrays.asList(getRelation(orgId1, orgId2, ORG_ORG_RELTYPE, DEDUP, relClass, provenance)); + return Arrays.asList(getRelation(orgId1, orgId2, Relation.RELTYPE.organizationOrganization, Relation.SUBRELTYPE.dedup, relClass, provenance)); } catch (final Exception e) { throw new RuntimeException(e); } diff --git a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/OafToOafMapper.java b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/OafToOafMapper.java index a7f879c40..4335de609 100644 --- a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/OafToOafMapper.java +++ b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/OafToOafMapper.java @@ -276,7 +276,7 @@ public class OafToOafMapper extends AbstractMdRecordToOafMapper { res .add( getRelation( - docId, otherId, RESULT_RESULT, RELATIONSHIP, IS_RELATED_TO, entity)); + docId, otherId, Relation.RELTYPE.resultResult, Relation.SUBRELTYPE.relationship, Relation.RELCLASS.IsRelatedTo, entity)); } } return res; diff --git a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/OdfToOafMapper.java b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/OdfToOafMapper.java index 0195a76a2..4d2b2d242 100644 --- a/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/OdfToOafMapper.java +++ b/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/raw/OdfToOafMapper.java @@ -401,13 +401,14 @@ public class OdfToOafMapper extends AbstractMdRecordToOafMapper { protected List getRelations(final String reltype, final String entityId, final String otherId, final Entity entity) { final List res = new ArrayList<>(); - RelationLabel rel = ModelSupport.findRelation(reltype); - if (rel != null) { + Relation.RELCLASS rel = Relation.RELCLASS.lookUp(reltype); + Relation.SUBRELTYPE subrelType = rel.getSubRel(); + Relation.RELTYPE rt = subrelType.getRelType(ModelSupport.getEntityTypeFromId(entityId)); res .add( getRelation( - entityId, otherId, rel.getRelType(), rel.getSubReltype(), rel.getRelClass(), entity)); - } + entityId, otherId, rt, subrelType, rel, entity)); + return res; } diff --git a/dhp-workflows/dhp-graph-provision/src/main/java/eu/dnetlib/dhp/oa/provision/model/RelatedEntity.java b/dhp-workflows/dhp-graph-provision/src/main/java/eu/dnetlib/dhp/oa/provision/model/RelatedEntity.java index 1940da08c..e73b6da6d 100644 --- a/dhp-workflows/dhp-graph-provision/src/main/java/eu/dnetlib/dhp/oa/provision/model/RelatedEntity.java +++ b/dhp-workflows/dhp-graph-provision/src/main/java/eu/dnetlib/dhp/oa/provision/model/RelatedEntity.java @@ -6,10 +6,7 @@ import java.util.List; import com.google.common.base.Objects; -import eu.dnetlib.dhp.schema.oaf.Instance; -import eu.dnetlib.dhp.schema.oaf.KeyValue; -import eu.dnetlib.dhp.schema.oaf.Qualifier; -import eu.dnetlib.dhp.schema.oaf.StructuredProperty; +import eu.dnetlib.dhp.schema.oaf.*; public class RelatedEntity implements Serializable { @@ -25,7 +22,7 @@ public class RelatedEntity implements Serializable { private String publisher; private List pid; private String codeRepositoryUrl; - private String resulttype; + private Result.RESULTTYPE resulttype; private List collectedfrom; private List instances; @@ -111,11 +108,11 @@ public class RelatedEntity implements Serializable { this.codeRepositoryUrl = codeRepositoryUrl; } - public String getResulttype() { + public Result.RESULTTYPE getResulttype() { return resulttype; } - public void setResulttype(String resulttype) { + public void setResulttype(Result.RESULTTYPE resulttype) { this.resulttype = resulttype; } diff --git a/dhp-workflows/dhp-graph-provision/src/main/java/eu/dnetlib/dhp/oa/provision/model/SortableRelationKey.java b/dhp-workflows/dhp-graph-provision/src/main/java/eu/dnetlib/dhp/oa/provision/model/SortableRelationKey.java index 34fe2b9a4..ba74992c0 100644 --- a/dhp-workflows/dhp-graph-provision/src/main/java/eu/dnetlib/dhp/oa/provision/model/SortableRelationKey.java +++ b/dhp-workflows/dhp-graph-provision/src/main/java/eu/dnetlib/dhp/oa/provision/model/SortableRelationKey.java @@ -14,9 +14,10 @@ import eu.dnetlib.dhp.schema.oaf.Relation; public class SortableRelationKey implements Comparable, Serializable { - private static final Map weights = Maps.newHashMap(); + private static final Map weights = Maps.newHashMap(); static { + //TODO Claudio check why we need to have SUBRELTYPE AND RELTYPE weights.put(Relation.SUBRELTYPE.participation, 0); weights.put(Relation.SUBRELTYPE.outcome, 1); weights.put(Relation.SUBRELTYPE.affiliation, 2); @@ -25,9 +26,9 @@ public class SortableRelationKey implements Comparable, Ser weights.put(Relation.SUBRELTYPE.supplement, 5); weights.put(Relation.SUBRELTYPE.review, 6); weights.put(Relation.SUBRELTYPE.relationship, 7); - weights.put(ModelConstants.PART, 8); + weights.put(Relation.SUBRELTYPE.part, 8); weights.put(Relation.SUBRELTYPE.provision, 9); - weights.put(ModelConstants.VERSION, 10); + weights.put(Relation.SUBRELTYPE.version, 10); weights.put(Relation.SUBRELTYPE.similarity, 11); weights.put(Relation.SUBRELTYPE.citation, 12); } diff --git a/dhp-workflows/dhp-graph-provision/src/main/java/eu/dnetlib/dhp/oa/provision/utils/XmlRecordFactory.java b/dhp-workflows/dhp-graph-provision/src/main/java/eu/dnetlib/dhp/oa/provision/utils/XmlRecordFactory.java index e05a0102f..7d426f15b 100644 --- a/dhp-workflows/dhp-graph-provision/src/main/java/eu/dnetlib/dhp/oa/provision/utils/XmlRecordFactory.java +++ b/dhp-workflows/dhp-graph-provision/src/main/java/eu/dnetlib/dhp/oa/provision/utils/XmlRecordFactory.java @@ -222,7 +222,7 @@ public class XmlRecordFactory implements Serializable { .getFulltext() .stream() .filter(Objects::nonNull) - .map(c -> XmlSerializationUtils.asXmlElement("fulltext", c.getValue())) + .map(c -> XmlSerializationUtils.asXmlElement("fulltext", c)) .collect(Collectors.toList())); } @@ -421,7 +421,7 @@ public class XmlRecordFactory implements Serializable { .collect(Collectors.toList())); } if (r.getResulttype() != null) { - metadata.add(XmlSerializationUtils.asXmlElement("resulttype", r.getResulttype())); + metadata.add(XmlSerializationUtils.asXmlElement("resulttype", r.getResulttype().toString())); } if (r.getResourcetype() != null) { metadata.add(XmlSerializationUtils.mapQualifier("resourcetype", r.getResourcetype())); @@ -1132,7 +1132,7 @@ public class XmlRecordFactory implements Serializable { throw new IllegalArgumentException("invalid target type: " + targetType); } - final String accumulatorName = getRelDescriptor(rel.getRelType(), rel.getSubRelType(), rel.getRelClass()); + final String accumulatorName = getRelDescriptor(rel.getRelType().toString(), rel.getSubRelType().toString(), rel.getRelClass().toString()); if (accumulators.containsKey(accumulatorName)) { accumulators.get(accumulatorName).add(1); } @@ -1159,7 +1159,7 @@ public class XmlRecordFactory implements Serializable { final DataInfo dataInfo = Optional.ofNullable(rel.getProvenance()).map(p -> p.get(0).getDataInfo()).orElse(null); return templateFactory .getRel( - targetType, rel.getTarget(), fields, rel.getRelClass(), scheme, dataInfo, rel.getValidated(), + targetType, rel.getTarget(), fields, rel.getRelClass().toString(), scheme, dataInfo, rel.getValidated(), rel.getValidationDate()); } @@ -1459,7 +1459,7 @@ public class XmlRecordFactory implements Serializable { } private boolean isDuplicate(final RelatedEntityWrapper link) { - return Relation.SUBRELTYPE.dedup.equalsIgnoreCase(link.getRelation().getSubRelType()); + return Relation.SUBRELTYPE.dedup== link.getRelation().getSubRelType(); } private List listExtraInfo(final Entity entity) {