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"); 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 * Helper method: combines the relation attributes
* @param relType * @param relType
@ -105,9 +112,7 @@ public class ModelSupport {
/** /**
* Helper method: deserialize the relation attributes serialized with rel * Helper method: deserialize the relation attributes serialized with rel
* @param relType * @param deserialization
* @param subRelType
* @param relClass
* @return * @return
*/ */
public static RelationLabel unRel(String deserialization) { public static RelationLabel unRel(String deserialization) {

View File

@ -4,6 +4,7 @@ package eu.dnetlib.doiboost.orcidnodoi.util;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import eu.dnetlib.dhp.schema.oaf.Result;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
@ -66,15 +67,16 @@ public class DumpToActionsUtility {
return result.substring(0, result.length() - 2) + ":" + result.substring(result.length() - 2); 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) { switch (cobjcategory) {
case "0029": case "0029":
return "software"; return Result.RESULTTYPE.software;
case "0021": case "0021":
case "0024": case "0024":
case "0025": case "0025":
case "0030": case "0030":
return "dataset"; return Result.RESULTTYPE.dataset;
case "0000": case "0000":
case "0010": case "0010":
case "0018": case "0018":
@ -85,7 +87,7 @@ public class DumpToActionsUtility {
case "0027": case "0027":
case "0028": case "0028":
case "0037": case "0037":
return "other"; return Result.RESULTTYPE.otherresearchproduct;
case "0001": case "0001":
case "0002": case "0002":
case "0004": case "0004":
@ -104,9 +106,10 @@ public class DumpToActionsUtility {
case "0019": case "0019":
case "0031": case "0031":
case "0032": case "0032":
return "publication"; return Result.RESULTTYPE.publication;
default: 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) { private static void cleanRelation(VocabularyGroup vocabularies, Relation r) {
if (vocabularies.vocabularyExists(ModelConstants.DNET_RELATION_SUBRELTYPE)) { if (vocabularies.vocabularyExists(ModelConstants.DNET_RELATION_SUBRELTYPE)) {
Qualifier newValue = vocabularies.lookup(ModelConstants.DNET_RELATION_SUBRELTYPE, r.getSubRelType()); Qualifier newValue = vocabularies.lookup(ModelConstants.DNET_RELATION_SUBRELTYPE, r.getSubRelType().toString());
r.setSubRelType(newValue.getClassid()); r.setSubRelType(Relation.SUBRELTYPE.valueOf(newValue.getClassid()));
} }
if (vocabularies.vocabularyExists(ModelConstants.DNET_RELATION_RELCLASS)) { if (vocabularies.vocabularyExists(ModelConstants.DNET_RELATION_RELCLASS)) {
Qualifier newValue = vocabularies.lookup(ModelConstants.DNET_RELATION_RELCLASS, r.getRelClass()); Qualifier newValue = vocabularies.lookup(ModelConstants.DNET_RELATION_RELCLASS, r.getRelClass().toString());
r.setRelClass(newValue.getClassid()); 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), (MapFunction<String, Relation>) value -> OBJECT_MAPPER.readValue(value, Relation.class),
Encoders.bean(Relation.class)) Encoders.bean(Relation.class))
.filter( .filter(
(FilterFunction<Relation>) rel -> rel.getRelClass().equalsIgnoreCase(Relation.RELCLASS.isProvidedBy)); (FilterFunction<Relation>) rel -> Relation.RELCLASS.isProvidedBy == rel.getRelClass());
organization organization
.joinWith(relation, organization.col("id").equalTo(relation.col("target"))) .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); final List<Provenance> provenance = getProvenance(collectedFrom, info);
return Arrays.asList(OafMapperUtils return Arrays.asList(OafMapperUtils
.getRelation( .getRelation(
orgId, dsId, DATASOURCE_ORGANIZATION, PROVISION, PROVIDES, provenance)); orgId, dsId, Relation.RELTYPE.datasourceOrganization, Relation.SUBRELTYPE.provision, Relation.RELCLASS.provides, provenance));
} catch (final Exception e) { } catch (final Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -428,7 +428,7 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i
return Arrays.asList( return Arrays.asList(
OafMapperUtils.getRelation( 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) { } catch (final Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
@ -444,16 +444,16 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i
if (targetType.equals("dataset")) { if (targetType.equals("dataset")) {
r = new Dataset(); r = new Dataset();
r.setResulttype(DATASET_DEFAULT_RESULTTYPE.getClassid()); r.setResulttype(Result.RESULTTYPE.dataset);
} else if (targetType.equals("software")) { } else if (targetType.equals("software")) {
r = new Software(); r = new Software();
r.setResulttype(SOFTWARE_DEFAULT_RESULTTYPE.getClassid()); r.setResulttype(Result.RESULTTYPE.software);
} else if (targetType.equals("other")) { } else if (targetType.equals("other")) {
r = new OtherResearchProduct(); r = new OtherResearchProduct();
r.setResulttype(ORP_DEFAULT_RESULTTYPE.getClassid()); r.setResulttype(Result.RESULTTYPE.otherresearchproduct);
} else { } else {
r = new Publication(); r = new Publication();
r.setResulttype(PUBLICATION_DEFAULT_RESULTTYPE.getClassid()); r.setResulttype(Result.RESULTTYPE.publication);
} }
r.setId(createOpenaireId(50, rs.getString("target_id"), false)); r.setId(createOpenaireId(50, rs.getString("target_id"), false));
r.setLastupdatetimestamp(lastUpdateTimestamp); r.setLastupdatetimestamp(lastUpdateTimestamp);
@ -473,8 +473,8 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i
final String semantics = rs.getString("semantics"); final String semantics = rs.getString("semantics");
switch (semantics) { switch (semantics) {
case "resultResult_relationship_isRelatedTo": case "resultResult_Relation.SUBRELTYPE.relationship_isRelatedTo":
rel = setRelationSemantic(rel, RESULT_RESULT, RELATIONSHIP, IS_RELATED_TO); rel = setRelationSemantic(rel, Relation.RELTYPE.resultResult, Relation.SUBRELTYPE.relationship, Relation.RELCLASS.IsRelatedTo);
break; break;
case "resultProject_outcome_produces": case "resultProject_outcome_produces":
if (!"project".equals(sourceType)) { if (!"project".equals(sourceType)) {
@ -484,10 +484,10 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i
"invalid claim, sourceId: %s, targetId: %s, semantics: %s", sourceId, targetId, "invalid claim, sourceId: %s, targetId: %s, semantics: %s", sourceId, targetId,
semantics)); semantics));
} }
rel = setRelationSemantic(rel, RESULT_PROJECT, OUTCOME, PRODUCES); rel = setRelationSemantic(rel, Relation.RELTYPE.resultProject, Relation.SUBRELTYPE.outcome, Relation.RELCLASS.produces);
break; break;
case "resultResult_publicationDataset_isRelatedTo": 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; break;
default: default:
throw new IllegalArgumentException("claim semantics not managed: " + semantics); throw new IllegalArgumentException("claim semantics not managed: " + semantics);
@ -512,8 +512,8 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i
return r; return r;
} }
private Relation setRelationSemantic(final Relation r, final String relType, final String subRelType, private Relation setRelationSemantic(final Relation r, final Relation.RELTYPE relType, final Relation.SUBRELTYPE subRelType,
final String relClass) { final Relation.RELCLASS relClass) {
r.setRelType(relType); r.setRelType(relType);
r.setSubRelType(subRelType); r.setSubRelType(subRelType);
r.setRelClass(relClass); r.setRelClass(relClass);
@ -641,7 +641,7 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i
createOpenaireId(10, rs.getString("collectedfromid"), true), rs.getString("collectedfromname")); createOpenaireId(10, rs.getString("collectedfromid"), true), rs.getString("collectedfromname"));
final List<Provenance> provenance = getProvenance(collectedFrom, info); 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) { } catch (final Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -659,8 +659,8 @@ public class MigrateDbEntitiesApplication extends AbstractMigrationApplication i
final List<Provenance> provenance = getProvenance(collectedFrom, info); final List<Provenance> provenance = getProvenance(collectedFrom, info);
final String relClass = rs.getString("type"); final Relation.RELCLASS relClass = Relation.RELCLASS.lookUp(rs.getString("type"));
return Arrays.asList(getRelation(orgId1, orgId2, ORG_ORG_RELTYPE, RELATIONSHIP, relClass, provenance)); return Arrays.asList(getRelation(orgId1, orgId2, Relation.RELTYPE.organizationOrganization, Relation.SUBRELTYPE.relationship, relClass, provenance));
} catch (final Exception e) { } catch (final Exception e) {
throw new RuntimeException(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 orgId1 = createOpenaireId(20, rs.getString("id1"), true);
final String orgId2 = createOpenaireId(20, rs.getString("id2"), 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( final List<KeyValue> collectedFrom = listKeyValues(
createOpenaireId(10, rs.getString("collectedfromid"), true), rs.getString("collectedfromname")); createOpenaireId(10, rs.getString("collectedfromid"), true), rs.getString("collectedfromname"));
final List<Provenance> provenance = getProvenance(collectedFrom, info); 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) { } catch (final Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }

View File

@ -276,7 +276,7 @@ public class OafToOafMapper extends AbstractMdRecordToOafMapper {
res res
.add( .add(
getRelation( getRelation(
docId, otherId, RESULT_RESULT, RELATIONSHIP, IS_RELATED_TO, entity)); docId, otherId, Relation.RELTYPE.resultResult, Relation.SUBRELTYPE.relationship, Relation.RELCLASS.IsRelatedTo, entity));
} }
} }
return res; 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, protected List<Oaf> getRelations(final String reltype, final String entityId, final String otherId,
final Entity entity) { final Entity entity) {
final List<Oaf> res = new ArrayList<>(); final List<Oaf> res = new ArrayList<>();
RelationLabel rel = ModelSupport.findRelation(reltype); Relation.RELCLASS rel = Relation.RELCLASS.lookUp(reltype);
if (rel != null) { Relation.SUBRELTYPE subrelType = rel.getSubRel();
Relation.RELTYPE rt = subrelType.getRelType(ModelSupport.getEntityTypeFromId(entityId));
res res
.add( .add(
getRelation( getRelation(
entityId, otherId, rel.getRelType(), rel.getSubReltype(), rel.getRelClass(), entity)); entityId, otherId, rt, subrelType, rel, entity));
}
return res; return res;
} }

View File

@ -6,10 +6,7 @@ import java.util.List;
import com.google.common.base.Objects; import com.google.common.base.Objects;
import eu.dnetlib.dhp.schema.oaf.Instance; import eu.dnetlib.dhp.schema.oaf.*;
import eu.dnetlib.dhp.schema.oaf.KeyValue;
import eu.dnetlib.dhp.schema.oaf.Qualifier;
import eu.dnetlib.dhp.schema.oaf.StructuredProperty;
public class RelatedEntity implements Serializable { public class RelatedEntity implements Serializable {
@ -25,7 +22,7 @@ public class RelatedEntity implements Serializable {
private String publisher; private String publisher;
private List<StructuredProperty> pid; private List<StructuredProperty> pid;
private String codeRepositoryUrl; private String codeRepositoryUrl;
private String resulttype; private Result.RESULTTYPE resulttype;
private List<KeyValue> collectedfrom; private List<KeyValue> collectedfrom;
private List<Instance> instances; private List<Instance> instances;
@ -111,11 +108,11 @@ public class RelatedEntity implements Serializable {
this.codeRepositoryUrl = codeRepositoryUrl; this.codeRepositoryUrl = codeRepositoryUrl;
} }
public String getResulttype() { public Result.RESULTTYPE getResulttype() {
return resulttype; return resulttype;
} }
public void setResulttype(String resulttype) { public void setResulttype(Result.RESULTTYPE resulttype) {
this.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 { 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 { static {
//TODO Claudio check why we need to have SUBRELTYPE AND RELTYPE
weights.put(Relation.SUBRELTYPE.participation, 0); weights.put(Relation.SUBRELTYPE.participation, 0);
weights.put(Relation.SUBRELTYPE.outcome, 1); weights.put(Relation.SUBRELTYPE.outcome, 1);
weights.put(Relation.SUBRELTYPE.affiliation, 2); 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.supplement, 5);
weights.put(Relation.SUBRELTYPE.review, 6); weights.put(Relation.SUBRELTYPE.review, 6);
weights.put(Relation.SUBRELTYPE.relationship, 7); 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(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.similarity, 11);
weights.put(Relation.SUBRELTYPE.citation, 12); weights.put(Relation.SUBRELTYPE.citation, 12);
} }

View File

@ -222,7 +222,7 @@ public class XmlRecordFactory implements Serializable {
.getFulltext() .getFulltext()
.stream() .stream()
.filter(Objects::nonNull) .filter(Objects::nonNull)
.map(c -> XmlSerializationUtils.asXmlElement("fulltext", c.getValue())) .map(c -> XmlSerializationUtils.asXmlElement("fulltext", c))
.collect(Collectors.toList())); .collect(Collectors.toList()));
} }
@ -421,7 +421,7 @@ public class XmlRecordFactory implements Serializable {
.collect(Collectors.toList())); .collect(Collectors.toList()));
} }
if (r.getResulttype() != null) { if (r.getResulttype() != null) {
metadata.add(XmlSerializationUtils.asXmlElement("resulttype", r.getResulttype())); metadata.add(XmlSerializationUtils.asXmlElement("resulttype", r.getResulttype().toString()));
} }
if (r.getResourcetype() != null) { if (r.getResourcetype() != null) {
metadata.add(XmlSerializationUtils.mapQualifier("resourcetype", r.getResourcetype())); metadata.add(XmlSerializationUtils.mapQualifier("resourcetype", r.getResourcetype()));
@ -1132,7 +1132,7 @@ public class XmlRecordFactory implements Serializable {
throw new IllegalArgumentException("invalid target type: " + targetType); 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)) { if (accumulators.containsKey(accumulatorName)) {
accumulators.get(accumulatorName).add(1); 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); final DataInfo dataInfo = Optional.ofNullable(rel.getProvenance()).map(p -> p.get(0).getDataInfo()).orElse(null);
return templateFactory return templateFactory
.getRel( .getRel(
targetType, rel.getTarget(), fields, rel.getRelClass(), scheme, dataInfo, rel.getValidated(), targetType, rel.getTarget(), fields, rel.getRelClass().toString(), scheme, dataInfo, rel.getValidated(),
rel.getValidationDate()); rel.getValidationDate());
} }
@ -1459,7 +1459,7 @@ public class XmlRecordFactory implements Serializable {
} }
private boolean isDuplicate(final RelatedEntityWrapper link) { 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) { private List<String> listExtraInfo(final Entity entity) {