dnet-hadoop/dhp-workflows/dhp-graph-mapper/src/main/java/eu/dnetlib/dhp/oa/graph/dump/complete/Process.java

101 lines
2.9 KiB
Java
Raw Normal View History

2020-07-29 17:42:50 +02:00
package eu.dnetlib.dhp.oa.graph.dump.complete;
2020-07-29 17:42:50 +02:00
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
2020-09-14 14:33:10 +02:00
import org.apache.commons.lang3.StringUtils;
2020-07-30 16:40:15 +02:00
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import eu.dnetlib.dhp.oa.graph.dump.Constants;
import eu.dnetlib.dhp.oa.graph.dump.Utils;
import eu.dnetlib.dhp.schema.common.ModelConstants;
import eu.dnetlib.dhp.schema.common.ModelSupport;
import eu.dnetlib.dhp.schema.dump.oaf.Provenance;
import eu.dnetlib.dhp.schema.dump.oaf.graph.*;
/**
2020-08-19 10:57:36 +02:00
* It process the ContextInfo information to produce a new Context Entity or a set of Relations between the generic
* context entity and datasource/projects related to the context.
*/
public class Process implements Serializable {
2020-07-30 16:40:15 +02:00
private static final Logger log = LoggerFactory.getLogger(Process.class);
2020-07-29 17:42:50 +02:00
public static <R extends ResearchInitiative> R getEntity(ContextInfo ci) {
try {
ResearchInitiative ri;
if (ci.getType().equals("community")) {
ri = new ResearchCommunity();
((ResearchCommunity) ri).setSubject(ci.getSubject());
ri.setType(Constants.RESEARCH_COMMUNITY);
} else {
ri = new ResearchInitiative();
ri.setType(Constants.RESEARCH_INFRASTRUCTURE);
}
ri.setId(Utils.getContextId(ci.getId()));
ri.setOriginalId(ci.getId());
2020-07-29 17:42:50 +02:00
ri.setDescription(ci.getDescription());
ri.setName(ci.getName());
2020-09-14 14:33:10 +02:00
if (StringUtils.isNotEmpty(ci.getZenodocommunity())) {
ri.setZenodo_community(Constants.ZENODO_COMMUNITY_PREFIX + ci.getZenodocommunity());
}
2020-07-29 17:42:50 +02:00
return (R) ri;
2020-07-29 17:42:50 +02:00
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
2020-07-29 17:42:50 +02:00
public static List<Relation> getRelation(ContextInfo ci) {
try {
2020-07-29 17:42:50 +02:00
List<Relation> relationList = new ArrayList<>();
ci
.getDatasourceList()
.forEach(ds -> {
2020-07-30 16:40:15 +02:00
2020-07-29 17:42:50 +02:00
String nodeType = ModelSupport.idPrefixEntity.get(ds.substring(0, 2));
2020-07-30 16:40:15 +02:00
2020-07-30 16:41:31 +02:00
String contextId = Utils.getContextId(ci.getId());
2020-08-03 18:06:18 +02:00
relationList
.add(
Relation
.newInstance(
Node
.newInstance(
contextId, eu.dnetlib.dhp.schema.dump.oaf.graph.Constants.CONTEXT_ENTITY),
Node.newInstance(ds, nodeType),
RelType.newInstance(ModelConstants.IS_RELATED_TO, ModelConstants.RELATIONSHIP),
Provenance
.newInstance(
2020-08-07 17:43:20 +02:00
Constants.USER_CLAIM,
Constants.DEFAULT_TRUST)));
2020-08-03 18:06:18 +02:00
relationList
.add(
Relation
.newInstance(
Node.newInstance(ds, nodeType),
Node
.newInstance(
contextId, eu.dnetlib.dhp.schema.dump.oaf.graph.Constants.CONTEXT_ENTITY),
RelType.newInstance(ModelConstants.IS_RELATED_TO, ModelConstants.RELATIONSHIP),
Provenance
.newInstance(
2020-08-07 17:43:20 +02:00
Constants.USER_CLAIM,
Constants.DEFAULT_TRUST)));
2020-07-29 17:42:50 +02:00
});
2020-07-29 17:42:50 +02:00
return relationList;
2020-07-29 17:42:50 +02:00
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
}