in theory, just auto-formatting after mvn compile

This commit is contained in:
Alessia Bardi 2020-12-09 20:00:27 +01:00
parent bece04b330
commit 112da6d76a
4 changed files with 364 additions and 365 deletions

View File

@ -1,10 +1,10 @@
package eu.dnetlib.dhp.common; package eu.dnetlib.dhp.common;
import com.google.common.collect.Maps;
import java.util.Map; import java.util.Map;
import com.google.common.collect.Maps;
public class Constants { public class Constants {
public static final Map<String, String> accessRightsCoarMap = Maps.newHashMap(); public static final Map<String, String> accessRightsCoarMap = Maps.newHashMap();

View File

@ -1,6 +1,10 @@
package eu.dnetlib.dhp.common; package eu.dnetlib.dhp.common;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
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.CommunityInstance;
@ -10,406 +14,399 @@ import eu.dnetlib.dhp.schema.oaf.Field;
import eu.dnetlib.dhp.schema.oaf.Journal; import eu.dnetlib.dhp.schema.oaf.Journal;
import eu.dnetlib.dhp.schema.oaf.StructuredProperty; import eu.dnetlib.dhp.schema.oaf.StructuredProperty;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
public class GraphResultMapper implements Serializable { public class GraphResultMapper implements Serializable {
public static <E extends eu.dnetlib.dhp.schema.oaf.OafEntity> Result map( public static <E extends eu.dnetlib.dhp.schema.oaf.OafEntity> Result map(
E in) { E in) {
CommunityResult out = new CommunityResult(); CommunityResult out = new CommunityResult();
eu.dnetlib.dhp.schema.oaf.Result input = (eu.dnetlib.dhp.schema.oaf.Result) in; eu.dnetlib.dhp.schema.oaf.Result input = (eu.dnetlib.dhp.schema.oaf.Result) in;
Optional<eu.dnetlib.dhp.schema.oaf.Qualifier> ort = Optional.ofNullable(input.getResulttype()); Optional<eu.dnetlib.dhp.schema.oaf.Qualifier> ort = Optional.ofNullable(input.getResulttype());
if (ort.isPresent()) { if (ort.isPresent()) {
switch (ort.get().getClassid()) { switch (ort.get().getClassid()) {
case "publication": case "publication":
Optional<Journal> journal = Optional Optional<Journal> journal = Optional
.ofNullable(((eu.dnetlib.dhp.schema.oaf.Publication) input).getJournal()); .ofNullable(((eu.dnetlib.dhp.schema.oaf.Publication) input).getJournal());
if (journal.isPresent()) { if (journal.isPresent()) {
Journal j = journal.get(); Journal j = journal.get();
Container c = new Container(); Container c = new Container();
c.setConferencedate(j.getConferencedate()); c.setConferencedate(j.getConferencedate());
c.setConferenceplace(j.getConferenceplace()); c.setConferenceplace(j.getConferenceplace());
c.setEdition(j.getEdition()); c.setEdition(j.getEdition());
c.setEp(j.getEp()); c.setEp(j.getEp());
c.setIss(j.getIss()); c.setIss(j.getIss());
c.setIssnLinking(j.getIssnLinking()); c.setIssnLinking(j.getIssnLinking());
c.setIssnOnline(j.getIssnOnline()); c.setIssnOnline(j.getIssnOnline());
c.setIssnPrinted(j.getIssnPrinted()); c.setIssnPrinted(j.getIssnPrinted());
c.setName(j.getName()); c.setName(j.getName());
c.setSp(j.getSp()); c.setSp(j.getSp());
c.setVol(j.getVol()); c.setVol(j.getVol());
out.setContainer(c); out.setContainer(c);
out.setType(ModelConstants.PUBLICATION_DEFAULT_RESULTTYPE.getClassname()); out.setType(ModelConstants.PUBLICATION_DEFAULT_RESULTTYPE.getClassname());
} }
break; break;
case "dataset": case "dataset":
eu.dnetlib.dhp.schema.oaf.Dataset id = (eu.dnetlib.dhp.schema.oaf.Dataset) input; eu.dnetlib.dhp.schema.oaf.Dataset id = (eu.dnetlib.dhp.schema.oaf.Dataset) input;
Optional.ofNullable(id.getSize()).ifPresent(v -> out.setSize(v.getValue())); Optional.ofNullable(id.getSize()).ifPresent(v -> out.setSize(v.getValue()));
Optional.ofNullable(id.getVersion()).ifPresent(v -> out.setVersion(v.getValue())); Optional.ofNullable(id.getVersion()).ifPresent(v -> out.setVersion(v.getValue()));
out out
.setGeolocation( .setGeolocation(
Optional Optional
.ofNullable(id.getGeolocation()) .ofNullable(id.getGeolocation())
.map( .map(
igl -> igl igl -> igl
.stream() .stream()
.filter(Objects::nonNull) .filter(Objects::nonNull)
.map(gli -> { .map(gli -> {
GeoLocation gl = new GeoLocation(); GeoLocation gl = new GeoLocation();
gl.setBox(gli.getBox()); gl.setBox(gli.getBox());
gl.setPlace(gli.getPlace()); gl.setPlace(gli.getPlace());
gl.setPoint(gli.getPoint()); gl.setPoint(gli.getPoint());
return gl; return gl;
}) })
.collect(Collectors.toList())) .collect(Collectors.toList()))
.orElse(null)); .orElse(null));
out.setType(ModelConstants.DATASET_DEFAULT_RESULTTYPE.getClassname()); out.setType(ModelConstants.DATASET_DEFAULT_RESULTTYPE.getClassname());
break; break;
case "software": case "software":
eu.dnetlib.dhp.schema.oaf.Software is = (eu.dnetlib.dhp.schema.oaf.Software) input; eu.dnetlib.dhp.schema.oaf.Software is = (eu.dnetlib.dhp.schema.oaf.Software) input;
Optional Optional
.ofNullable(is.getCodeRepositoryUrl()) .ofNullable(is.getCodeRepositoryUrl())
.ifPresent(value -> out.setCodeRepositoryUrl(value.getValue())); .ifPresent(value -> out.setCodeRepositoryUrl(value.getValue()));
Optional Optional
.ofNullable(is.getDocumentationUrl()) .ofNullable(is.getDocumentationUrl())
.ifPresent( .ifPresent(
value -> out value -> out
.setDocumentationUrl( .setDocumentationUrl(
value value
.stream() .stream()
.map(v -> v.getValue()) .map(v -> v.getValue())
.collect(Collectors.toList()))); .collect(Collectors.toList())));
Optional Optional
.ofNullable(is.getProgrammingLanguage()) .ofNullable(is.getProgrammingLanguage())
.ifPresent(value -> out.setProgrammingLanguage(value.getClassid())); .ifPresent(value -> out.setProgrammingLanguage(value.getClassid()));
out.setType(ModelConstants.SOFTWARE_DEFAULT_RESULTTYPE.getClassname()); out.setType(ModelConstants.SOFTWARE_DEFAULT_RESULTTYPE.getClassname());
break; break;
case "other": case "other":
eu.dnetlib.dhp.schema.oaf.OtherResearchProduct ir = (eu.dnetlib.dhp.schema.oaf.OtherResearchProduct) input; eu.dnetlib.dhp.schema.oaf.OtherResearchProduct ir = (eu.dnetlib.dhp.schema.oaf.OtherResearchProduct) input;
out out
.setContactgroup( .setContactgroup(
Optional Optional
.ofNullable(ir.getContactgroup()) .ofNullable(ir.getContactgroup())
.map(value -> value.stream().map(cg -> cg.getValue()).collect(Collectors.toList())) .map(value -> value.stream().map(cg -> cg.getValue()).collect(Collectors.toList()))
.orElse(null)); .orElse(null));
out out
.setContactperson( .setContactperson(
Optional Optional
.ofNullable(ir.getContactperson()) .ofNullable(ir.getContactperson())
.map(value -> value.stream().map(cp -> cp.getValue()).collect(Collectors.toList())) .map(value -> value.stream().map(cp -> cp.getValue()).collect(Collectors.toList()))
.orElse(null)); .orElse(null));
out out
.setTool( .setTool(
Optional Optional
.ofNullable(ir.getTool()) .ofNullable(ir.getTool())
.map(value -> value.stream().map(t -> t.getValue()).collect(Collectors.toList())) .map(value -> value.stream().map(t -> t.getValue()).collect(Collectors.toList()))
.orElse(null)); .orElse(null));
out.setType(ModelConstants.ORP_DEFAULT_RESULTTYPE.getClassname()); out.setType(ModelConstants.ORP_DEFAULT_RESULTTYPE.getClassname());
break; break;
} }
Optional Optional
.ofNullable(input.getAuthor()) .ofNullable(input.getAuthor())
.ifPresent(ats -> out.setAuthor(ats.stream().map(at -> getAuthor(at)).collect(Collectors.toList()))); .ifPresent(ats -> out.setAuthor(ats.stream().map(at -> getAuthor(at)).collect(Collectors.toList())));
// I do not map Access Right UNKNOWN or OTHER // I do not map Access Right UNKNOWN or OTHER
Optional<eu.dnetlib.dhp.schema.oaf.Qualifier> oar = Optional.ofNullable(input.getBestaccessright()); Optional<eu.dnetlib.dhp.schema.oaf.Qualifier> oar = Optional.ofNullable(input.getBestaccessright());
if (oar.isPresent()) { if (oar.isPresent()) {
if (Constants.accessRightsCoarMap.containsKey(oar.get().getClassid())) { if (Constants.accessRightsCoarMap.containsKey(oar.get().getClassid())) {
String code = Constants.accessRightsCoarMap.get(oar.get().getClassid()); String code = Constants.accessRightsCoarMap.get(oar.get().getClassid());
out out
.setBestaccessright( .setBestaccessright(
AccessRight AccessRight
.newInstance( .newInstance(
code, code,
Constants.coarCodeLabelMap.get(code), Constants.coarCodeLabelMap.get(code),
Constants.COAR_ACCESS_RIGHT_SCHEMA)); Constants.COAR_ACCESS_RIGHT_SCHEMA));
} }
} }
final List<String> contributorList = new ArrayList<>(); final List<String> contributorList = new ArrayList<>();
Optional Optional
.ofNullable(input.getContributor()) .ofNullable(input.getContributor())
.ifPresent(value -> value.stream().forEach(c -> contributorList.add(c.getValue()))); .ifPresent(value -> value.stream().forEach(c -> contributorList.add(c.getValue())));
out.setContributor(contributorList); out.setContributor(contributorList);
Optional Optional
.ofNullable(input.getCountry()) .ofNullable(input.getCountry())
.ifPresent( .ifPresent(
value -> out value -> out
.setCountry( .setCountry(
value value
.stream() .stream()
.map( .map(
c -> { c -> {
if (c.getClassid().equals((ModelConstants.UNKNOWN))) { if (c.getClassid().equals((ModelConstants.UNKNOWN))) {
return null; return null;
} }
Country country = new Country(); Country country = new Country();
country.setCode(c.getClassid()); country.setCode(c.getClassid());
country.setLabel(c.getClassname()); country.setLabel(c.getClassname());
Optional Optional
.ofNullable(c.getDataInfo()) .ofNullable(c.getDataInfo())
.ifPresent( .ifPresent(
provenance -> country provenance -> country
.setProvenance( .setProvenance(
Provenance Provenance
.newInstance( .newInstance(
provenance provenance
.getProvenanceaction() .getProvenanceaction()
.getClassname(), .getClassname(),
c.getDataInfo().getTrust()))); c.getDataInfo().getTrust())));
return country; return country;
}) })
.filter(Objects::nonNull) .filter(Objects::nonNull)
.collect(Collectors.toList()))); .collect(Collectors.toList())));
final List<String> coverageList = new ArrayList<>(); final List<String> coverageList = new ArrayList<>();
Optional Optional
.ofNullable(input.getCoverage()) .ofNullable(input.getCoverage())
.ifPresent(value -> value.stream().forEach(c -> coverageList.add(c.getValue()))); .ifPresent(value -> value.stream().forEach(c -> coverageList.add(c.getValue())));
out.setCoverage(coverageList); out.setCoverage(coverageList);
out.setDateofcollection(input.getDateofcollection()); out.setDateofcollection(input.getDateofcollection());
final List<String> descriptionList = new ArrayList<>(); final List<String> descriptionList = new ArrayList<>();
Optional Optional
.ofNullable(input.getDescription()) .ofNullable(input.getDescription())
.ifPresent(value -> value.forEach(d -> descriptionList.add(d.getValue()))); .ifPresent(value -> value.forEach(d -> descriptionList.add(d.getValue())));
out.setDescription(descriptionList); out.setDescription(descriptionList);
Optional<Field<String>> oStr = Optional.ofNullable(input.getEmbargoenddate()); Optional<Field<String>> oStr = Optional.ofNullable(input.getEmbargoenddate());
if (oStr.isPresent()) { if (oStr.isPresent()) {
out.setEmbargoenddate(oStr.get().getValue()); out.setEmbargoenddate(oStr.get().getValue());
} }
final List<String> formatList = new ArrayList<>(); final List<String> formatList = new ArrayList<>();
Optional Optional
.ofNullable(input.getFormat()) .ofNullable(input.getFormat())
.ifPresent(value -> value.stream().forEach(f -> formatList.add(f.getValue()))); .ifPresent(value -> value.stream().forEach(f -> formatList.add(f.getValue())));
out.setFormat(formatList); out.setFormat(formatList);
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()) {
out out
.setInstance( .setInstance(
oInst.get().stream().map(i -> getInstance(i)).collect(Collectors.toList())); oInst.get().stream().map(i -> getInstance(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()) {
eu.dnetlib.dhp.schema.oaf.Qualifier language = oL.get(); eu.dnetlib.dhp.schema.oaf.Qualifier language = oL.get();
out.setLanguage(Qualifier.newInstance(language.getClassid(), language.getClassname())); out.setLanguage(Qualifier.newInstance(language.getClassid(), language.getClassname()));
} }
Optional<Long> oLong = Optional.ofNullable(input.getLastupdatetimestamp()); Optional<Long> oLong = Optional.ofNullable(input.getLastupdatetimestamp());
if (oLong.isPresent()) { if (oLong.isPresent()) {
out.setLastupdatetimestamp(oLong.get()); out.setLastupdatetimestamp(oLong.get());
} }
Optional<List<StructuredProperty>> otitle = Optional.ofNullable(input.getTitle()); Optional<List<StructuredProperty>> otitle = Optional.ofNullable(input.getTitle());
if (otitle.isPresent()) { if (otitle.isPresent()) {
List<StructuredProperty> iTitle = otitle List<StructuredProperty> iTitle = otitle
.get() .get()
.stream() .stream()
.filter(t -> t.getQualifier().getClassid().equalsIgnoreCase("main title")) .filter(t -> t.getQualifier().getClassid().equalsIgnoreCase("main title"))
.collect(Collectors.toList()); .collect(Collectors.toList());
if (iTitle.size() > 0) { if (iTitle.size() > 0) {
out.setMaintitle(iTitle.get(0).getValue()); out.setMaintitle(iTitle.get(0).getValue());
} }
iTitle = otitle iTitle = otitle
.get() .get()
.stream() .stream()
.filter(t -> t.getQualifier().getClassid().equalsIgnoreCase("subtitle")) .filter(t -> t.getQualifier().getClassid().equalsIgnoreCase("subtitle"))
.collect(Collectors.toList()); .collect(Collectors.toList());
if (iTitle.size() > 0) { if (iTitle.size() > 0) {
out.setSubtitle(iTitle.get(0).getValue()); out.setSubtitle(iTitle.get(0).getValue());
} }
} }
List<ControlledField> pids = new ArrayList<>(); List<ControlledField> pids = new ArrayList<>();
Optional Optional
.ofNullable(input.getPid()) .ofNullable(input.getPid())
.ifPresent( .ifPresent(
value -> value value -> value
.stream() .stream()
.forEach( .forEach(
p -> pids p -> pids
.add( .add(
ControlledField ControlledField
.newInstance(p.getQualifier().getClassid(), p.getValue())))); .newInstance(p.getQualifier().getClassid(), p.getValue()))));
out.setPid(pids); out.setPid(pids);
oStr = Optional.ofNullable(input.getDateofacceptance()); oStr = Optional.ofNullable(input.getDateofacceptance());
if (oStr.isPresent()) { if (oStr.isPresent()) {
out.setPublicationdate(oStr.get().getValue()); out.setPublicationdate(oStr.get().getValue());
} }
oStr = Optional.ofNullable(input.getPublisher()); oStr = Optional.ofNullable(input.getPublisher());
if (oStr.isPresent()) { if (oStr.isPresent()) {
out.setPublisher(oStr.get().getValue()); out.setPublisher(oStr.get().getValue());
} }
List<String> sourceList = new ArrayList<>(); List<String> sourceList = new ArrayList<>();
Optional Optional
.ofNullable(input.getSource()) .ofNullable(input.getSource())
.ifPresent(value -> value.stream().forEach(s -> sourceList.add(s.getValue()))); .ifPresent(value -> value.stream().forEach(s -> sourceList.add(s.getValue())));
// out.setSource(input.getSource().stream().map(s -> s.getValue()).collect(Collectors.toList())); // out.setSource(input.getSource().stream().map(s -> s.getValue()).collect(Collectors.toList()));
List<Subject> subjectList = new ArrayList<>(); List<Subject> subjectList = new ArrayList<>();
Optional Optional
.ofNullable(input.getSubject()) .ofNullable(input.getSubject())
.ifPresent( .ifPresent(
value -> value value -> value
.forEach(s -> subjectList.add(getSubject(s)))); .forEach(s -> subjectList.add(getSubject(s))));
out.setSubjects(subjectList); out.setSubjects(subjectList);
out.setType(input.getResulttype().getClassid()); out.setType(input.getResulttype().getClassid());
} }
out out
.setCollectedfrom( .setCollectedfrom(
input input
.getCollectedfrom() .getCollectedfrom()
.stream() .stream()
.map(cf -> KeyValue.newInstance(cf.getKey(), cf.getValue())) .map(cf -> KeyValue.newInstance(cf.getKey(), cf.getValue()))
.collect(Collectors.toList())); .collect(Collectors.toList()));
return out;
return out; }
} private static CommunityInstance getInstance(eu.dnetlib.dhp.schema.oaf.Instance i) {
CommunityInstance instance = new CommunityInstance();
setCommonValue(i, instance);
private static CommunityInstance getInstance(eu.dnetlib.dhp.schema.oaf.Instance i) { instance
CommunityInstance instance = new CommunityInstance(); .setCollectedfrom(
KeyValue
.newInstance(i.getCollectedfrom().getKey(), i.getCollectedfrom().getValue()));
setCommonValue(i, instance); instance
.setHostedby(
KeyValue.newInstance(i.getHostedby().getKey(), i.getHostedby().getValue()));
instance return instance;
.setCollectedfrom(
KeyValue
.newInstance(i.getCollectedfrom().getKey(), i.getCollectedfrom().getValue()));
instance }
.setHostedby(
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) {
Optional<eu.dnetlib.dhp.schema.oaf.Qualifier> opAr = Optional
.ofNullable(i.getAccessright());
if (opAr.isPresent()) {
if (Constants.accessRightsCoarMap.containsKey(opAr.get().getClassid())) {
String code = Constants.accessRightsCoarMap.get(opAr.get().getClassid());
instance
.setAccessright(
AccessRight
.newInstance(
code,
Constants.coarCodeLabelMap.get(code),
Constants.COAR_ACCESS_RIGHT_SCHEMA));
}
}
} 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));
private static <I extends Instance> void setCommonValue(eu.dnetlib.dhp.schema.oaf.Instance i, I instance) { }
Optional<eu.dnetlib.dhp.schema.oaf.Qualifier> opAr = Optional
.ofNullable(i.getAccessright());
if (opAr.isPresent()) {
if (Constants.accessRightsCoarMap.containsKey(opAr.get().getClassid())) {
String code = Constants.accessRightsCoarMap.get(opAr.get().getClassid());
instance
.setAccessright(
AccessRight
.newInstance(
code,
Constants.coarCodeLabelMap.get(code),
Constants.COAR_ACCESS_RIGHT_SCHEMA));
}
}
Optional private static Subject getSubject(StructuredProperty s) {
.ofNullable(i.getLicense()) Subject subject = new Subject();
.ifPresent(value -> instance.setLicense(value.getValue())); subject.setSubject(ControlledField.newInstance(s.getQualifier().getClassid(), s.getValue()));
Optional Optional<DataInfo> di = Optional.ofNullable(s.getDataInfo());
.ofNullable(i.getDateofacceptance()) if (di.isPresent()) {
.ifPresent(value -> instance.setPublicationdate(value.getValue())); Provenance p = new Provenance();
Optional p.setProvenance(di.get().getProvenanceaction().getClassname());
.ofNullable(i.getRefereed()) p.setTrust(di.get().getTrust());
.ifPresent(value -> instance.setRefereed(value.getClassname())); subject.setProvenance(p);
Optional }
.ofNullable(i.getInstancetype())
.ifPresent(value -> instance.setType(value.getClassname()));
Optional.ofNullable(i.getUrl()).ifPresent(value -> instance.setUrl(value));
} return subject;
}
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());
private static Subject getSubject(StructuredProperty s) { Optional<List<StructuredProperty>> oPids = Optional
Subject subject = new Subject(); .ofNullable(oa.getPid());
subject.setSubject(ControlledField.newInstance(s.getQualifier().getClassid(), s.getValue())); if (oPids.isPresent()) {
Optional<DataInfo> di = Optional.ofNullable(s.getDataInfo()); Pid pid = getOrcid(oPids.get());
if (di.isPresent()) { if (pid != null) {
Provenance p = new Provenance(); a.setPid(pid);
p.setProvenance(di.get().getProvenanceaction().getClassname()); }
p.setTrust(di.get().getTrust()); }
subject.setProvenance(p);
}
return subject; return a;
} }
private static Author getAuthor(eu.dnetlib.dhp.schema.oaf.Author oa) { private static Pid getOrcid(List<StructuredProperty> p) {
Author a = new Author(); for (StructuredProperty pid : p) {
a.setFullname(oa.getFullname()); if (pid.getQualifier().getClassid().equals(ModelConstants.ORCID)) {
a.setName(oa.getName()); Optional<DataInfo> di = Optional.ofNullable(pid.getDataInfo());
a.setSurname(oa.getSurname()); if (di.isPresent()) {
a.setRank(oa.getRank()); return Pid
.newInstance(
ControlledField
.newInstance(
pid.getQualifier().getClassid(),
pid.getValue()),
Provenance
.newInstance(
di.get().getProvenanceaction().getClassname(),
di.get().getTrust()));
} else {
return Pid
.newInstance(
ControlledField
.newInstance(
pid.getQualifier().getClassid(),
pid.getValue())
Optional<List<StructuredProperty>> oPids = Optional );
.ofNullable(oa.getPid()); }
if (oPids.isPresent()) {
Pid pid = getOrcid(oPids.get());
if (pid != null) {
a.setPid(pid);
}
}
return a; }
} }
return null;
private static Pid getOrcid(List<StructuredProperty> p) { }
for (StructuredProperty pid : p) {
if (pid.getQualifier().getClassid().equals(ModelConstants.ORCID)) {
Optional<DataInfo> di = Optional.ofNullable(pid.getDataInfo());
if (di.isPresent()) {
return Pid
.newInstance(
ControlledField
.newInstance(
pid.getQualifier().getClassid(),
pid.getValue()),
Provenance
.newInstance(
di.get().getProvenanceaction().getClassname(),
di.get().getTrust()));
} else {
return Pid
.newInstance(
ControlledField
.newInstance(
pid.getQualifier().getClassid(),
pid.getValue())
);
}
}
}
return null;
}
} }

View File

@ -49,23 +49,24 @@ public abstract class Oaf implements Serializable {
return; return;
} }
setCollectedfrom( setCollectedfrom(
Stream Stream
.concat( .concat(
Optional Optional
.ofNullable(getCollectedfrom()) .ofNullable(getCollectedfrom())
.map(Collection::stream) .map(Collection::stream)
.orElse(Stream.empty()), .orElse(Stream.empty()),
Optional Optional
.ofNullable(o.getCollectedfrom()) .ofNullable(o.getCollectedfrom())
.map(Collection::stream) .map(Collection::stream)
.orElse(Stream.empty())) .orElse(Stream.empty()))
.distinct() // relies on KeyValue.equals .distinct() // relies on KeyValue.equals
.collect(Collectors.toList())); .collect(Collectors.toList()));
mergeOAFDataInfo(o); mergeOAFDataInfo(o);
setLastupdatetimestamp( setLastupdatetimestamp(
Math.max( Math
.max(
Optional.ofNullable(getLastupdatetimestamp()).orElse(0L), Optional.ofNullable(getLastupdatetimestamp()).orElse(0L),
Optional.ofNullable(o.getLastupdatetimestamp()).orElse(0L))); Optional.ofNullable(o.getLastupdatetimestamp()).orElse(0L)));
} }

View File

@ -371,7 +371,8 @@ public class MappersTest {
assertEquals("OPEN", p.getInstance().get(0).getAccessright().getClassid()); assertEquals("OPEN", p.getInstance().get(0).getAccessright().getClassid());
assertValidId(p.getInstance().get(0).getCollectedfrom().getKey()); assertValidId(p.getInstance().get(0).getCollectedfrom().getKey());
assertValidId(p.getInstance().get(0).getHostedby().getKey()); assertValidId(p.getInstance().get(0).getHostedby().getKey());
assertEquals("http://creativecommons.org/licenses/by/3.0/de/legalcode", p.getInstance().get(0).getLicense().getValue()); assertEquals(
"http://creativecommons.org/licenses/by/3.0/de/legalcode", p.getInstance().get(0).getLicense().getValue());
assertEquals(1, p.getInstance().get(0).getUrl().size()); assertEquals(1, p.getInstance().get(0).getUrl().size());
// System.out.println(p.getInstance().get(0).getUrl().get(0)); // System.out.println(p.getInstance().get(0).getUrl().get(0));
// System.out.println(p.getInstance().get(0).getHostedby().getValue()); // System.out.println(p.getInstance().get(0).getHostedby().getValue());