Makes the code compilable

This commit is contained in:
Sandro La Bruzzo 2023-05-09 12:23:42 +02:00
parent 88fffa6dbd
commit ba380f5826
10 changed files with 58 additions and 51 deletions

View File

@ -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) {

View File

@ -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;
}
}

View File

@ -64,12 +64,12 @@ public class CleaningRuleMap extends HashMap<Class<?>, SerializableConsumer<Obje
private static void cleanRelation(VocabularyGroup vocabularies, Relation r) {
if (vocabularies.vocabularyExists(ModelConstants.DNET_RELATION_SUBRELTYPE)) {
Qualifier newValue = vocabularies.lookup(ModelConstants.DNET_RELATION_SUBRELTYPE, r.getSubRelType());
r.setSubRelType(newValue.getClassid());
Qualifier newValue = vocabularies.lookup(ModelConstants.DNET_RELATION_SUBRELTYPE, r.getSubRelType().toString());
r.setSubRelType(Relation.SUBRELTYPE.valueOf(newValue.getClassid()));
}
if (vocabularies.vocabularyExists(ModelConstants.DNET_RELATION_RELCLASS)) {
Qualifier newValue = vocabularies.lookup(ModelConstants.DNET_RELATION_RELCLASS, r.getRelClass());
r.setRelClass(newValue.getClassid());
Qualifier newValue = vocabularies.lookup(ModelConstants.DNET_RELATION_RELCLASS, r.getRelClass().toString());
r.setRelClass(Relation.RELCLASS.valueOf(newValue.getClassid()));
}
}

View File

@ -89,7 +89,7 @@ public class GetDatasourceFromCountry implements Serializable {
(MapFunction<String, Relation>) value -> OBJECT_MAPPER.readValue(value, Relation.class),
Encoders.bean(Relation.class))
.filter(
(FilterFunction<Relation>) rel -> rel.getRelClass().equalsIgnoreCase(Relation.RELCLASS.isProvidedBy));
(FilterFunction<Relation>) rel -> Relation.RELCLASS.isProvidedBy == rel.getRelClass());
organization
.joinWith(relation, organization.col("id").equalTo(relation.col("target")))

View File

@ -405,7 +405,7 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i
final List<Provenance> 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> 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> 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<KeyValue> collectedFrom = listKeyValues(
createOpenaireId(10, rs.getString("collectedfromid"), true), rs.getString("collectedfromname"));
final List<Provenance> 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);
}

View File

@ -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;

View File

@ -401,13 +401,14 @@ public class OdfToOafMapper extends AbstractMdRecordToOafMapper {
protected List<Oaf> getRelations(final String reltype, final String entityId, final String otherId,
final Entity entity) {
final List<Oaf> 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;
}

View File

@ -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<StructuredProperty> pid;
private String codeRepositoryUrl;
private String resulttype;
private Result.RESULTTYPE resulttype;
private List<KeyValue> collectedfrom;
private List<Instance> 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;
}

View File

@ -14,9 +14,10 @@ import eu.dnetlib.dhp.schema.oaf.Relation;
public class SortableRelationKey implements Comparable<SortableRelationKey>, Serializable {
private static final Map<String, Integer> weights = Maps.newHashMap();
private static final Map<Relation.SUBRELTYPE, Integer> 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<SortableRelationKey>, 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);
}

View File

@ -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<String> listExtraInfo(final Entity entity) {