2020-06-15 11:12:14 +02:00
|
|
|
|
2020-06-09 15:37:46 +02:00
|
|
|
package eu.dnetlib.dhp.oa.graph.dump;
|
|
|
|
|
2020-06-15 11:12:14 +02:00
|
|
|
import java.io.Serializable;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
2021-08-06 18:56:18 +02:00
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
2021-10-04 18:40:07 +02:00
|
|
|
import eu.dnetlib.dhp.oa.graph.dump.exceptions.NoAvailableEntityTypeException;
|
2021-08-06 18:56:18 +02:00
|
|
|
import eu.dnetlib.dhp.schema.common.ModelConstants;
|
|
|
|
import eu.dnetlib.dhp.schema.dump.oaf.*;
|
2021-08-05 15:20:50 +02:00
|
|
|
import eu.dnetlib.dhp.schema.dump.oaf.AccessRight;
|
|
|
|
import eu.dnetlib.dhp.schema.dump.oaf.Author;
|
|
|
|
import eu.dnetlib.dhp.schema.dump.oaf.GeoLocation;
|
|
|
|
import eu.dnetlib.dhp.schema.dump.oaf.Instance;
|
2021-11-19 11:25:50 +01:00
|
|
|
import eu.dnetlib.dhp.schema.dump.oaf.Measure;
|
2021-08-05 15:20:50 +02:00
|
|
|
import eu.dnetlib.dhp.schema.dump.oaf.OpenAccessRoute;
|
|
|
|
import eu.dnetlib.dhp.schema.dump.oaf.Result;
|
2021-11-19 15:56:25 +01:00
|
|
|
import eu.dnetlib.dhp.schema.dump.oaf.community.CfHbKeyValue;
|
2020-08-24 17:00:20 +02:00
|
|
|
import eu.dnetlib.dhp.schema.dump.oaf.community.CommunityInstance;
|
2020-07-24 17:28:11 +02:00
|
|
|
import eu.dnetlib.dhp.schema.dump.oaf.community.CommunityResult;
|
2020-08-13 12:14:37 +02:00
|
|
|
import eu.dnetlib.dhp.schema.dump.oaf.community.Context;
|
2020-08-24 17:00:20 +02:00
|
|
|
import eu.dnetlib.dhp.schema.dump.oaf.graph.GraphResult;
|
2021-08-06 18:56:18 +02:00
|
|
|
import eu.dnetlib.dhp.schema.oaf.*;
|
2020-06-09 15:39:03 +02:00
|
|
|
|
2020-07-20 17:54:28 +02:00
|
|
|
public class ResultMapper implements Serializable {
|
2020-06-09 15:39:03 +02:00
|
|
|
|
2020-08-19 11:28:26 +02:00
|
|
|
public static <E extends eu.dnetlib.dhp.schema.oaf.OafEntity> Result map(
|
2021-10-04 18:40:07 +02:00
|
|
|
E in, Map<String, String> communityMap, String dumpType) throws NoAvailableEntityTypeException {
|
2020-06-15 11:12:14 +02:00
|
|
|
|
2020-07-24 17:28:11 +02:00
|
|
|
Result out;
|
2020-11-24 14:37:36 +01:00
|
|
|
if (Constants.DUMPTYPE.COMPLETE.getType().equals(dumpType)) {
|
2020-08-19 11:28:26 +02:00
|
|
|
out = new GraphResult();
|
2020-07-24 17:28:11 +02:00
|
|
|
} else {
|
|
|
|
out = new CommunityResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
eu.dnetlib.dhp.schema.oaf.Result input = (eu.dnetlib.dhp.schema.oaf.Result) in;
|
2020-06-15 11:12:14 +02:00
|
|
|
Optional<eu.dnetlib.dhp.schema.oaf.Qualifier> ort = Optional.ofNullable(input.getResulttype());
|
|
|
|
if (ort.isPresent()) {
|
2021-10-13 11:28:28 +02:00
|
|
|
try {
|
|
|
|
|
|
|
|
addTypeSpecificInformation(out, input, ort);
|
2020-06-15 11:12:14 +02:00
|
|
|
|
2021-10-13 11:28:28 +02:00
|
|
|
Optional
|
|
|
|
.ofNullable(input.getAuthor())
|
|
|
|
.ifPresent(
|
|
|
|
ats -> out.setAuthor(ats.stream().map(ResultMapper::getAuthor).collect(Collectors.toList())));
|
2020-06-18 11:22:58 +02:00
|
|
|
|
2021-10-13 11:28:28 +02:00
|
|
|
// I do not map Access Right UNKNOWN or OTHER
|
2020-06-18 11:22:58 +02:00
|
|
|
|
2021-10-13 11:28:28 +02:00
|
|
|
Optional<eu.dnetlib.dhp.schema.oaf.Qualifier> oar = Optional.ofNullable(input.getBestaccessright());
|
|
|
|
if (oar.isPresent() && Constants.accessRightsCoarMap.containsKey(oar.get().getClassid())) {
|
|
|
|
String code = Constants.accessRightsCoarMap.get(oar.get().getClassid());
|
|
|
|
out
|
|
|
|
.setBestaccessright(
|
2021-11-11 08:59:20 +01:00
|
|
|
|
|
|
|
BestAccessRight
|
2021-10-13 11:28:28 +02:00
|
|
|
.newInstance(
|
|
|
|
code,
|
|
|
|
Constants.coarCodeLabelMap.get(code),
|
|
|
|
Constants.COAR_ACCESS_RIGHT_SCHEMA));
|
|
|
|
}
|
2021-08-05 15:20:50 +02:00
|
|
|
|
2021-10-13 11:28:28 +02:00
|
|
|
final List<String> contributorList = new ArrayList<>();
|
|
|
|
Optional
|
|
|
|
.ofNullable(input.getContributor())
|
|
|
|
.ifPresent(value -> value.stream().forEach(c -> contributorList.add(c.getValue())));
|
|
|
|
out.setContributor(contributorList);
|
|
|
|
|
|
|
|
Optional
|
|
|
|
.ofNullable(input.getCountry())
|
|
|
|
.ifPresent(
|
|
|
|
value -> out
|
|
|
|
.setCountry(
|
|
|
|
value
|
|
|
|
.stream()
|
|
|
|
.map(
|
|
|
|
c -> {
|
|
|
|
if (c.getClassid().equals((ModelConstants.UNKNOWN))) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-11-19 11:25:50 +01:00
|
|
|
ResultCountry country = new ResultCountry();
|
2021-10-13 11:28:28 +02:00
|
|
|
country.setCode(c.getClassid());
|
|
|
|
country.setLabel(c.getClassname());
|
|
|
|
Optional
|
|
|
|
.ofNullable(c.getDataInfo())
|
|
|
|
.ifPresent(
|
|
|
|
provenance -> country
|
|
|
|
.setProvenance(
|
|
|
|
Provenance
|
|
|
|
.newInstance(
|
|
|
|
provenance
|
|
|
|
.getProvenanceaction()
|
|
|
|
.getClassname(),
|
|
|
|
c.getDataInfo().getTrust())));
|
|
|
|
return country;
|
|
|
|
})
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
.collect(Collectors.toList())));
|
|
|
|
|
|
|
|
final List<String> coverageList = new ArrayList<>();
|
|
|
|
Optional
|
|
|
|
.ofNullable(input.getCoverage())
|
|
|
|
.ifPresent(value -> value.stream().forEach(c -> coverageList.add(c.getValue())));
|
|
|
|
out.setCoverage(coverageList);
|
|
|
|
|
|
|
|
out.setDateofcollection(input.getDateofcollection());
|
|
|
|
|
|
|
|
final List<String> descriptionList = new ArrayList<>();
|
|
|
|
Optional
|
|
|
|
.ofNullable(input.getDescription())
|
|
|
|
.ifPresent(value -> value.forEach(d -> descriptionList.add(d.getValue())));
|
|
|
|
out.setDescription(descriptionList);
|
|
|
|
Optional<Field<String>> oStr = Optional.ofNullable(input.getEmbargoenddate());
|
|
|
|
if (oStr.isPresent()) {
|
|
|
|
out.setEmbargoenddate(oStr.get().getValue());
|
|
|
|
}
|
2020-06-15 11:12:14 +02:00
|
|
|
|
2021-10-13 11:28:28 +02:00
|
|
|
final List<String> formatList = new ArrayList<>();
|
|
|
|
Optional
|
|
|
|
.ofNullable(input.getFormat())
|
|
|
|
.ifPresent(value -> value.stream().forEach(f -> formatList.add(f.getValue())));
|
|
|
|
out.setFormat(formatList);
|
|
|
|
out.setId(input.getId());
|
2021-11-08 10:25:28 +01:00
|
|
|
out.setOriginalId(new ArrayList<>());
|
|
|
|
Optional
|
|
|
|
.ofNullable(input.getOriginalId())
|
|
|
|
.ifPresent(
|
|
|
|
v -> out
|
|
|
|
.setOriginalId(
|
|
|
|
input
|
|
|
|
.getOriginalId()
|
|
|
|
.stream()
|
|
|
|
.filter(s -> !s.startsWith("50|"))
|
|
|
|
.collect(Collectors.toList())));
|
2021-10-13 11:28:28 +02:00
|
|
|
|
|
|
|
Optional<List<eu.dnetlib.dhp.schema.oaf.Instance>> oInst = Optional
|
|
|
|
.ofNullable(input.getInstance());
|
|
|
|
|
|
|
|
if (oInst.isPresent()) {
|
|
|
|
if (Constants.DUMPTYPE.COMPLETE.getType().equals(dumpType)) {
|
|
|
|
((GraphResult) out)
|
|
|
|
.setInstance(
|
|
|
|
oInst.get().stream().map(ResultMapper::getGraphInstance).collect(Collectors.toList()));
|
|
|
|
} else {
|
|
|
|
((CommunityResult) out)
|
|
|
|
.setInstance(
|
|
|
|
oInst
|
|
|
|
.get()
|
|
|
|
.stream()
|
|
|
|
.map(ResultMapper::getCommunityInstance)
|
|
|
|
.collect(Collectors.toList()));
|
|
|
|
}
|
|
|
|
}
|
2020-06-15 11:12:14 +02:00
|
|
|
|
2021-10-13 11:28:28 +02:00
|
|
|
Optional<eu.dnetlib.dhp.schema.oaf.Qualifier> oL = Optional.ofNullable(input.getLanguage());
|
|
|
|
if (oL.isPresent()) {
|
|
|
|
eu.dnetlib.dhp.schema.oaf.Qualifier language = oL.get();
|
2021-11-19 11:25:50 +01:00
|
|
|
out.setLanguage(Language.newInstance(language.getClassid(), language.getClassname()));
|
2021-10-13 11:28:28 +02:00
|
|
|
}
|
|
|
|
Optional<Long> oLong = Optional.ofNullable(input.getLastupdatetimestamp());
|
|
|
|
if (oLong.isPresent()) {
|
|
|
|
out.setLastupdatetimestamp(oLong.get());
|
|
|
|
}
|
|
|
|
Optional<List<StructuredProperty>> otitle = Optional.ofNullable(input.getTitle());
|
|
|
|
if (otitle.isPresent()) {
|
|
|
|
List<StructuredProperty> iTitle = otitle
|
|
|
|
.get()
|
|
|
|
.stream()
|
|
|
|
.filter(t -> t.getQualifier().getClassid().equalsIgnoreCase("main title"))
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
if (!iTitle.isEmpty()) {
|
|
|
|
out.setMaintitle(iTitle.get(0).getValue());
|
|
|
|
}
|
2020-06-15 11:12:14 +02:00
|
|
|
|
2021-10-13 11:28:28 +02:00
|
|
|
iTitle = otitle
|
|
|
|
.get()
|
|
|
|
.stream()
|
|
|
|
.filter(t -> t.getQualifier().getClassid().equalsIgnoreCase("subtitle"))
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
if (!iTitle.isEmpty()) {
|
|
|
|
out.setSubtitle(iTitle.get(0).getValue());
|
|
|
|
}
|
2020-06-15 11:12:14 +02:00
|
|
|
|
2020-08-19 11:28:26 +02:00
|
|
|
}
|
2020-06-15 11:12:14 +02:00
|
|
|
|
2021-10-13 11:28:28 +02:00
|
|
|
Optional
|
|
|
|
.ofNullable(input.getPid())
|
|
|
|
.ifPresent(
|
|
|
|
value -> out
|
|
|
|
.setPid(
|
|
|
|
value
|
|
|
|
.stream()
|
|
|
|
.map(
|
2021-11-19 11:25:50 +01:00
|
|
|
p -> ResultPid
|
2021-10-13 11:28:28 +02:00
|
|
|
.newInstance(p.getQualifier().getClassid(), p.getValue()))
|
|
|
|
.collect(Collectors.toList())));
|
|
|
|
|
|
|
|
oStr = Optional.ofNullable(input.getDateofacceptance());
|
|
|
|
if (oStr.isPresent()) {
|
|
|
|
out.setPublicationdate(oStr.get().getValue());
|
2020-06-15 11:12:14 +02:00
|
|
|
}
|
2021-10-13 11:28:28 +02:00
|
|
|
oStr = Optional.ofNullable(input.getPublisher());
|
|
|
|
if (oStr.isPresent()) {
|
|
|
|
out.setPublisher(oStr.get().getValue());
|
2020-06-15 11:12:14 +02:00
|
|
|
}
|
|
|
|
|
2021-10-13 11:28:28 +02:00
|
|
|
Optional
|
|
|
|
.ofNullable(input.getSource())
|
|
|
|
.ifPresent(
|
|
|
|
value -> out.setSource(value.stream().map(Field::getValue).collect(Collectors.toList())));
|
2020-06-15 11:12:14 +02:00
|
|
|
|
2021-10-13 11:28:28 +02:00
|
|
|
List<Subject> subjectList = new ArrayList<>();
|
|
|
|
Optional
|
|
|
|
.ofNullable(input.getSubject())
|
|
|
|
.ifPresent(
|
|
|
|
value -> value
|
|
|
|
.forEach(s -> subjectList.add(getSubject(s))));
|
2021-10-04 18:40:07 +02:00
|
|
|
|
2021-10-13 11:28:28 +02:00
|
|
|
out.setSubjects(subjectList);
|
2020-07-20 17:46:27 +02:00
|
|
|
|
2021-10-13 11:28:28 +02:00
|
|
|
out.setType(input.getResulttype().getClassid());
|
2020-06-15 11:12:14 +02:00
|
|
|
|
2021-10-13 11:28:28 +02:00
|
|
|
if (!Constants.DUMPTYPE.COMPLETE.getType().equals(dumpType)) {
|
|
|
|
((CommunityResult) out)
|
|
|
|
.setCollectedfrom(
|
|
|
|
input
|
|
|
|
.getCollectedfrom()
|
|
|
|
.stream()
|
2021-11-19 15:56:25 +01:00
|
|
|
.map(cf -> CfHbKeyValue.newInstance(cf.getKey(), cf.getValue()))
|
2021-10-13 11:28:28 +02:00
|
|
|
.collect(Collectors.toList()));
|
|
|
|
|
|
|
|
Set<String> communities = communityMap.keySet();
|
|
|
|
List<Context> contextList = Optional
|
|
|
|
.ofNullable(
|
|
|
|
input
|
|
|
|
.getContext())
|
|
|
|
.map(
|
|
|
|
value -> value
|
|
|
|
.stream()
|
|
|
|
.map(c -> {
|
|
|
|
String communityId = c.getId();
|
|
|
|
if (communityId.contains("::")) {
|
|
|
|
communityId = communityId.substring(0, communityId.indexOf("::"));
|
|
|
|
}
|
|
|
|
if (communities.contains(communityId)) {
|
|
|
|
Context context = new Context();
|
|
|
|
context.setCode(communityId);
|
|
|
|
context.setLabel(communityMap.get(communityId));
|
|
|
|
Optional<List<DataInfo>> dataInfo = Optional.ofNullable(c.getDataInfo());
|
|
|
|
if (dataInfo.isPresent()) {
|
|
|
|
List<Provenance> provenance = new ArrayList<>();
|
|
|
|
provenance
|
|
|
|
.addAll(
|
|
|
|
dataInfo
|
|
|
|
.get()
|
|
|
|
.stream()
|
2020-07-24 17:28:11 +02:00
|
|
|
.map(
|
2021-10-13 11:28:28 +02:00
|
|
|
di -> Optional
|
|
|
|
.ofNullable(di.getProvenanceaction())
|
|
|
|
.map(
|
|
|
|
provenanceaction -> Provenance
|
|
|
|
.newInstance(
|
|
|
|
provenanceaction.getClassname(),
|
|
|
|
di.getTrust()))
|
|
|
|
.orElse(null))
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
.collect(Collectors.toSet()));
|
|
|
|
|
|
|
|
try {
|
|
|
|
context.setProvenance(getUniqueProvenance(provenance));
|
|
|
|
} catch (NoAvailableEntityTypeException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return context;
|
2021-10-04 18:40:07 +02:00
|
|
|
}
|
2021-10-13 11:28:28 +02:00
|
|
|
return null;
|
|
|
|
})
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
.collect(Collectors.toList()))
|
|
|
|
.orElse(new ArrayList<>());
|
|
|
|
|
|
|
|
if (!contextList.isEmpty()) {
|
|
|
|
Set<Integer> hashValue = new HashSet<>();
|
|
|
|
List<Context> remainigContext = new ArrayList<>();
|
|
|
|
contextList.forEach(c -> {
|
|
|
|
if (!hashValue.contains(c.hashCode())) {
|
|
|
|
remainigContext.add(c);
|
|
|
|
hashValue.add(c.hashCode());
|
2020-07-24 17:28:11 +02:00
|
|
|
}
|
2021-10-13 11:28:28 +02:00
|
|
|
});
|
|
|
|
((CommunityResult) out).setContext(remainigContext);
|
2020-07-24 17:28:11 +02:00
|
|
|
}
|
2021-10-13 11:28:28 +02:00
|
|
|
}
|
|
|
|
} catch (ClassCastException cce) {
|
|
|
|
return out;
|
2020-07-24 17:28:11 +02:00
|
|
|
}
|
|
|
|
}
|
2021-10-13 11:28:28 +02:00
|
|
|
|
2020-06-15 11:12:14 +02:00
|
|
|
return out;
|
2020-07-24 17:28:11 +02:00
|
|
|
|
2020-06-15 11:12:14 +02:00
|
|
|
}
|
|
|
|
|
2021-10-13 11:28:28 +02:00
|
|
|
private static void addTypeSpecificInformation(Result out, eu.dnetlib.dhp.schema.oaf.Result input,
|
|
|
|
Optional<eu.dnetlib.dhp.schema.oaf.Qualifier> ort) throws NoAvailableEntityTypeException {
|
|
|
|
switch (ort.get().getClassid()) {
|
|
|
|
case "publication":
|
|
|
|
Optional<Journal> journal = Optional
|
|
|
|
.ofNullable(((Publication) input).getJournal());
|
|
|
|
if (journal.isPresent()) {
|
|
|
|
Journal j = journal.get();
|
|
|
|
Container c = new Container();
|
|
|
|
c.setConferencedate(j.getConferencedate());
|
|
|
|
c.setConferenceplace(j.getConferenceplace());
|
|
|
|
c.setEdition(j.getEdition());
|
|
|
|
c.setEp(j.getEp());
|
|
|
|
c.setIss(j.getIss());
|
|
|
|
c.setIssnLinking(j.getIssnLinking());
|
|
|
|
c.setIssnOnline(j.getIssnOnline());
|
|
|
|
c.setIssnPrinted(j.getIssnPrinted());
|
|
|
|
c.setName(j.getName());
|
|
|
|
c.setSp(j.getSp());
|
|
|
|
c.setVol(j.getVol());
|
|
|
|
out.setContainer(c);
|
|
|
|
out.setType(ModelConstants.PUBLICATION_DEFAULT_RESULTTYPE.getClassname());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "dataset":
|
|
|
|
Dataset id = (Dataset) input;
|
|
|
|
Optional.ofNullable(id.getSize()).ifPresent(v -> out.setSize(v.getValue()));
|
|
|
|
Optional.ofNullable(id.getVersion()).ifPresent(v -> out.setVersion(v.getValue()));
|
|
|
|
|
|
|
|
out
|
|
|
|
.setGeolocation(
|
|
|
|
Optional
|
|
|
|
.ofNullable(id.getGeolocation())
|
|
|
|
.map(
|
|
|
|
igl -> igl
|
|
|
|
.stream()
|
|
|
|
.filter(Objects::nonNull)
|
|
|
|
.map(gli -> {
|
|
|
|
GeoLocation gl = new GeoLocation();
|
|
|
|
gl.setBox(gli.getBox());
|
|
|
|
gl.setPlace(gli.getPlace());
|
|
|
|
gl.setPoint(gli.getPoint());
|
|
|
|
return gl;
|
|
|
|
})
|
|
|
|
.collect(Collectors.toList()))
|
|
|
|
.orElse(null));
|
|
|
|
|
|
|
|
out.setType(ModelConstants.DATASET_DEFAULT_RESULTTYPE.getClassname());
|
|
|
|
break;
|
|
|
|
case "software":
|
|
|
|
|
|
|
|
Software is = (Software) input;
|
|
|
|
Optional
|
|
|
|
.ofNullable(is.getCodeRepositoryUrl())
|
|
|
|
.ifPresent(value -> out.setCodeRepositoryUrl(value.getValue()));
|
|
|
|
Optional
|
|
|
|
.ofNullable(is.getDocumentationUrl())
|
|
|
|
.ifPresent(
|
|
|
|
value -> out
|
|
|
|
.setDocumentationUrl(
|
|
|
|
value
|
|
|
|
.stream()
|
|
|
|
.map(Field::getValue)
|
|
|
|
.collect(Collectors.toList())));
|
|
|
|
|
|
|
|
Optional
|
|
|
|
.ofNullable(is.getProgrammingLanguage())
|
|
|
|
.ifPresent(value -> out.setProgrammingLanguage(value.getClassid()));
|
|
|
|
|
|
|
|
out.setType(ModelConstants.SOFTWARE_DEFAULT_RESULTTYPE.getClassname());
|
|
|
|
break;
|
|
|
|
case "other":
|
|
|
|
|
|
|
|
OtherResearchProduct ir = (OtherResearchProduct) input;
|
|
|
|
out
|
|
|
|
.setContactgroup(
|
|
|
|
Optional
|
|
|
|
.ofNullable(ir.getContactgroup())
|
|
|
|
.map(value -> value.stream().map(Field::getValue).collect(Collectors.toList()))
|
|
|
|
.orElse(null));
|
|
|
|
|
|
|
|
out
|
|
|
|
.setContactperson(
|
|
|
|
Optional
|
|
|
|
.ofNullable(ir.getContactperson())
|
|
|
|
.map(value -> value.stream().map(Field::getValue).collect(Collectors.toList()))
|
|
|
|
.orElse(null));
|
|
|
|
out
|
|
|
|
.setTool(
|
|
|
|
Optional
|
|
|
|
.ofNullable(ir.getTool())
|
|
|
|
.map(value -> value.stream().map(Field::getValue).collect(Collectors.toList()))
|
|
|
|
.orElse(null));
|
|
|
|
|
|
|
|
out.setType(ModelConstants.ORP_DEFAULT_RESULTTYPE.getClassname());
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
throw new NoAvailableEntityTypeException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-24 17:00:20 +02:00
|
|
|
private static Instance getGraphInstance(eu.dnetlib.dhp.schema.oaf.Instance i) {
|
2020-08-19 11:28:26 +02:00
|
|
|
Instance instance = new Instance();
|
2020-08-13 18:45:50 +02:00
|
|
|
|
2020-08-19 11:28:26 +02:00
|
|
|
setCommonValue(i, instance);
|
2020-08-13 18:45:50 +02:00
|
|
|
|
2020-08-19 11:28:26 +02:00
|
|
|
return instance;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-08-24 17:00:20 +02:00
|
|
|
private static CommunityInstance getCommunityInstance(eu.dnetlib.dhp.schema.oaf.Instance i) {
|
2020-08-19 11:28:26 +02:00
|
|
|
CommunityInstance instance = new CommunityInstance();
|
|
|
|
|
|
|
|
setCommonValue(i, instance);
|
|
|
|
|
2020-08-24 17:00:20 +02:00
|
|
|
instance
|
|
|
|
.setCollectedfrom(
|
2021-11-19 15:56:25 +01:00
|
|
|
CfHbKeyValue
|
2020-08-24 17:00:20 +02:00
|
|
|
.newInstance(i.getCollectedfrom().getKey(), i.getCollectedfrom().getValue()));
|
2020-08-19 11:28:26 +02:00
|
|
|
|
|
|
|
instance
|
2020-08-24 17:00:20 +02:00
|
|
|
.setHostedby(
|
2021-11-19 15:56:25 +01:00
|
|
|
CfHbKeyValue.newInstance(i.getHostedby().getKey(), i.getHostedby().getValue()));
|
2020-08-19 11:28:26 +02:00
|
|
|
|
|
|
|
return instance;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-11-04 17:15:21 +01:00
|
|
|
private static <I extends Instance> void setCommonValue(eu.dnetlib.dhp.schema.oaf.Instance i, I instance) {
|
2021-08-05 15:20:50 +02:00
|
|
|
Optional<eu.dnetlib.dhp.schema.oaf.AccessRight> opAr = Optional.ofNullable(i.getAccessright());
|
|
|
|
|
2021-10-04 18:40:07 +02:00
|
|
|
if (opAr.isPresent() && Constants.accessRightsCoarMap.containsKey(opAr.get().getClassid())) {
|
|
|
|
String code = Constants.accessRightsCoarMap.get(opAr.get().getClassid());
|
2021-08-05 15:20:50 +02:00
|
|
|
|
2021-10-04 18:40:07 +02:00
|
|
|
instance
|
|
|
|
.setAccessright(
|
|
|
|
AccessRight
|
|
|
|
.newInstance(
|
|
|
|
code,
|
|
|
|
Constants.coarCodeLabelMap.get(code),
|
|
|
|
Constants.COAR_ACCESS_RIGHT_SCHEMA));
|
2021-11-16 12:04:21 +01:00
|
|
|
|
2021-11-19 11:25:50 +01:00
|
|
|
Optional<List<eu.dnetlib.dhp.schema.oaf.Measure>> mes = Optional.ofNullable(i.getMeasures());
|
|
|
|
if (mes.isPresent()) {
|
|
|
|
List<Measure> measure = new ArrayList<>();
|
2021-11-16 12:04:21 +01:00
|
|
|
mes
|
2021-11-19 11:25:50 +01:00
|
|
|
.get()
|
|
|
|
.forEach(
|
|
|
|
m -> m.getUnit().forEach(u -> measure.add(Measure.newInstance(m.getId(), u.getValue()))));
|
|
|
|
instance.setMeasures(measure);
|
2021-11-16 12:04:21 +01:00
|
|
|
}
|
|
|
|
|
2021-10-04 18:40:07 +02:00
|
|
|
if (opAr.get().getOpenAccessRoute() != null) {
|
|
|
|
switch (opAr.get().getOpenAccessRoute()) {
|
|
|
|
case hybrid:
|
|
|
|
instance.getAccessright().setOpenAccessRoute(OpenAccessRoute.hybrid);
|
|
|
|
break;
|
|
|
|
case gold:
|
|
|
|
instance.getAccessright().setOpenAccessRoute(OpenAccessRoute.gold);
|
|
|
|
break;
|
|
|
|
case green:
|
|
|
|
instance.getAccessright().setOpenAccessRoute(OpenAccessRoute.green);
|
|
|
|
break;
|
|
|
|
case bronze:
|
|
|
|
instance.getAccessright().setOpenAccessRoute(OpenAccessRoute.bronze);
|
|
|
|
break;
|
2021-08-05 15:20:50 +02:00
|
|
|
|
|
|
|
}
|
2020-08-13 18:45:50 +02:00
|
|
|
}
|
2021-10-04 18:40:07 +02:00
|
|
|
|
2020-08-19 11:28:26 +02:00
|
|
|
}
|
2020-08-13 18:45:50 +02:00
|
|
|
|
2021-08-06 18:56:18 +02:00
|
|
|
Optional
|
|
|
|
.ofNullable(i.getPid())
|
|
|
|
.ifPresent(
|
|
|
|
pid -> instance
|
|
|
|
.setPid(
|
|
|
|
pid
|
|
|
|
.stream()
|
2021-11-19 11:25:50 +01:00
|
|
|
.map(p -> ResultPid.newInstance(p.getQualifier().getClassid(), p.getValue()))
|
2021-08-06 18:56:18 +02:00
|
|
|
.collect(Collectors.toList())));
|
2021-08-05 15:20:50 +02:00
|
|
|
|
2021-08-06 18:56:18 +02:00
|
|
|
Optional
|
|
|
|
.ofNullable(i.getAlternateIdentifier())
|
|
|
|
.ifPresent(
|
|
|
|
ai -> instance
|
|
|
|
.setAlternateIdentifier(
|
|
|
|
ai
|
|
|
|
.stream()
|
2021-11-19 11:25:50 +01:00
|
|
|
.map(p -> AlternateIdentifier.newInstance(p.getQualifier().getClassid(), p.getValue()))
|
2021-08-06 18:56:18 +02:00
|
|
|
.collect(Collectors.toList())));
|
2021-08-05 15:20:50 +02:00
|
|
|
|
2020-08-19 11:28:26 +02:00
|
|
|
Optional
|
|
|
|
.ofNullable(i.getLicense())
|
|
|
|
.ifPresent(value -> instance.setLicense(value.getValue()));
|
|
|
|
Optional
|
|
|
|
.ofNullable(i.getDateofacceptance())
|
|
|
|
.ifPresent(value -> instance.setPublicationdate(value.getValue()));
|
|
|
|
Optional
|
|
|
|
.ofNullable(i.getRefereed())
|
|
|
|
.ifPresent(value -> instance.setRefereed(value.getClassname()));
|
|
|
|
Optional
|
|
|
|
.ofNullable(i.getInstancetype())
|
|
|
|
.ifPresent(value -> instance.setType(value.getClassname()));
|
|
|
|
Optional.ofNullable(i.getUrl()).ifPresent(value -> instance.setUrl(value));
|
2021-07-13 15:13:58 +02:00
|
|
|
Optional<Field<String>> oPca = Optional.ofNullable(i.getProcessingchargeamount());
|
|
|
|
Optional<Field<String>> oPcc = Optional.ofNullable(i.getProcessingchargecurrency());
|
|
|
|
if (oPca.isPresent() && oPcc.isPresent()) {
|
2021-07-13 15:53:35 +02:00
|
|
|
Field<String> pca = oPca.get();
|
|
|
|
Field<String> pcc = oPcc.get();
|
2021-07-13 17:10:02 +02:00
|
|
|
if (!pca.getValue().trim().equals("") && !pcc.getValue().trim().equals("")) {
|
2021-07-13 15:53:35 +02:00
|
|
|
APC apc = new APC();
|
|
|
|
apc.setCurrency(oPcc.get().getValue());
|
|
|
|
apc.setAmount(oPca.get().getValue());
|
|
|
|
instance.setArticleprocessingcharge(apc);
|
|
|
|
}
|
|
|
|
|
2021-07-13 15:13:58 +02:00
|
|
|
}
|
2021-08-11 12:13:22 +02:00
|
|
|
Optional.ofNullable(i.getUrl()).ifPresent(instance::setUrl);
|
2020-08-13 18:45:50 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-10-04 18:40:07 +02:00
|
|
|
private static List<Provenance> getUniqueProvenance(List<Provenance> provenance)
|
|
|
|
throws NoAvailableEntityTypeException {
|
2020-08-07 17:48:18 +02:00
|
|
|
Provenance iProv = new Provenance();
|
|
|
|
|
|
|
|
Provenance hProv = new Provenance();
|
|
|
|
Provenance lProv = new Provenance();
|
|
|
|
|
|
|
|
for (Provenance p : provenance) {
|
|
|
|
switch (p.getProvenance()) {
|
|
|
|
case Constants.HARVESTED:
|
|
|
|
hProv = getHighestTrust(hProv, p);
|
|
|
|
break;
|
|
|
|
case Constants.INFERRED:
|
|
|
|
iProv = getHighestTrust(iProv, p);
|
|
|
|
// To be removed as soon as the new beta run has been done
|
|
|
|
// this fixex issue of not set trust during bulktagging
|
|
|
|
if (StringUtils.isEmpty(iProv.getTrust())) {
|
|
|
|
iProv.setTrust(Constants.DEFAULT_TRUST);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Constants.USER_CLAIM:
|
|
|
|
lProv = getHighestTrust(lProv, p);
|
|
|
|
break;
|
2021-10-04 18:40:07 +02:00
|
|
|
default:
|
|
|
|
throw new NoAvailableEntityTypeException();
|
2020-08-07 17:48:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Arrays
|
|
|
|
.asList(iProv, hProv, lProv)
|
|
|
|
.stream()
|
|
|
|
.filter(p -> !StringUtils.isEmpty(p.getProvenance()))
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private static Provenance getHighestTrust(Provenance hProv, Provenance p) {
|
|
|
|
if (StringUtils.isNoneEmpty(hProv.getTrust(), p.getTrust()))
|
|
|
|
return hProv.getTrust().compareTo(p.getTrust()) > 0 ? hProv : p;
|
|
|
|
|
|
|
|
return (StringUtils.isEmpty(p.getTrust()) && !StringUtils.isEmpty(hProv.getTrust())) ? hProv : p;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-07-24 17:28:11 +02:00
|
|
|
private static Subject getSubject(StructuredProperty s) {
|
2020-07-20 17:46:27 +02:00
|
|
|
Subject subject = new Subject();
|
2021-11-19 11:25:50 +01:00
|
|
|
subject.setSubject(SubjectSchemeValue.newInstance(s.getQualifier().getClassid(), s.getValue()));
|
2020-07-20 17:54:28 +02:00
|
|
|
Optional<DataInfo> di = Optional.ofNullable(s.getDataInfo());
|
2020-07-24 17:28:11 +02:00
|
|
|
if (di.isPresent()) {
|
2020-07-20 17:54:28 +02:00
|
|
|
Provenance p = new Provenance();
|
2020-07-20 17:46:27 +02:00
|
|
|
p.setProvenance(di.get().getProvenanceaction().getClassname());
|
|
|
|
p.setTrust(di.get().getTrust());
|
|
|
|
subject.setProvenance(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
return subject;
|
|
|
|
}
|
2020-07-24 17:28:11 +02:00
|
|
|
|
2020-06-15 11:12:14 +02:00
|
|
|
private static Author getAuthor(eu.dnetlib.dhp.schema.oaf.Author oa) {
|
|
|
|
Author a = new Author();
|
|
|
|
a.setFullname(oa.getFullname());
|
|
|
|
a.setName(oa.getName());
|
|
|
|
a.setSurname(oa.getSurname());
|
|
|
|
a.setRank(oa.getRank());
|
2020-08-07 17:48:18 +02:00
|
|
|
|
|
|
|
Optional<List<StructuredProperty>> oPids = Optional
|
|
|
|
.ofNullable(oa.getPid());
|
|
|
|
if (oPids.isPresent()) {
|
2021-11-19 11:25:50 +01:00
|
|
|
AuthorPid pid = getOrcid(oPids.get());
|
2020-08-07 17:48:18 +02:00
|
|
|
if (pid != null) {
|
|
|
|
a.setPid(pid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-15 11:12:14 +02:00
|
|
|
return a;
|
|
|
|
}
|
2020-06-09 15:39:03 +02:00
|
|
|
|
2021-11-19 11:25:50 +01:00
|
|
|
private static AuthorPid getAuthorPid(StructuredProperty pid) {
|
2021-08-06 18:56:18 +02:00
|
|
|
Optional<DataInfo> di = Optional.ofNullable(pid.getDataInfo());
|
|
|
|
if (di.isPresent()) {
|
2021-11-19 11:25:50 +01:00
|
|
|
return AuthorPid
|
2021-10-01 12:59:47 +02:00
|
|
|
.newInstance(
|
2021-11-19 11:25:50 +01:00
|
|
|
AuthorPidSchemeValue
|
2021-10-01 12:59:47 +02:00
|
|
|
.newInstance(
|
|
|
|
pid.getQualifier().getClassid(),
|
|
|
|
pid.getValue()),
|
|
|
|
Provenance
|
|
|
|
.newInstance(
|
|
|
|
di.get().getProvenanceaction().getClassname(),
|
|
|
|
di.get().getTrust()));
|
2021-08-06 18:56:18 +02:00
|
|
|
} else {
|
2021-11-19 11:25:50 +01:00
|
|
|
return AuthorPid
|
2021-10-01 12:59:47 +02:00
|
|
|
.newInstance(
|
2021-11-19 11:25:50 +01:00
|
|
|
AuthorPidSchemeValue
|
2021-10-01 12:59:47 +02:00
|
|
|
.newInstance(
|
|
|
|
pid.getQualifier().getClassid(),
|
|
|
|
pid.getValue())
|
2020-08-07 17:48:18 +02:00
|
|
|
|
2021-10-01 12:59:47 +02:00
|
|
|
);
|
2021-08-06 18:56:18 +02:00
|
|
|
}
|
|
|
|
}
|
2020-08-07 17:48:18 +02:00
|
|
|
|
2021-11-19 11:25:50 +01:00
|
|
|
private static AuthorPid getOrcid(List<StructuredProperty> p) {
|
2021-10-04 18:40:07 +02:00
|
|
|
List<StructuredProperty> pidList = p.stream().map(pid -> {
|
2021-08-06 18:56:18 +02:00
|
|
|
if (pid.getQualifier().getClassid().equals(ModelConstants.ORCID) ||
|
2021-10-01 12:59:47 +02:00
|
|
|
(pid.getQualifier().getClassid().equals(ModelConstants.ORCID_PENDING))) {
|
2021-08-06 18:56:18 +02:00
|
|
|
return pid;
|
2020-08-07 17:48:18 +02:00
|
|
|
}
|
2021-10-01 12:59:47 +02:00
|
|
|
return null;
|
2021-10-04 18:40:07 +02:00
|
|
|
}).filter(Objects::nonNull).collect(Collectors.toList());
|
2021-08-06 18:56:18 +02:00
|
|
|
|
2021-10-04 18:40:07 +02:00
|
|
|
if (pidList.size() == 1) {
|
|
|
|
return getAuthorPid(pidList.get(0));
|
2020-08-07 17:48:18 +02:00
|
|
|
}
|
2021-08-06 18:56:18 +02:00
|
|
|
|
2021-10-04 18:40:07 +02:00
|
|
|
List<StructuredProperty> orcid = pidList
|
2021-10-01 12:59:47 +02:00
|
|
|
.stream()
|
|
|
|
.filter(
|
|
|
|
ap -> ap
|
|
|
|
.getQualifier()
|
|
|
|
.getClassid()
|
|
|
|
.equals(ModelConstants.ORCID))
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
if (orcid.size() == 1) {
|
2021-08-06 18:56:18 +02:00
|
|
|
return getAuthorPid(orcid.get(0));
|
|
|
|
}
|
2021-10-04 18:40:07 +02:00
|
|
|
orcid = pidList
|
2021-10-01 12:59:47 +02:00
|
|
|
.stream()
|
|
|
|
.filter(
|
|
|
|
ap -> ap
|
|
|
|
.getQualifier()
|
|
|
|
.getClassid()
|
|
|
|
.equals(ModelConstants.ORCID_PENDING))
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
if (orcid.size() == 1) {
|
2021-08-06 18:56:18 +02:00
|
|
|
return getAuthorPid(orcid.get(0));
|
|
|
|
}
|
|
|
|
|
2020-08-07 17:48:18 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-06-09 15:37:46 +02:00
|
|
|
}
|