forked from antonis.lempesis/dnet-hadoop
changed to mirror the changes in the model (Instance, CommunityInstance, GraphResult)
This commit is contained in:
parent
387be43fd4
commit
f81ee22418
|
@ -5,6 +5,8 @@ import java.io.Serializable;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import eu.dnetlib.dhp.schema.dump.oaf.community.CommunityInstance;
|
||||||
|
import eu.dnetlib.dhp.schema.dump.oaf.graph.GraphResult;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import eu.dnetlib.dhp.schema.common.ModelConstants;
|
import eu.dnetlib.dhp.schema.common.ModelConstants;
|
||||||
|
@ -18,12 +20,12 @@ import eu.dnetlib.dhp.schema.oaf.StructuredProperty;
|
||||||
|
|
||||||
public class ResultMapper implements Serializable {
|
public class ResultMapper implements Serializable {
|
||||||
|
|
||||||
public static <I extends eu.dnetlib.dhp.schema.oaf.OafEntity> Result map(
|
public static <E extends eu.dnetlib.dhp.schema.oaf.OafEntity> Result map(
|
||||||
I in, Map<String, String> communityMap, boolean graph) {
|
E in, Map<String, String> communityMap, boolean graph) {
|
||||||
|
|
||||||
Result out;
|
Result out;
|
||||||
if (graph) {
|
if (graph) {
|
||||||
out = new Result();
|
out = new GraphResult();
|
||||||
} else {
|
} else {
|
||||||
out = new CommunityResult();
|
out = new CommunityResult();
|
||||||
}
|
}
|
||||||
|
@ -214,15 +216,18 @@ public class ResultMapper implements Serializable {
|
||||||
out.setId(input.getId());
|
out.setId(input.getId());
|
||||||
out.setOriginalId(input.getOriginalId());
|
out.setOriginalId(input.getOriginalId());
|
||||||
|
|
||||||
final List<Instance> instanceList = new ArrayList<>();
|
|
||||||
Optional
|
Optional<List<eu.dnetlib.dhp.schema.oaf.Instance>> oInst = Optional
|
||||||
.ofNullable(input.getInstance())
|
.ofNullable(input.getInstance());
|
||||||
.ifPresent(
|
|
||||||
inst -> inst
|
if(oInst.isPresent()){
|
||||||
.stream()
|
if (graph){
|
||||||
.forEach(i -> instanceList.add(getInstance(i, graph))));
|
((GraphResult)out).setInstance(oInst.get().stream().map(i -> getGraphInstance(i)).collect(Collectors.toList()));
|
||||||
out
|
}
|
||||||
.setInstance(instanceList);
|
else{
|
||||||
|
((CommunityResult)out).setInstance(oInst.get().stream().map(i -> getCommunityInstance(i)).collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Optional<eu.dnetlib.dhp.schema.oaf.Qualifier> oL = Optional.ofNullable(input.getLanguage());
|
Optional<eu.dnetlib.dhp.schema.oaf.Qualifier> oL = Optional.ofNullable(input.getLanguage());
|
||||||
if (oL.isPresent()) {
|
if (oL.isPresent()) {
|
||||||
|
@ -364,20 +369,37 @@ public class ResultMapper implements Serializable {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Instance getInstance(eu.dnetlib.dhp.schema.oaf.Instance i, boolean graph) {
|
private static Instance getGraphInstance (eu.dnetlib.dhp.schema.oaf.Instance i){
|
||||||
|
|
||||||
Instance instance = new Instance();
|
Instance instance = new Instance();
|
||||||
|
|
||||||
if(!graph){
|
setCommonValue(i, instance);
|
||||||
instance
|
|
||||||
.setCollectedfrom(
|
return instance;
|
||||||
KeyValue
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static CommunityInstance getCommunityInstance (eu.dnetlib.dhp.schema.oaf.Instance i){
|
||||||
|
CommunityInstance instance = new CommunityInstance();
|
||||||
|
|
||||||
|
setCommonValue(i, instance);
|
||||||
|
|
||||||
|
instance.setCollectedfrom(KeyValue
|
||||||
.newInstance(i.getCollectedfrom().getKey(), i.getCollectedfrom().getValue()));
|
.newInstance(i.getCollectedfrom().getKey(), i.getCollectedfrom().getValue()));
|
||||||
|
|
||||||
|
|
||||||
instance
|
instance
|
||||||
.setHostedby(
|
.setHostedby(
|
||||||
KeyValue.newInstance(i.getHostedby().getKey(), i.getHostedby().getValue()));
|
KeyValue.newInstance(i.getHostedby().getKey(), i.getHostedby().getValue()));
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static <I extends Instance> void setCommonValue(eu.dnetlib.dhp.schema.oaf.Instance i, I instance) {// <I extends Instance> I
|
||||||
|
// getInstance(eu.dnetlib.dhp.schema.oaf.Instance
|
||||||
|
// i, boolean graph) {
|
||||||
Optional<eu.dnetlib.dhp.schema.oaf.Qualifier> opAr = Optional
|
Optional<eu.dnetlib.dhp.schema.oaf.Qualifier> opAr = Optional
|
||||||
.ofNullable(i.getAccessright());
|
.ofNullable(i.getAccessright());
|
||||||
if (opAr.isPresent()) {
|
if (opAr.isPresent()) {
|
||||||
|
@ -393,7 +415,6 @@ public class ResultMapper implements Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Optional
|
Optional
|
||||||
.ofNullable(i.getLicense())
|
.ofNullable(i.getLicense())
|
||||||
.ifPresent(value -> instance.setLicense(value.getValue()));
|
.ifPresent(value -> instance.setLicense(value.getValue()));
|
||||||
|
@ -409,7 +430,8 @@ public class ResultMapper implements Serializable {
|
||||||
.ifPresent(value -> instance.setType(value.getClassname()));
|
.ifPresent(value -> instance.setType(value.getClassname()));
|
||||||
Optional.ofNullable(i.getUrl()).ifPresent(value -> instance.setUrl(value));
|
Optional.ofNullable(i.getUrl()).ifPresent(value -> instance.setUrl(value));
|
||||||
|
|
||||||
return instance;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<Provenance> getUniqueProvenance(List<Provenance> provenance) {
|
private static List<Provenance> getUniqueProvenance(List<Provenance> provenance) {
|
||||||
|
|
Loading…
Reference in New Issue