This commit is contained in:
Miriam Baglioni 2020-08-24 17:00:20 +02:00
parent 5fb2949cb8
commit 34fa96f3b1
1 changed files with 25 additions and 24 deletions

View File

@ -5,14 +5,14 @@ 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;
import eu.dnetlib.dhp.schema.dump.oaf.*; import eu.dnetlib.dhp.schema.dump.oaf.*;
import eu.dnetlib.dhp.schema.dump.oaf.community.CommunityInstance;
import eu.dnetlib.dhp.schema.dump.oaf.community.CommunityResult; import eu.dnetlib.dhp.schema.dump.oaf.community.CommunityResult;
import eu.dnetlib.dhp.schema.dump.oaf.community.Context; import eu.dnetlib.dhp.schema.dump.oaf.community.Context;
import eu.dnetlib.dhp.schema.dump.oaf.graph.GraphResult;
import eu.dnetlib.dhp.schema.oaf.DataInfo; import eu.dnetlib.dhp.schema.oaf.DataInfo;
import eu.dnetlib.dhp.schema.oaf.Field; import eu.dnetlib.dhp.schema.oaf.Field;
import eu.dnetlib.dhp.schema.oaf.Journal; import eu.dnetlib.dhp.schema.oaf.Journal;
@ -216,16 +216,17 @@ public class ResultMapper implements Serializable {
out.setId(input.getId()); out.setId(input.getId());
out.setOriginalId(input.getOriginalId()); out.setOriginalId(input.getOriginalId());
Optional<List<eu.dnetlib.dhp.schema.oaf.Instance>> oInst = Optional Optional<List<eu.dnetlib.dhp.schema.oaf.Instance>> oInst = Optional
.ofNullable(input.getInstance()); .ofNullable(input.getInstance());
if(oInst.isPresent()){ if (oInst.isPresent()) {
if (graph){ if (graph) {
((GraphResult)out).setInstance(oInst.get().stream().map(i -> getGraphInstance(i)).collect(Collectors.toList())); ((GraphResult) out)
} .setInstance(oInst.get().stream().map(i -> getGraphInstance(i)).collect(Collectors.toList()));
else{ } else {
((CommunityResult)out).setInstance(oInst.get().stream().map(i -> getCommunityInstance(i)).collect(Collectors.toList())); ((CommunityResult) out)
.setInstance(
oInst.get().stream().map(i -> getCommunityInstance(i)).collect(Collectors.toList()));
} }
} }
@ -369,7 +370,7 @@ public class ResultMapper implements Serializable {
} }
private static Instance getGraphInstance (eu.dnetlib.dhp.schema.oaf.Instance i){ private static Instance getGraphInstance(eu.dnetlib.dhp.schema.oaf.Instance i) {
Instance instance = new Instance(); Instance instance = new Instance();
setCommonValue(i, instance); setCommonValue(i, instance);
@ -378,28 +379,30 @@ public class ResultMapper implements Serializable {
} }
private static CommunityInstance getCommunityInstance(eu.dnetlib.dhp.schema.oaf.Instance i) {
private static CommunityInstance getCommunityInstance (eu.dnetlib.dhp.schema.oaf.Instance i){
CommunityInstance instance = new CommunityInstance(); CommunityInstance instance = new CommunityInstance();
setCommonValue(i, instance); setCommonValue(i, instance);
instance.setCollectedfrom(KeyValue instance
.newInstance(i.getCollectedfrom().getKey(), i.getCollectedfrom().getValue())); .setCollectedfrom(
KeyValue
.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; return instance;
} }
private static <I extends Instance> void setCommonValue(eu.dnetlib.dhp.schema.oaf.Instance i, I instance) {// <I
private static <I extends Instance> void setCommonValue(eu.dnetlib.dhp.schema.oaf.Instance i, I instance) {// <I extends Instance> I // extends
// getInstance(eu.dnetlib.dhp.schema.oaf.Instance // Instance>
// i, boolean graph) { // 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()) {
@ -430,8 +433,6 @@ 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));
} }
private static List<Provenance> getUniqueProvenance(List<Provenance> provenance) { private static List<Provenance> getUniqueProvenance(List<Provenance> provenance) {