Compare commits
1 Commits
master
...
doiboost_r
Author | SHA1 | Date |
---|---|---|
Sandro La Bruzzo | d82a4c126b |
2
pom.xml
2
pom.xml
|
@ -5,7 +5,7 @@
|
|||
<groupId>eu.dnetlib.dhp</groupId>
|
||||
<artifactId>dhp-schemas</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>2.12.1-SNAPSHOT</version>
|
||||
<version>2.12.1-DOIBOOST_REFACTOR-SNAPSHOT</version>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
|
|
|
@ -83,34 +83,4 @@ public class Dataset extends Result implements Serializable {
|
|||
this.geolocation = geolocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mergeFrom(OafEntity e) {
|
||||
super.mergeFrom(e);
|
||||
|
||||
if (!Dataset.class.isAssignableFrom(e.getClass())) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Dataset d = (Dataset) e;
|
||||
|
||||
storagedate = d.getStoragedate() != null && compareTrust(this, e) < 0 ? d.getStoragedate() : storagedate;
|
||||
|
||||
device = d.getDevice() != null && compareTrust(this, e) < 0 ? d.getDevice() : device;
|
||||
|
||||
size = d.getSize() != null && compareTrust(this, e) < 0 ? d.getSize() : size;
|
||||
|
||||
version = d.getVersion() != null && compareTrust(this, e) < 0 ? d.getVersion() : version;
|
||||
|
||||
lastmetadataupdate = d.getLastmetadataupdate() != null && compareTrust(this, e) < 0
|
||||
? d.getLastmetadataupdate()
|
||||
: lastmetadataupdate;
|
||||
|
||||
metadataversionnumber = d.getMetadataversionnumber() != null && compareTrust(this, e) < 0
|
||||
? d.getMetadataversionnumber()
|
||||
: metadataversionnumber;
|
||||
|
||||
geolocation = mergeLists(geolocation, d.getGeolocation());
|
||||
|
||||
mergeOAFDataInfo(d);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -553,9 +553,5 @@ public class Datasource extends OafEntity implements Serializable {
|
|||
this.consenttermsofusedate = consenttermsofusedate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mergeFrom(final OafEntity e) {
|
||||
super.mergeFrom(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,9 @@ import java.util.Optional;
|
|||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* The type Oaf.
|
||||
*/
|
||||
public abstract class Oaf implements Serializable {
|
||||
|
||||
/**
|
||||
|
@ -20,76 +23,60 @@ public abstract class Oaf implements Serializable {
|
|||
|
||||
private Long lastupdatetimestamp;
|
||||
|
||||
/**
|
||||
* Gets collectedfrom.
|
||||
*
|
||||
* @return the collectedfrom
|
||||
*/
|
||||
public List<KeyValue> getCollectedfrom() {
|
||||
return collectedfrom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets collectedfrom.
|
||||
*
|
||||
* @param collectedfrom the collectedfrom
|
||||
*/
|
||||
public void setCollectedfrom(List<KeyValue> collectedfrom) {
|
||||
this.collectedfrom = collectedfrom;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets data info.
|
||||
*
|
||||
* @return the data info
|
||||
*/
|
||||
public DataInfo getDataInfo() {
|
||||
return dataInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets data info.
|
||||
*
|
||||
* @param dataInfo the data info
|
||||
*/
|
||||
public void setDataInfo(DataInfo dataInfo) {
|
||||
this.dataInfo = dataInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets lastupdatetimestamp.
|
||||
*
|
||||
* @return the lastupdatetimestamp
|
||||
*/
|
||||
public Long getLastupdatetimestamp() {
|
||||
return lastupdatetimestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets lastupdatetimestamp.
|
||||
*
|
||||
* @param lastupdatetimestamp the lastupdatetimestamp
|
||||
*/
|
||||
public void setLastupdatetimestamp(Long lastupdatetimestamp) {
|
||||
this.lastupdatetimestamp = lastupdatetimestamp;
|
||||
}
|
||||
|
||||
public void mergeFrom(Oaf o) {
|
||||
if (Objects.isNull(o)) {
|
||||
return;
|
||||
}
|
||||
setCollectedfrom(
|
||||
Stream
|
||||
.concat(
|
||||
Optional
|
||||
.ofNullable(getCollectedfrom())
|
||||
.map(Collection::stream)
|
||||
.orElse(Stream.empty()),
|
||||
Optional
|
||||
.ofNullable(o.getCollectedfrom())
|
||||
.map(Collection::stream)
|
||||
.orElse(Stream.empty()))
|
||||
.distinct() // relies on KeyValue.equals
|
||||
.collect(Collectors.toList()));
|
||||
|
||||
setLastupdatetimestamp(
|
||||
Math
|
||||
.max(
|
||||
Optional.ofNullable(getLastupdatetimestamp()).orElse(0L),
|
||||
Optional.ofNullable(o.getLastupdatetimestamp()).orElse(0L)));
|
||||
}
|
||||
|
||||
public void mergeOAFDataInfo(Oaf o) {
|
||||
Optional.ofNullable(o)
|
||||
.ifPresent(other -> Optional.ofNullable(other.getDataInfo())
|
||||
.ifPresent(otherDataInfo -> Optional.ofNullable(this.getDataInfo())
|
||||
.ifPresent(thisDataInfo -> {
|
||||
if (compareTrust(this, other) < 0 || thisDataInfo.getInvisible()) {
|
||||
setDataInfo(otherDataInfo);
|
||||
}
|
||||
})));
|
||||
}
|
||||
|
||||
protected String extractTrust(Oaf e) {
|
||||
if (e == null || e.getDataInfo() == null || e.getDataInfo().getTrust() == null)
|
||||
return "0.0";
|
||||
return e.getDataInfo().getTrust();
|
||||
}
|
||||
|
||||
protected int compareTrust(Oaf a, Oaf b) {
|
||||
return extractTrust(a).compareTo(extractTrust(b));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
|
|
|
@ -5,6 +5,9 @@ import java.io.Serializable;
|
|||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* The type Oaf entity.
|
||||
*/
|
||||
public abstract class OafEntity extends Oaf implements Serializable {
|
||||
|
||||
private String id;
|
||||
|
@ -21,93 +24,132 @@ public abstract class OafEntity extends Oaf implements Serializable {
|
|||
|
||||
private OAIProvenance oaiprovenance;
|
||||
|
||||
/**
|
||||
* Gets id.
|
||||
*
|
||||
* @return the id
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets id.
|
||||
*
|
||||
* @param id the id
|
||||
*/
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets original id.
|
||||
*
|
||||
* @return the original id
|
||||
*/
|
||||
public List<String> getOriginalId() {
|
||||
return originalId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets original id.
|
||||
*
|
||||
* @param originalId the original id
|
||||
*/
|
||||
public void setOriginalId(List<String> originalId) {
|
||||
this.originalId = originalId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets pid.
|
||||
*
|
||||
* @return the pid
|
||||
*/
|
||||
public List<StructuredProperty> getPid() {
|
||||
return pid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets pid.
|
||||
*
|
||||
* @param pid the pid
|
||||
*/
|
||||
public void setPid(List<StructuredProperty> pid) {
|
||||
this.pid = pid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets dateofcollection.
|
||||
*
|
||||
* @return the dateofcollection
|
||||
*/
|
||||
public String getDateofcollection() {
|
||||
return dateofcollection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets dateofcollection.
|
||||
*
|
||||
* @param dateofcollection the dateofcollection
|
||||
*/
|
||||
public void setDateofcollection(String dateofcollection) {
|
||||
this.dateofcollection = dateofcollection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets dateoftransformation.
|
||||
*
|
||||
* @return the dateoftransformation
|
||||
*/
|
||||
public String getDateoftransformation() {
|
||||
return dateoftransformation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets dateoftransformation.
|
||||
*
|
||||
* @param dateoftransformation the dateoftransformation
|
||||
*/
|
||||
public void setDateoftransformation(String dateoftransformation) {
|
||||
this.dateoftransformation = dateoftransformation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets extra info.
|
||||
*
|
||||
* @return the extra info
|
||||
*/
|
||||
public List<ExtraInfo> getExtraInfo() {
|
||||
return extraInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets extra info.
|
||||
*
|
||||
* @param extraInfo the extra info
|
||||
*/
|
||||
public void setExtraInfo(List<ExtraInfo> extraInfo) {
|
||||
this.extraInfo = extraInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets oaiprovenance.
|
||||
*
|
||||
* @return the oaiprovenance
|
||||
*/
|
||||
public OAIProvenance getOaiprovenance() {
|
||||
return oaiprovenance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets oaiprovenance.
|
||||
*
|
||||
* @param oaiprovenance the oaiprovenance
|
||||
*/
|
||||
public void setOaiprovenance(OAIProvenance oaiprovenance) {
|
||||
this.oaiprovenance = oaiprovenance;
|
||||
}
|
||||
|
||||
public void mergeFrom(OafEntity e) {
|
||||
super.mergeFrom(e);
|
||||
|
||||
originalId = mergeLists(originalId, e.getOriginalId());
|
||||
|
||||
pid = mergeLists(pid, e.getPid());
|
||||
|
||||
if (e.getDateofcollection() != null && compareTrust(this, e) < 0)
|
||||
dateofcollection = e.getDateofcollection();
|
||||
|
||||
if (e.getDateoftransformation() != null && compareTrust(this, e) < 0)
|
||||
dateoftransformation = e.getDateoftransformation();
|
||||
|
||||
extraInfo = mergeLists(extraInfo, e.getExtraInfo());
|
||||
|
||||
if (e.getOaiprovenance() != null && compareTrust(this, e) < 0)
|
||||
oaiprovenance = e.getOaiprovenance();
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
protected final <T> List<T> mergeLists(final List<T>... lists) {
|
||||
|
||||
return Arrays
|
||||
.stream(lists)
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap(List::stream)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
|
|
|
@ -167,48 +167,4 @@ public class Organization extends OafEntity implements Serializable {
|
|||
this.country = country;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mergeFrom(OafEntity e) {
|
||||
super.mergeFrom(e);
|
||||
|
||||
if (!Organization.class.isAssignableFrom(e.getClass())) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Organization o = (Organization) e;
|
||||
legalshortname = o.getLegalshortname() != null && compareTrust(this, e) < 0
|
||||
? o.getLegalshortname()
|
||||
: legalshortname;
|
||||
legalname = o.getLegalname() != null && compareTrust(this, e) < 0 ? o.getLegalname() : legalname;
|
||||
alternativeNames = mergeLists(o.getAlternativeNames(), alternativeNames);
|
||||
websiteurl = o.getWebsiteurl() != null && compareTrust(this, e) < 0 ? o.getWebsiteurl() : websiteurl;
|
||||
logourl = o.getLogourl() != null && compareTrust(this, e) < 0 ? o.getLogourl() : logourl;
|
||||
eclegalbody = o.getEclegalbody() != null && compareTrust(this, e) < 0 ? o.getEclegalbody() : eclegalbody;
|
||||
eclegalperson = o.getEclegalperson() != null && compareTrust(this, e) < 0
|
||||
? o.getEclegalperson()
|
||||
: eclegalperson;
|
||||
ecnonprofit = o.getEcnonprofit() != null && compareTrust(this, e) < 0 ? o.getEcnonprofit() : ecnonprofit;
|
||||
ecresearchorganization = o.getEcresearchorganization() != null && compareTrust(this, e) < 0
|
||||
? o.getEcresearchorganization()
|
||||
: ecresearchorganization;
|
||||
echighereducation = o.getEchighereducation() != null && compareTrust(this, e) < 0
|
||||
? o.getEchighereducation()
|
||||
: echighereducation;
|
||||
ecinternationalorganizationeurinterests = o.getEcinternationalorganizationeurinterests() != null
|
||||
&& compareTrust(this, e) < 0
|
||||
? o.getEcinternationalorganizationeurinterests()
|
||||
: ecinternationalorganizationeurinterests;
|
||||
ecinternationalorganization = o.getEcinternationalorganization() != null && compareTrust(this, e) < 0
|
||||
? o.getEcinternationalorganization()
|
||||
: ecinternationalorganization;
|
||||
ecenterprise = o.getEcenterprise() != null && compareTrust(this, e) < 0
|
||||
? o.getEcenterprise()
|
||||
: ecenterprise;
|
||||
ecsmevalidated = o.getEcsmevalidated() != null && compareTrust(this, e) < 0
|
||||
? o.getEcsmevalidated()
|
||||
: ecsmevalidated;
|
||||
ecnutscode = o.getEcnutscode() != null && compareTrust(this, e) < 0 ? o.getEcnutscode() : ecnutscode;
|
||||
country = o.getCountry() != null && compareTrust(this, e) < 0 ? o.getCountry() : country;
|
||||
mergeOAFDataInfo(o);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,19 +42,4 @@ public class OtherResearchProduct extends Result implements Serializable {
|
|||
this.tool = tool;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mergeFrom(OafEntity e) {
|
||||
super.mergeFrom(e);
|
||||
|
||||
if (!OtherResearchProduct.class.isAssignableFrom(e.getClass())) {
|
||||
return;
|
||||
}
|
||||
|
||||
OtherResearchProduct o = (OtherResearchProduct) e;
|
||||
|
||||
contactperson = mergeLists(contactperson, o.getContactperson());
|
||||
contactgroup = mergeLists(contactgroup, o.getContactgroup());
|
||||
tool = mergeLists(tool, o.getTool());
|
||||
mergeOAFDataInfo(e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -298,64 +298,4 @@ public class Project extends OafEntity implements Serializable {
|
|||
this.fundedamount = fundedamount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mergeFrom(OafEntity e) {
|
||||
super.mergeFrom(e);
|
||||
|
||||
if (!Project.class.isAssignableFrom(e.getClass())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Project p = (Project) e;
|
||||
|
||||
websiteurl = p.getWebsiteurl() != null && compareTrust(this, e) < 0 ? p.getWebsiteurl() : websiteurl;
|
||||
code = p.getCode() != null && compareTrust(this, e) < 0 ? p.getCode() : code;
|
||||
acronym = p.getAcronym() != null && compareTrust(this, e) < 0 ? p.getAcronym() : acronym;
|
||||
title = p.getTitle() != null && compareTrust(this, e) < 0 ? p.getTitle() : title;
|
||||
startdate = p.getStartdate() != null && compareTrust(this, e) < 0 ? p.getStartdate() : startdate;
|
||||
enddate = p.getEnddate() != null && compareTrust(this, e) < 0 ? p.getEnddate() : enddate;
|
||||
callidentifier = p.getCallidentifier() != null && compareTrust(this, e) < 0
|
||||
? p.getCallidentifier()
|
||||
: callidentifier;
|
||||
keywords = p.getKeywords() != null && compareTrust(this, e) < 0 ? p.getKeywords() : keywords;
|
||||
duration = p.getDuration() != null && compareTrust(this, e) < 0 ? p.getDuration() : duration;
|
||||
ecsc39 = p.getEcsc39() != null && compareTrust(this, e) < 0 ? p.getEcsc39() : ecsc39;
|
||||
oamandatepublications = p.getOamandatepublications() != null && compareTrust(this, e) < 0
|
||||
? p.getOamandatepublications()
|
||||
: oamandatepublications;
|
||||
ecarticle29_3 = p.getEcarticle29_3() != null && compareTrust(this, e) < 0
|
||||
? p.getEcarticle29_3()
|
||||
: ecarticle29_3;
|
||||
subjects = mergeLists(subjects, p.getSubjects());
|
||||
fundingtree = mergeLists(fundingtree, p.getFundingtree());
|
||||
contracttype = p.getContracttype() != null && compareTrust(this, e) < 0
|
||||
? p.getContracttype()
|
||||
: contracttype;
|
||||
optional1 = p.getOptional1() != null && compareTrust(this, e) < 0 ? p.getOptional1() : optional1;
|
||||
optional2 = p.getOptional2() != null && compareTrust(this, e) < 0 ? p.getOptional2() : optional2;
|
||||
jsonextrainfo = p.getJsonextrainfo() != null && compareTrust(this, e) < 0
|
||||
? p.getJsonextrainfo()
|
||||
: jsonextrainfo;
|
||||
contactfullname = p.getContactfullname() != null && compareTrust(this, e) < 0
|
||||
? p.getContactfullname()
|
||||
: contactfullname;
|
||||
contactfax = p.getContactfax() != null && compareTrust(this, e) < 0 ? p.getContactfax() : contactfax;
|
||||
contactphone = p.getContactphone() != null && compareTrust(this, e) < 0
|
||||
? p.getContactphone()
|
||||
: contactphone;
|
||||
contactemail = p.getContactemail() != null && compareTrust(this, e) < 0
|
||||
? p.getContactemail()
|
||||
: contactemail;
|
||||
summary = p.getSummary() != null && compareTrust(this, e) < 0 ? p.getSummary() : summary;
|
||||
currency = p.getCurrency() != null && compareTrust(this, e) < 0 ? p.getCurrency() : currency;
|
||||
|
||||
if (p.getH2020topiccode() != null && StringUtils.isEmpty(h2020topiccode)){
|
||||
h2020topiccode = p.getH2020topiccode();
|
||||
h2020topicdescription = p.getH2020topicdescription();
|
||||
}
|
||||
|
||||
h2020classification = mergeLists(h2020classification, p.getH2020classification());
|
||||
|
||||
mergeOAFDataInfo(e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,19 +21,4 @@ public class Publication extends Result implements Serializable {
|
|||
public void setJournal(Journal journal) {
|
||||
this.journal = journal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mergeFrom(OafEntity e) {
|
||||
super.mergeFrom(e);
|
||||
|
||||
if (!Publication.class.isAssignableFrom(e.getClass())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Publication p = (Publication) e;
|
||||
|
||||
if (p.getJournal() != null && compareTrust(this, e) < 0)
|
||||
journal = p.getJournal();
|
||||
mergeOAFDataInfo(e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,27 +124,6 @@ public class Relation extends Oaf {
|
|||
this.validationDate = validationDate;
|
||||
}
|
||||
|
||||
public void mergeFrom(final Relation r) {
|
||||
|
||||
checkArgument(Objects.equals(getSource(), r.getSource()), "source ids must be equal");
|
||||
checkArgument(Objects.equals(getTarget(), r.getTarget()), "target ids must be equal");
|
||||
checkArgument(Objects.equals(getRelType(), r.getRelType()), "relType(s) must be equal");
|
||||
checkArgument(
|
||||
Objects.equals(getSubRelType(), r.getSubRelType()), "subRelType(s) must be equal");
|
||||
checkArgument(Objects.equals(getRelClass(), r.getRelClass()), "relClass(es) must be equal");
|
||||
|
||||
setValidated(getValidated() || r.getValidated());
|
||||
try {
|
||||
setValidationDate(ModelSupport.oldest(getValidationDate(), r.getValidationDate()));
|
||||
} catch (ParseException e) {
|
||||
throw new IllegalArgumentException(String
|
||||
.format(
|
||||
"invalid validation date format in relation [s:%s, t:%s]: %s", getSource(), getTarget(),
|
||||
getValidationDate()));
|
||||
}
|
||||
|
||||
super.mergeFrom(r);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
|
|
@ -6,12 +6,9 @@ import java.util.*;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import eu.dnetlib.dhp.schema.common.AccessRightComparator;
|
||||
import eu.dnetlib.dhp.schema.common.ModelConstants;
|
||||
import eu.dnetlib.dhp.schema.oaf.utils.CleaningFunctions;
|
||||
|
||||
/**
|
||||
* The type Result.
|
||||
|
@ -554,331 +551,4 @@ public class Result extends OafEntity implements Serializable {
|
|||
this.instance = instance;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Is an enrichment boolean.
|
||||
*
|
||||
* @param e the e
|
||||
* @return the boolean
|
||||
*/
|
||||
public static boolean isAnEnrichment(OafEntity e) {
|
||||
return e.getDataInfo()!= null &&
|
||||
e.getDataInfo().getProvenanceaction()!= null
|
||||
&& ModelConstants.PROVENANCE_ENRICH.equalsIgnoreCase(e.getDataInfo().getProvenanceaction().getClassid());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Normalize pid string.
|
||||
*
|
||||
* @param pid the pid
|
||||
* @return the string
|
||||
*/
|
||||
private static String extractKeyFromPid(final StructuredProperty pid) {
|
||||
if (pid == null)
|
||||
return null;
|
||||
final StructuredProperty normalizedPid = CleaningFunctions.normalizePidValue(pid);
|
||||
|
||||
return String.format("%s::%s", normalizedPid.getQualifier().getClassid(), normalizedPid.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Valid pid boolean.
|
||||
*
|
||||
* @param p the p
|
||||
* @return the boolean
|
||||
*/
|
||||
private static boolean validPid(final StructuredProperty p) {
|
||||
return p.getValue()!= null && p.getQualifier()!= null && p.getQualifier().getClassid()!=null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method converts the list of instance enrichments
|
||||
* into a Map where the key is the normalized identifier
|
||||
* and the value is the instance itself
|
||||
*
|
||||
* @param ri the list of enrichment instances
|
||||
* @return the result map
|
||||
*/
|
||||
public static Map<String, Instance> toInstanceMap(final List<Instance> ri) {
|
||||
|
||||
|
||||
return ri
|
||||
.stream()
|
||||
.filter(i -> i.getPid() != null || i.getAlternateIdentifier() != null)
|
||||
.flatMap(i -> {
|
||||
final List<Pair<String, Instance>> result = new ArrayList<>();
|
||||
if (i.getPid() != null)
|
||||
i.getPid().stream().filter(Result::validPid).forEach(p -> result.add(new ImmutablePair<>(extractKeyFromPid(p), i)));
|
||||
if (i.getAlternateIdentifier() != null)
|
||||
i.getAlternateIdentifier().stream().filter(Result::validPid).forEach(p -> result.add(new ImmutablePair<>(extractKeyFromPid(p), i)));
|
||||
return result.stream();
|
||||
}).collect(Collectors.toMap(
|
||||
Pair::getLeft,
|
||||
Pair::getRight,
|
||||
(a, b) -> a
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* This utility method finds the list of enrichment instances
|
||||
* that match one or more PIDs in the input list
|
||||
*
|
||||
* @param pids the list of PIDs
|
||||
* @param enrichments the List of enrichment instances having the same pid
|
||||
* @return the list
|
||||
*/
|
||||
private static List<Instance> findEnrichmentsByPID(final List<StructuredProperty> pids, final Map<String,Instance> enrichments) {
|
||||
if (pids == null || enrichments == null)
|
||||
return null;
|
||||
return pids
|
||||
.stream()
|
||||
.map(Result::extractKeyFromPid)
|
||||
.map(enrichments::get)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method apply enrichment on a single instance
|
||||
* The enrichment consists of replacing values on
|
||||
* single attribute only if in the current instance is missing
|
||||
* The only repeatable field enriched is measures
|
||||
*
|
||||
* @param currentInstance the current instance
|
||||
* @param enrichment the enrichment instance
|
||||
*/
|
||||
private static void applyEnrichment(final Instance currentInstance, final Instance enrichment) {
|
||||
if (currentInstance == null || enrichment == null)
|
||||
return;
|
||||
|
||||
//ENRICH accessright
|
||||
if (enrichment.getAccessright()!=null && currentInstance.getAccessright() == null)
|
||||
currentInstance.setAccessright(enrichment.getAccessright());
|
||||
|
||||
//ENRICH license
|
||||
if (enrichment.getLicense()!=null && currentInstance.getLicense() == null)
|
||||
currentInstance.setLicense(enrichment.getLicense());
|
||||
|
||||
//ENRICH instanceType
|
||||
if (enrichment.getInstancetype()!=null && currentInstance.getInstancetype() == null)
|
||||
currentInstance.setInstancetype(enrichment.getInstancetype());
|
||||
|
||||
//ENRICH hostedby
|
||||
if (enrichment.getHostedby()!=null && currentInstance.getHostedby() == null)
|
||||
currentInstance.setHostedby(enrichment.getHostedby());
|
||||
|
||||
//ENRICH distributionlocation
|
||||
if (enrichment.getDistributionlocation()!=null && currentInstance.getDistributionlocation() == null)
|
||||
currentInstance.setDistributionlocation(enrichment.getDistributionlocation());
|
||||
|
||||
//ENRICH collectedfrom
|
||||
if (enrichment.getCollectedfrom()!=null && currentInstance.getCollectedfrom() == null)
|
||||
currentInstance.setCollectedfrom(enrichment.getCollectedfrom());
|
||||
|
||||
//ENRICH dateofacceptance
|
||||
if (enrichment.getDateofacceptance()!=null && currentInstance.getDateofacceptance() == null)
|
||||
currentInstance.setDateofacceptance(enrichment.getDateofacceptance());
|
||||
|
||||
//ENRICH processingchargeamount
|
||||
if (enrichment.getProcessingchargeamount()!=null && currentInstance.getProcessingchargeamount() == null)
|
||||
currentInstance.setProcessingchargeamount(enrichment.getProcessingchargeamount());
|
||||
|
||||
//ENRICH refereed
|
||||
if (enrichment.getRefereed()!=null && currentInstance.getRefereed() == null)
|
||||
currentInstance.setRefereed(enrichment.getRefereed());
|
||||
|
||||
//ENRICH measures
|
||||
if (enrichment.getMeasures()!=null)
|
||||
if (currentInstance.getMeasures() == null)
|
||||
currentInstance.setMeasures(enrichment.getMeasures());
|
||||
else
|
||||
enrichment.getMeasures().forEach(currentInstance.getMeasures()::add);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This main method apply the enrichment of the instances
|
||||
*
|
||||
* @param toEnrichInstances the instances that could be enriched
|
||||
* @param enrichmentInstances the enrichment instances
|
||||
* @return list of instances possibly enriched
|
||||
*/
|
||||
private static List<Instance> enrichInstances(final List<Instance> toEnrichInstances,final List<Instance> enrichmentInstances) {
|
||||
final List<Instance> enrichmentResult = new ArrayList<>();
|
||||
|
||||
if (toEnrichInstances == null) {
|
||||
return enrichmentResult;
|
||||
}
|
||||
if (enrichmentInstances == null) {
|
||||
return enrichmentResult;
|
||||
}
|
||||
Map<String, Instance> ri = toInstanceMap(enrichmentInstances);
|
||||
|
||||
toEnrichInstances.forEach(i -> {
|
||||
final List<Instance> e = findEnrichmentsByPID(i.getPid(), ri);
|
||||
if (e!= null && e.size()> 0) {
|
||||
e.forEach(enr -> applyEnrichment(i, enr));
|
||||
} else {
|
||||
final List<Instance> a = findEnrichmentsByPID(i.getAlternateIdentifier(), ri);
|
||||
if (a!= null && a.size()> 0) {
|
||||
a.forEach(enr -> applyEnrichment(i, enr));
|
||||
}
|
||||
}
|
||||
enrichmentResult.add(i);
|
||||
});
|
||||
return enrichmentResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mergeFrom(OafEntity e) {
|
||||
super.mergeFrom(e);
|
||||
|
||||
if (!Result.class.isAssignableFrom(e.getClass())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Result r = (Result) e;
|
||||
|
||||
if(processingchargeamount == null || StringUtils.isBlank(processingchargeamount.getValue() )){
|
||||
processingchargeamount = r.getProcessingchargeamount();
|
||||
processingchargecurrency = r.getProcessingchargecurrency();
|
||||
}
|
||||
|
||||
measures = mergeLists(measures, r.getMeasures());
|
||||
|
||||
if( !isAnEnrichment(this) && !isAnEnrichment(e))
|
||||
instance = mergeLists(instance, r.getInstance());
|
||||
else {
|
||||
final List<Instance> enrichmentInstances = isAnEnrichment(this) ? instance : r.getInstance();
|
||||
final List<Instance> enrichedInstances= isAnEnrichment(this) ? r.getInstance(): instance;
|
||||
if (isAnEnrichment(this))
|
||||
setDataInfo(e.getDataInfo());
|
||||
instance = enrichInstances(enrichedInstances,enrichmentInstances);
|
||||
}
|
||||
|
||||
if (r.getBestaccessright() != null
|
||||
&& new AccessRightComparator().compare(r.getBestaccessright(), bestaccessright) < 0)
|
||||
bestaccessright = r.getBestaccessright();
|
||||
|
||||
if (r.getResulttype() != null && compareTrust(this, r) < 0)
|
||||
resulttype = r.getResulttype();
|
||||
|
||||
if (r.getLanguage() != null && compareTrust(this, r) < 0)
|
||||
language = r.getLanguage();
|
||||
|
||||
if (Objects.nonNull(r.getDateofacceptance())) {
|
||||
if (Objects.isNull(getDateofacceptance())) {
|
||||
dateofacceptance = r.getDateofacceptance();
|
||||
} else if (compareTrust(this, r) < 0) {
|
||||
dateofacceptance = r.getDateofacceptance();
|
||||
}
|
||||
}
|
||||
|
||||
country = mergeLists(country, r.getCountry());
|
||||
|
||||
subject = mergeLists(subject, r.getSubject());
|
||||
|
||||
// merge title lists: main title with higher trust and distinct between the others
|
||||
StructuredProperty baseMainTitle = null;
|
||||
if (title != null) {
|
||||
baseMainTitle = getMainTitle(title);
|
||||
if (baseMainTitle != null) {
|
||||
final StructuredProperty p = baseMainTitle;
|
||||
title = title.stream().filter(t -> t != p).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
StructuredProperty newMainTitle = null;
|
||||
if (r.getTitle() != null) {
|
||||
newMainTitle = getMainTitle(r.getTitle());
|
||||
if (newMainTitle != null) {
|
||||
final StructuredProperty p = newMainTitle;
|
||||
r.setTitle(r.getTitle().stream().filter(t -> t != p).collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
|
||||
if (newMainTitle != null && compareTrust(this, r) < 0) {
|
||||
baseMainTitle = newMainTitle;
|
||||
}
|
||||
|
||||
title = mergeLists(title, r.getTitle());
|
||||
if (title != null && baseMainTitle != null) {
|
||||
title.add(baseMainTitle);
|
||||
}
|
||||
|
||||
relevantdate = mergeLists(relevantdate, r.getRelevantdate());
|
||||
|
||||
description = longestLists(description, r.getDescription());
|
||||
|
||||
if (r.getPublisher() != null && compareTrust(this, r) < 0)
|
||||
publisher = r.getPublisher();
|
||||
|
||||
if (r.getEmbargoenddate() != null && compareTrust(this, r) < 0)
|
||||
embargoenddate = r.getEmbargoenddate();
|
||||
|
||||
source = mergeLists(source, r.getSource());
|
||||
|
||||
fulltext = mergeLists(fulltext, r.getFulltext());
|
||||
|
||||
format = mergeLists(format, r.getFormat());
|
||||
|
||||
contributor = mergeLists(contributor, r.getContributor());
|
||||
|
||||
if (r.getResourcetype() != null)
|
||||
resourcetype = r.getResourcetype();
|
||||
|
||||
coverage = mergeLists(coverage, r.getCoverage());
|
||||
|
||||
context = mergeLists(context, r.getContext());
|
||||
|
||||
externalReference = mergeLists(externalReference, r.getExternalReference());
|
||||
}
|
||||
|
||||
/**
|
||||
* Longest lists list.
|
||||
*
|
||||
* @param a the a
|
||||
* @param b the b
|
||||
* @return the list
|
||||
*/
|
||||
private List<Field<String>> longestLists(List<Field<String>> a, List<Field<String>> b) {
|
||||
if (a == null || b == null)
|
||||
return a == null ? b : a;
|
||||
if (a.size() == b.size()) {
|
||||
int msa = a
|
||||
.stream()
|
||||
.filter(i -> i != null && i.getValue() != null)
|
||||
.map(i -> i.getValue().length())
|
||||
.max(Comparator.naturalOrder())
|
||||
.orElse(0);
|
||||
int msb = b
|
||||
.stream()
|
||||
.filter(i -> i != null && i.getValue() != null)
|
||||
.map(i -> i.getValue().length())
|
||||
.max(Comparator.naturalOrder())
|
||||
.orElse(0);
|
||||
return msa > msb ? a : b;
|
||||
}
|
||||
return a.size() > b.size() ? a : b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets main title.
|
||||
*
|
||||
* @param titles the titles
|
||||
* @return the main title
|
||||
*/
|
||||
private StructuredProperty getMainTitle(List<StructuredProperty> titles) {
|
||||
// need to check if the list of titles contains more than 1 main title? (in that case, we should chose which
|
||||
// main title select in the list)
|
||||
for (StructuredProperty t : titles) {
|
||||
if (t.getQualifier() != null && t.getQualifier().getClassid() != null)
|
||||
if (t.getQualifier().getClassid().equals("main title"))
|
||||
return t;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,28 +53,4 @@ public class Software extends Result implements Serializable {
|
|||
public void setProgrammingLanguage(Qualifier programmingLanguage) {
|
||||
this.programmingLanguage = programmingLanguage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mergeFrom(OafEntity e) {
|
||||
super.mergeFrom(e);
|
||||
|
||||
if (!Software.class.isAssignableFrom(e.getClass())) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Software s = (Software) e;
|
||||
documentationUrl = mergeLists(documentationUrl, s.getDocumentationUrl());
|
||||
|
||||
license = mergeLists(license, s.getLicense());
|
||||
|
||||
codeRepositoryUrl = s.getCodeRepositoryUrl() != null && compareTrust(this, s) < 0
|
||||
? s.getCodeRepositoryUrl()
|
||||
: codeRepositoryUrl;
|
||||
|
||||
programmingLanguage = s.getProgrammingLanguage() != null && compareTrust(this, s) < 0
|
||||
? s.getProgrammingLanguage()
|
||||
: programmingLanguage;
|
||||
|
||||
mergeOAFDataInfo(e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,74 +0,0 @@
|
|||
|
||||
package eu.dnetlib.dhp.schema.oaf.utils;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import eu.dnetlib.dhp.schema.oaf.StructuredProperty;
|
||||
|
||||
public class CleaningFunctions {
|
||||
|
||||
public static final String DOI_PREFIX_REGEX = "(^10\\.|\\/10\\.)";
|
||||
public static final String DOI_PREFIX = "10.";
|
||||
|
||||
public static final Set<String> PID_BLACKLIST = new HashSet<>();
|
||||
|
||||
static {
|
||||
PID_BLACKLIST.add("none");
|
||||
PID_BLACKLIST.add("na");
|
||||
}
|
||||
|
||||
public CleaningFunctions() {}
|
||||
|
||||
/**
|
||||
* Utility method that filter PID values on a per-type basis.
|
||||
* @param s the PID whose value will be checked.
|
||||
* @return false if the pid matches the filter criteria, true otherwise.
|
||||
*/
|
||||
public static boolean pidFilter(StructuredProperty s) {
|
||||
final String pidValue = s.getValue();
|
||||
if (Objects.isNull(s.getQualifier()) ||
|
||||
StringUtils.isBlank(pidValue) ||
|
||||
StringUtils.isBlank(pidValue.replaceAll("(?:\\n|\\r|\\t|\\s)", ""))) {
|
||||
return false;
|
||||
}
|
||||
if (CleaningFunctions.PID_BLACKLIST.contains(pidValue)) {
|
||||
return false;
|
||||
}
|
||||
return !PidBlacklistProvider.getBlacklist(s.getQualifier().getClassid()).contains(pidValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method that normalises PID values on a per-type basis.
|
||||
* @param pid the PID whose value will be normalised.
|
||||
* @return the PID containing the normalised value.
|
||||
*/
|
||||
public static StructuredProperty normalizePidValue(StructuredProperty pid) {
|
||||
pid.setValue(
|
||||
normalizePidValue(
|
||||
pid.getQualifier().getClassid(),
|
||||
pid.getValue()));
|
||||
|
||||
return pid;
|
||||
}
|
||||
|
||||
public static String normalizePidValue(String pidType, String pidValue) {
|
||||
String value = Optional
|
||||
.ofNullable(pidValue)
|
||||
.map(String::trim)
|
||||
.orElseThrow(() -> new IllegalArgumentException("PID value cannot be empty"));
|
||||
|
||||
switch (pidType) {
|
||||
|
||||
// TODO add cleaning for more PID types as needed
|
||||
case "doi":
|
||||
return value.toLowerCase().replaceFirst(DOI_PREFIX_REGEX, DOI_PREFIX);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,283 +0,0 @@
|
|||
|
||||
package eu.dnetlib.dhp.schema.oaf.utils;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static eu.dnetlib.dhp.schema.common.ModelConstants.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import eu.dnetlib.dhp.schema.common.ModelSupport;
|
||||
import eu.dnetlib.dhp.schema.oaf.*;
|
||||
|
||||
/**
|
||||
* Factory class for OpenAIRE identifiers in the Graph
|
||||
*/
|
||||
public class IdentifierFactory implements Serializable {
|
||||
|
||||
public static final String ID_SEPARATOR = "::";
|
||||
public static final String ID_PREFIX_SEPARATOR = "|";
|
||||
|
||||
public static final int ID_PREFIX_LEN = 12;
|
||||
|
||||
/**
|
||||
* Declares the associations PID_TYPE -> [DATASOURCE ID, NAME] considered authoritative for that PID_TYPE
|
||||
*/
|
||||
public static final Map<PidType, HashBiMap<String, String>> PID_AUTHORITY = Maps.newHashMap();
|
||||
|
||||
static {
|
||||
PID_AUTHORITY.put(PidType.doi, HashBiMap.create());
|
||||
PID_AUTHORITY.get(PidType.doi).put(CROSSREF_ID, "Crossref");
|
||||
PID_AUTHORITY.get(PidType.doi).put(DATACITE_ID, "Datacite");
|
||||
PID_AUTHORITY.get(PidType.doi).put(ZENODO_OD_ID, "ZENODO");
|
||||
PID_AUTHORITY.get(PidType.doi).put(ZENODO_R3_ID, "Zenodo");
|
||||
|
||||
PID_AUTHORITY.put(PidType.pmc, HashBiMap.create());
|
||||
PID_AUTHORITY.get(PidType.pmc).put(EUROPE_PUBMED_CENTRAL_ID, "Europe PubMed Central");
|
||||
PID_AUTHORITY.get(PidType.pmc).put(PUBMED_CENTRAL_ID, "PubMed Central");
|
||||
|
||||
PID_AUTHORITY.put(PidType.pmid, HashBiMap.create());
|
||||
PID_AUTHORITY.get(PidType.pmid).put(EUROPE_PUBMED_CENTRAL_ID, "Europe PubMed Central");
|
||||
PID_AUTHORITY.get(PidType.pmid).put(PUBMED_CENTRAL_ID, "PubMed Central");
|
||||
|
||||
PID_AUTHORITY.put(PidType.arXiv, HashBiMap.create());
|
||||
PID_AUTHORITY.get(PidType.arXiv).put(ARXIV_ID, "arXiv.org e-Print Archive");
|
||||
}
|
||||
|
||||
/**
|
||||
* Declares the associations PID_TYPE -> [DATASOURCE ID, PID SUBSTRING] considered as delegated authority for that
|
||||
* PID_TYPE. Example, Zenodo is delegated to forge DOIs that contain the 'zenodo' word.
|
||||
*/
|
||||
public static final Map<PidType, Map<String, String>> DELEGATED_PID_AUTHORITY = Maps.newHashMap();
|
||||
|
||||
static {
|
||||
DELEGATED_PID_AUTHORITY.put(PidType.doi, new HashMap<>());
|
||||
DELEGATED_PID_AUTHORITY.get(PidType.doi).put(ZENODO_OD_ID, "zenodo");
|
||||
DELEGATED_PID_AUTHORITY.get(PidType.doi).put(ZENODO_R3_ID, "zenodo");
|
||||
}
|
||||
|
||||
/**
|
||||
* Declares the associations PID_TYPE -> [DATASOURCE ID, NAME] whose records are considered enrichment for the graph.
|
||||
* Their OpenAIRE ID is built from the declared PID type. Are merged with their corresponding record, identified by
|
||||
* the same OpenAIRE id.
|
||||
*/
|
||||
public static final Map<PidType, HashBiMap<String, String>> ENRICHMENT_PROVIDER = Maps.newHashMap();
|
||||
|
||||
static {
|
||||
ENRICHMENT_PROVIDER.put(PidType.doi, HashBiMap.create());
|
||||
ENRICHMENT_PROVIDER.get(PidType.doi).put(OPEN_APC_ID, OPEN_APC_NAME);
|
||||
}
|
||||
|
||||
public static Set<String> delegatedAuthorityDatasourceIds() {
|
||||
return DELEGATED_PID_AUTHORITY.values()
|
||||
.stream()
|
||||
.flatMap(m -> m.keySet().stream())
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
}
|
||||
|
||||
public static List<StructuredProperty> getPids(List<StructuredProperty> pid, KeyValue collectedFrom) {
|
||||
return pidFromInstance(pid, collectedFrom, true).distinct().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static <T extends Result> String createDOIBoostIdentifier(T entity) {
|
||||
if (entity == null)
|
||||
return null;
|
||||
|
||||
StructuredProperty pid = null;
|
||||
if (entity.getPid() != null) {
|
||||
pid = entity
|
||||
.getPid()
|
||||
.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.filter(s -> s.getQualifier() != null && "doi".equalsIgnoreCase(s.getQualifier().getClassid()))
|
||||
.filter(CleaningFunctions::pidFilter)
|
||||
.findAny()
|
||||
.orElse(null);
|
||||
} else {
|
||||
if (entity.getInstance() != null) {
|
||||
pid = entity
|
||||
.getInstance()
|
||||
.stream()
|
||||
.filter(i -> i.getPid() != null)
|
||||
.flatMap(i -> i.getPid().stream())
|
||||
.filter(CleaningFunctions::pidFilter)
|
||||
.findAny()
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
if (pid != null)
|
||||
return idFromPid(entity, pid, true);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an identifier from the most relevant PID (if available) provided by a known PID authority in the given
|
||||
* entity T. Returns entity.id when none of the PIDs meet the selection criteria is available.
|
||||
*
|
||||
* @param entity the entity providing PIDs and a default ID.
|
||||
* @param <T> the specific entity type. Currently Organization and Result subclasses are supported.
|
||||
* @param md5 indicates whether should hash the PID value or not.
|
||||
* @return an identifier from the most relevant PID, entity.id otherwise
|
||||
*/
|
||||
public static <T extends OafEntity> String createIdentifier(T entity, boolean md5) {
|
||||
|
||||
checkArgument(StringUtils.isNoneBlank(entity.getId()), "missing entity identifier");
|
||||
|
||||
final Map<String, Set<StructuredProperty>> pids = extractPids(entity);
|
||||
|
||||
return pids
|
||||
.values()
|
||||
.stream()
|
||||
.flatMap(Set::stream)
|
||||
.min(new PidComparator<>(entity))
|
||||
.map(
|
||||
min -> Optional
|
||||
.ofNullable(pids.get(min.getQualifier().getClassid()))
|
||||
.map(
|
||||
p -> p
|
||||
.stream()
|
||||
.sorted(new PidValueComparator())
|
||||
.findFirst()
|
||||
.map(s -> idFromPid(entity, s, md5))
|
||||
.orElseGet(entity::getId))
|
||||
.orElseGet(entity::getId))
|
||||
.orElseGet(entity::getId);
|
||||
}
|
||||
|
||||
private static <T extends OafEntity> Map<String, Set<StructuredProperty>> extractPids(T entity) {
|
||||
if (entity instanceof Result) {
|
||||
return Optional
|
||||
.ofNullable(((Result) entity).getInstance())
|
||||
.map(IdentifierFactory::mapPids)
|
||||
.orElse(new HashMap<>());
|
||||
} else {
|
||||
return entity
|
||||
.getPid()
|
||||
.stream()
|
||||
.map(CleaningFunctions::normalizePidValue)
|
||||
.filter(CleaningFunctions::pidFilter)
|
||||
.collect(
|
||||
Collectors
|
||||
.groupingBy(
|
||||
p -> p.getQualifier().getClassid(),
|
||||
Collectors.mapping(p -> p, Collectors.toCollection(HashSet::new))));
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<String, Set<StructuredProperty>> mapPids(List<Instance> instance) {
|
||||
return instance
|
||||
.stream()
|
||||
.map(i -> pidFromInstance(i.getPid(), i.getCollectedfrom(), false))
|
||||
.flatMap(Function.identity())
|
||||
.collect(
|
||||
Collectors
|
||||
.groupingBy(
|
||||
p -> p.getQualifier().getClassid(),
|
||||
Collectors.mapping(p -> p, Collectors.toCollection(HashSet::new))));
|
||||
}
|
||||
|
||||
private static Stream<StructuredProperty> pidFromInstance(List<StructuredProperty> pid, KeyValue collectedFrom,
|
||||
boolean mapHandles) {
|
||||
return Optional
|
||||
.ofNullable(pid)
|
||||
.map(
|
||||
pp -> pp
|
||||
.stream()
|
||||
// filter away PIDs provided by a DS that is not considered an authority for the
|
||||
// given PID Type
|
||||
.filter(p -> shouldFilterPidByCriteria(collectedFrom, p, mapHandles))
|
||||
.map(CleaningFunctions::normalizePidValue)
|
||||
.filter(p -> isNotFromDelegatedAuthority(collectedFrom, p))
|
||||
.filter(CleaningFunctions::pidFilter))
|
||||
.orElse(Stream.empty());
|
||||
}
|
||||
|
||||
|
||||
private static boolean shouldFilterPidByCriteria(KeyValue collectedFrom, StructuredProperty p, boolean mapHandles) {
|
||||
final PidType pType = PidType.tryValueOf(p.getQualifier().getClassid());
|
||||
|
||||
if (Objects.isNull(collectedFrom)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean isEnrich = Optional
|
||||
.ofNullable(ENRICHMENT_PROVIDER.get(pType))
|
||||
.map(enrich -> enrich.containsKey(collectedFrom.getKey())
|
||||
|| enrich.containsValue(collectedFrom.getValue()))
|
||||
.orElse(false);
|
||||
|
||||
boolean isAuthority = Optional
|
||||
.ofNullable(PID_AUTHORITY.get(pType))
|
||||
.map(authorities -> authorities.containsKey(collectedFrom.getKey())
|
||||
|| authorities.containsValue(collectedFrom.getValue()))
|
||||
.orElse(false);
|
||||
|
||||
return (mapHandles && pType.equals(PidType.handle)) || isEnrich || isAuthority;
|
||||
}
|
||||
|
||||
private static boolean isNotFromDelegatedAuthority(KeyValue collectedFrom, StructuredProperty p) {
|
||||
final PidType pType = PidType.tryValueOf(p.getQualifier().getClassid());
|
||||
|
||||
final Map<String, String> da = DELEGATED_PID_AUTHORITY.get(pType);
|
||||
if (Objects.isNull(da)) {
|
||||
return true;
|
||||
}
|
||||
if (!da.containsKey(collectedFrom.getKey())) {
|
||||
return true;
|
||||
}
|
||||
return StringUtils.contains(p.getValue(), da.get(collectedFrom.getKey()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see {@link IdentifierFactory#createIdentifier(OafEntity, boolean)}
|
||||
*/
|
||||
public static <T extends OafEntity> String createIdentifier(T entity) {
|
||||
|
||||
return createIdentifier(entity, true);
|
||||
}
|
||||
|
||||
private static <T extends OafEntity> String idFromPid(T entity, StructuredProperty s, boolean md5) {
|
||||
return idFromPid(ModelSupport.getIdPrefix(entity.getClass()), s.getQualifier().getClassid(), s.getValue(), md5);
|
||||
}
|
||||
|
||||
public static String idFromPid(String numericPrefix, String pidType, String pidValue, boolean md5) {
|
||||
return new StringBuilder()
|
||||
.append(numericPrefix)
|
||||
.append(ID_PREFIX_SEPARATOR)
|
||||
.append(createPrefix(pidType))
|
||||
.append(ID_SEPARATOR)
|
||||
.append(md5 ? md5(pidValue) : pidValue)
|
||||
.toString();
|
||||
}
|
||||
|
||||
// create the prefix (length = 12)
|
||||
private static String createPrefix(String pidType) {
|
||||
StringBuilder prefix = new StringBuilder(StringUtils.left(pidType, ID_PREFIX_LEN));
|
||||
while (prefix.length() < ID_PREFIX_LEN) {
|
||||
prefix.append("_");
|
||||
}
|
||||
return prefix.substring(0, ID_PREFIX_LEN);
|
||||
}
|
||||
|
||||
public static String md5(final String s) {
|
||||
try {
|
||||
final MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
md.update(s.getBytes(StandardCharsets.UTF_8));
|
||||
return new String(Hex.encodeHex(md.digest()));
|
||||
} catch (final Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
|
||||
package eu.dnetlib.dhp.schema.oaf.utils;
|
||||
|
||||
public class ModelHardLimits {
|
||||
|
||||
private ModelHardLimits() {}
|
||||
|
||||
public static final String LAYOUT = "index";
|
||||
public static final String INTERPRETATION = "openaire";
|
||||
public static final String SEPARATOR = "-";
|
||||
|
||||
public static final int MAX_EXTERNAL_ENTITIES = 50;
|
||||
public static final int MAX_AUTHORS = 200;
|
||||
public static final int MAX_AUTHOR_FULLNAME_LENGTH = 1000;
|
||||
public static final int MAX_TITLE_LENGTH = 5000;
|
||||
public static final int MAX_TITLES = 10;
|
||||
public static final int MAX_ABSTRACT_LENGTH = 150000;
|
||||
public static final int MAX_INSTANCES = 10;
|
||||
|
||||
public static String getCollectionName(String format) {
|
||||
return format + SEPARATOR + LAYOUT + SEPARATOR + INTERPRETATION;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
|
||||
package eu.dnetlib.dhp.schema.oaf.utils;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import eu.dnetlib.dhp.schema.oaf.StructuredProperty;
|
||||
|
||||
public class OrganizationPidComparator implements Comparator<StructuredProperty> {
|
||||
|
||||
@Override
|
||||
public int compare(StructuredProperty left, StructuredProperty right) {
|
||||
|
||||
PidType lClass = PidType.tryValueOf(left.getQualifier().getClassid());
|
||||
PidType rClass = PidType.tryValueOf(right.getQualifier().getClassid());
|
||||
|
||||
if (lClass.equals(PidType.openorgs))
|
||||
return -1;
|
||||
if (rClass.equals(PidType.openorgs))
|
||||
return 1;
|
||||
|
||||
if (lClass.equals(PidType.GRID))
|
||||
return -1;
|
||||
if (rClass.equals(PidType.GRID))
|
||||
return 1;
|
||||
|
||||
if (lClass.equals(PidType.mag_id))
|
||||
return -1;
|
||||
if (rClass.equals(PidType.mag_id))
|
||||
return 1;
|
||||
|
||||
if (lClass.equals(PidType.urn))
|
||||
return -1;
|
||||
if (rClass.equals(PidType.urn))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
|
||||
package eu.dnetlib.dhp.schema.oaf.utils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class PidBlacklist extends HashMap<String, HashSet<String>> {
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
|
||||
package eu.dnetlib.dhp.schema.oaf.utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
public class PidBlacklistProvider {
|
||||
|
||||
private static final PidBlacklist blacklist;
|
||||
|
||||
static {
|
||||
try {
|
||||
String json = IOUtils.toString(IdentifierFactory.class.getResourceAsStream("pid_blacklist.json"));
|
||||
blacklist = new ObjectMapper().readValue(json, PidBlacklist.class);
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static PidBlacklist getBlacklist() {
|
||||
return blacklist;
|
||||
}
|
||||
|
||||
public static Set<String> getBlacklist(String pidType) {
|
||||
return Optional
|
||||
.ofNullable(getBlacklist().get(pidType))
|
||||
.orElse(new HashSet<>());
|
||||
}
|
||||
|
||||
private PidBlacklistProvider() {}
|
||||
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
|
||||
package eu.dnetlib.dhp.schema.oaf.utils;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import eu.dnetlib.dhp.schema.common.ModelSupport;
|
||||
import eu.dnetlib.dhp.schema.oaf.OafEntity;
|
||||
import eu.dnetlib.dhp.schema.oaf.Organization;
|
||||
import eu.dnetlib.dhp.schema.oaf.Result;
|
||||
import eu.dnetlib.dhp.schema.oaf.StructuredProperty;
|
||||
|
||||
public class PidComparator<T extends OafEntity> implements Comparator<StructuredProperty> {
|
||||
|
||||
private final T entity;
|
||||
|
||||
public PidComparator(T entity) {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(StructuredProperty left, StructuredProperty right) {
|
||||
|
||||
if (left == null && right == null)
|
||||
return 0;
|
||||
if (left == null)
|
||||
return 1;
|
||||
if (right == null)
|
||||
return -1;
|
||||
|
||||
if (ModelSupport.isSubClass(entity, Result.class)) {
|
||||
return compareResultPids(left, right);
|
||||
}
|
||||
if (ModelSupport.isSubClass(entity, Organization.class)) {
|
||||
return compareOrganizationtPids(left, right);
|
||||
}
|
||||
|
||||
// Else (but unlikely), lexicographical ordering will do.
|
||||
return left.getQualifier().getClassid().compareTo(right.getQualifier().getClassid());
|
||||
}
|
||||
|
||||
private int compareResultPids(StructuredProperty left, StructuredProperty right) {
|
||||
return new ResultPidComparator().compare(left, right);
|
||||
}
|
||||
|
||||
private int compareOrganizationtPids(StructuredProperty left, StructuredProperty right) {
|
||||
return new OrganizationPidComparator().compare(left, right);
|
||||
}
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
|
||||
package eu.dnetlib.dhp.schema.oaf.utils;
|
||||
|
||||
import org.apache.commons.lang3.EnumUtils;
|
||||
|
||||
public enum PidType {
|
||||
|
||||
/**
|
||||
* The DOI syntax shall be made up of a DOI prefix and a DOI suffix separated by a forward slash.
|
||||
*
|
||||
* There is no defined limit on the length of the DOI name, or of the DOI prefix or DOI suffix.
|
||||
*
|
||||
* The DOI name is case-insensitive and can incorporate any printable characters from the legal graphic characters
|
||||
* of Unicode. Further constraints on character use (e.g. use of language-specific alphanumeric characters) can be
|
||||
* defined for an application by the ISO 26324 Registration Authority.
|
||||
*
|
||||
*
|
||||
* DOI prefix: The DOI prefix shall be composed of a directory indicator followed by a registrant code.
|
||||
* These two components shall be separated by a full stop (period). The directory indicator shall be "10" and
|
||||
* distinguishes the entire set of character strings (prefix and suffix) as digital object identifiers within the
|
||||
* resolution system.
|
||||
*
|
||||
* Registrant code: The second element of the DOI prefix shall be the registrant code. The registrant code is a
|
||||
* unique string assigned to a registrant.
|
||||
*
|
||||
* DOI suffix: The DOI suffix shall consist of a character string of any length chosen by the registrant.
|
||||
* Each suffix shall be unique to the prefix element that precedes it. The unique suffix can be a sequential number,
|
||||
* or it might incorporate an identifier generated from or based on another system used by the registrant
|
||||
* (e.g. ISAN, ISBN, ISRC, ISSN, ISTC, ISNI; in such cases, a preferred construction for such a suffix can be
|
||||
* specified, as in Example 1).
|
||||
*
|
||||
* Source: https://www.doi.org/doi_handbook/2_Numbering.html#2.2
|
||||
*/
|
||||
doi,
|
||||
|
||||
/**
|
||||
* PubMed Unique Identifier (PMID)
|
||||
*
|
||||
* This field is a 1-to-8 digit accession number with no leading zeros. It is present on all records and is the
|
||||
* accession number for managing and disseminating records. PMIDs are not reused after records are deleted.
|
||||
*
|
||||
* Beginning in February 2012 PMIDs include extensions following a decimal point to account for article versions
|
||||
* (e.g., 21804956.2). All citations are considered version 1 until replaced. The extended PMID is not displayed
|
||||
* on the MEDLINE format.
|
||||
*
|
||||
* View the citation in abstract format in PubMed to access additional versions when available (see the article in
|
||||
* the Jan-Feb 2012 NLM Technical Bulletin).
|
||||
*
|
||||
* Source: https://www.nlm.nih.gov/bsd/mms/medlineelements.html#pmid
|
||||
*/
|
||||
pmid,
|
||||
|
||||
/**
|
||||
* This field contains the unique identifier for the cited article in PubMed Central. The identifier begins with the
|
||||
* prefix PMC.
|
||||
*
|
||||
* Source: https://www.nlm.nih.gov/bsd/mms/medlineelements.html#pmc
|
||||
*/
|
||||
pmc, handle, arXiv, nct, pdb,
|
||||
|
||||
// Organization
|
||||
openorgs, corda, corda_h2020, GRID, mag_id, urn,
|
||||
|
||||
// Used by dedup
|
||||
undefined, original;
|
||||
|
||||
public static boolean isValid(String type) {
|
||||
return EnumUtils.isValidEnum(PidType.class, type);
|
||||
}
|
||||
|
||||
public static PidType tryValueOf(String s) {
|
||||
try {
|
||||
return PidType.valueOf(s);
|
||||
} catch (Exception e) {
|
||||
return PidType.original;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
|
||||
package eu.dnetlib.dhp.schema.oaf.utils;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.Optional;
|
||||
|
||||
import eu.dnetlib.dhp.schema.oaf.StructuredProperty;
|
||||
|
||||
public class PidValueComparator implements Comparator<StructuredProperty> {
|
||||
|
||||
@Override
|
||||
public int compare(StructuredProperty left, StructuredProperty right) {
|
||||
|
||||
if (left == null && right == null)
|
||||
return 0;
|
||||
if (left == null)
|
||||
return 1;
|
||||
if (right == null)
|
||||
return -1;
|
||||
|
||||
StructuredProperty l = CleaningFunctions.normalizePidValue(left);
|
||||
StructuredProperty r = CleaningFunctions.normalizePidValue(right);
|
||||
|
||||
return Optional
|
||||
.ofNullable(l.getValue())
|
||||
.map(
|
||||
lv -> Optional
|
||||
.ofNullable(r.getValue())
|
||||
.map(rv -> lv.compareTo(rv))
|
||||
.orElse(-1))
|
||||
.orElse(1);
|
||||
}
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
|
||||
package eu.dnetlib.dhp.schema.oaf.utils;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import eu.dnetlib.dhp.schema.oaf.StructuredProperty;
|
||||
|
||||
public class ResultPidComparator implements Comparator<StructuredProperty> {
|
||||
|
||||
@Override
|
||||
public int compare(StructuredProperty left, StructuredProperty right) {
|
||||
|
||||
PidType lClass = PidType.tryValueOf(left.getQualifier().getClassid());
|
||||
PidType rClass = PidType.tryValueOf(right.getQualifier().getClassid());
|
||||
|
||||
if (lClass.equals(PidType.doi))
|
||||
return -1;
|
||||
if (rClass.equals(PidType.doi))
|
||||
return 1;
|
||||
|
||||
if (lClass.equals(PidType.pmid))
|
||||
return -1;
|
||||
if (rClass.equals(PidType.pmid))
|
||||
return 1;
|
||||
|
||||
if (lClass.equals(PidType.pmc))
|
||||
return -1;
|
||||
if (rClass.equals(PidType.pmc))
|
||||
return 1;
|
||||
|
||||
if (lClass.equals(PidType.handle))
|
||||
return -1;
|
||||
if (rClass.equals(PidType.handle))
|
||||
return 1;
|
||||
|
||||
if (lClass.equals(PidType.arXiv))
|
||||
return -1;
|
||||
if (rClass.equals(PidType.arXiv))
|
||||
return 1;
|
||||
|
||||
if (lClass.equals(PidType.nct))
|
||||
return -1;
|
||||
if (rClass.equals(PidType.nct))
|
||||
return 1;
|
||||
|
||||
if (lClass.equals(PidType.pdb))
|
||||
return -1;
|
||||
if (rClass.equals(PidType.pdb))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
|
||||
package eu.dnetlib.dhp.schema.oaf.utils;
|
||||
|
||||
import static eu.dnetlib.dhp.schema.common.ModelConstants.CROSSREF_ID;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import eu.dnetlib.dhp.schema.common.ModelConstants;
|
||||
import eu.dnetlib.dhp.schema.oaf.KeyValue;
|
||||
import eu.dnetlib.dhp.schema.oaf.Result;
|
||||
|
||||
public class ResultTypeComparator implements Comparator<Result> {
|
||||
|
||||
@Override
|
||||
public int compare(Result left, Result right) {
|
||||
|
||||
if (left == null && right == null)
|
||||
return 0;
|
||||
if (left == null)
|
||||
return 1;
|
||||
if (right == null)
|
||||
return -1;
|
||||
|
||||
HashSet<String> lCf = getCollectedFromIds(left);
|
||||
HashSet<String> rCf = getCollectedFromIds(right);
|
||||
|
||||
if (lCf.contains(CROSSREF_ID) && !rCf.contains(CROSSREF_ID)) {
|
||||
return -1;
|
||||
}
|
||||
if (!lCf.contains(CROSSREF_ID) && rCf.contains(CROSSREF_ID)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
String lClass = left.getResulttype().getClassid();
|
||||
String rClass = right.getResulttype().getClassid();
|
||||
|
||||
if (lClass.equals(rClass))
|
||||
return 0;
|
||||
|
||||
if (lClass.equals(ModelConstants.PUBLICATION_RESULTTYPE_CLASSID))
|
||||
return -1;
|
||||
if (rClass.equals(ModelConstants.PUBLICATION_RESULTTYPE_CLASSID))
|
||||
return 1;
|
||||
|
||||
if (lClass.equals(ModelConstants.DATASET_RESULTTYPE_CLASSID))
|
||||
return -1;
|
||||
if (rClass.equals(ModelConstants.DATASET_RESULTTYPE_CLASSID))
|
||||
return 1;
|
||||
|
||||
if (lClass.equals(ModelConstants.SOFTWARE_RESULTTYPE_CLASSID))
|
||||
return -1;
|
||||
if (rClass.equals(ModelConstants.SOFTWARE_RESULTTYPE_CLASSID))
|
||||
return 1;
|
||||
|
||||
if (lClass.equals(ModelConstants.ORP_RESULTTYPE_CLASSID))
|
||||
return -1;
|
||||
if (rClass.equals(ModelConstants.ORP_RESULTTYPE_CLASSID))
|
||||
return 1;
|
||||
|
||||
// Else (but unlikely), lexicographical ordering will do.
|
||||
return lClass.compareTo(rClass);
|
||||
}
|
||||
|
||||
protected HashSet<String> getCollectedFromIds(Result left) {
|
||||
return Optional
|
||||
.ofNullable(left.getCollectedfrom())
|
||||
.map(
|
||||
cf -> cf
|
||||
.stream()
|
||||
.map(KeyValue::getKey)
|
||||
.collect(Collectors.toCollection(HashSet::new)))
|
||||
.orElse(new HashSet<>());
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
|
||||
package eu.dnetlib.dhp.schema.oaf;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
class MeasureTest {
|
||||
|
||||
public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper()
|
||||
.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
|
||||
@Test
|
||||
void testMeasureSerialization() throws IOException {
|
||||
|
||||
Measure popularity = new Measure();
|
||||
popularity.setId("popularity");
|
||||
popularity
|
||||
.setUnit(
|
||||
Lists
|
||||
.newArrayList(
|
||||
unit("score", "0.5")));
|
||||
|
||||
Measure influence = new Measure();
|
||||
influence.setId("influence");
|
||||
influence
|
||||
.setUnit(
|
||||
Lists
|
||||
.newArrayList(
|
||||
unit("score", "0.3")));
|
||||
|
||||
List<Measure> m = Lists.newArrayList(popularity, influence);
|
||||
|
||||
String s = OBJECT_MAPPER.writeValueAsString(m);
|
||||
System.out.println(s);
|
||||
|
||||
List<Measure> mm = OBJECT_MAPPER.readValue(s, new TypeReference<List<Measure>>() {
|
||||
});
|
||||
|
||||
Assertions.assertNotNull(mm);
|
||||
}
|
||||
|
||||
private KeyValue unit(String key, String value) {
|
||||
KeyValue unit = new KeyValue();
|
||||
unit.setKey(key);
|
||||
unit.setValue(value);
|
||||
return unit;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,614 +0,0 @@
|
|||
|
||||
package eu.dnetlib.dhp.schema.oaf;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
/**
|
||||
* The type Merge test.
|
||||
*/
|
||||
class MergeTest {
|
||||
|
||||
/**
|
||||
* The Oaf.
|
||||
*/
|
||||
OafEntity oaf;
|
||||
|
||||
/**
|
||||
* Sets up.
|
||||
*/
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
oaf = new Publication();
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge lists test.
|
||||
*/
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void mergeListsTest() {
|
||||
|
||||
// string list merge test
|
||||
List<String> a = Arrays.asList("a", "b", "c", "e");
|
||||
List<String> b = Arrays.asList("a", "b", "c", "d");
|
||||
List<String> c = null;
|
||||
|
||||
System.out.println("merge result 1 = " + oaf.mergeLists(a, b));
|
||||
|
||||
System.out.println("merge result 2 = " + oaf.mergeLists(a, c));
|
||||
|
||||
System.out.println("merge result 3 = " + oaf.mergeLists(c, c));
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge publication collected from test.
|
||||
*/
|
||||
@Test
|
||||
void mergePublicationCollectedFromTest() {
|
||||
|
||||
Publication a = publication();
|
||||
Publication b = publication();
|
||||
|
||||
a.setCollectedfrom(Arrays.asList(setKV("a", "open"), setKV("b", "closed")));
|
||||
b.setCollectedfrom(Arrays.asList(setKV("A", "open"), setKV("b", "Open")));
|
||||
|
||||
a.mergeFrom(b);
|
||||
|
||||
assertNotNull(a.getCollectedfrom());
|
||||
assertEquals(3, a.getCollectedfrom().size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Load resource result list.
|
||||
*
|
||||
* @param <T> the type parameter
|
||||
* @param path the path
|
||||
* @param clazz the clazz
|
||||
* @return the list
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
private <T extends Result> List<Result> loadResourceResult(final String path, final Class<T> clazz ) throws Exception {
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
final InputStream str = Objects.requireNonNull(getClass().getResourceAsStream(path));
|
||||
// LOAD test publications
|
||||
return IOUtils.readLines(str).stream().map(s -> {
|
||||
try {
|
||||
return mapper.readValue(s, clazz);
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}).filter(Objects::nonNull).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Apply to any test list result the same pid of the enrichment instance
|
||||
*
|
||||
* @param source the source
|
||||
* @param enrichment the enrichment
|
||||
* @param overrideAlternateIdentifier the override alternate identifier
|
||||
*/
|
||||
private void updatePidIntoPublicationInstance(final List<Result> source, final List<Result>enrichment, final boolean overrideAlternateIdentifier) {
|
||||
for(int i = 0 ; i< source.size(); i++) {
|
||||
final Result currentPub = source.get(i);
|
||||
final Result currentEnrichment = enrichment.get(i);
|
||||
final Instance currentInstance = Objects.requireNonNull(currentPub.getInstance()).get(0);
|
||||
if (overrideAlternateIdentifier)
|
||||
currentInstance.setAlternateIdentifier(Objects.requireNonNull(currentEnrichment.getInstance()).get(0).getPid());
|
||||
else
|
||||
currentInstance.setPid(Objects.requireNonNull(currentEnrichment.getInstance()).get(0).getPid());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void applyAndVerifyEnrichment(final List<Result> l1, final List<Result> l2) {
|
||||
// Apply Merge and verify that enrichments works
|
||||
for(int i = 0 ; i< l1.size(); i++) {
|
||||
final Result currentPub = l2.get(i);
|
||||
final Result currentEnrichment = l1.get(i);
|
||||
currentPub.mergeFrom(currentEnrichment);
|
||||
assertEquals(1, currentPub.getInstance().size());
|
||||
final Instance currentInstance = Objects.requireNonNull(currentPub.getInstance()).get(0);
|
||||
assertNotNull(currentInstance.getMeasures());
|
||||
assertNotNull(currentPub.getTitle());
|
||||
assertFalse(Result.isAnEnrichment(currentPub));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the merge of the APC at the level of the result and the instance.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
|
||||
@Test
|
||||
void testAPCMerge() throws Exception {
|
||||
List<Result> publications = loadResourceResult("/eu/dnetlib/dhp/schema/oaf/utils/publication_apc.json", Publication.class);
|
||||
System.out.println(publications.size());
|
||||
publications.forEach(p -> assertEquals(1, p.getInstance().size()));
|
||||
publications.forEach(p -> assertTrue(p.getProcessingchargeamount() != null ));
|
||||
publications.forEach(p -> assertTrue(p.getProcessingchargecurrency() != null ));
|
||||
publications.forEach(p -> assertTrue(StringUtils.isNotBlank(p.getProcessingchargeamount().getValue() )));
|
||||
publications.forEach(p -> assertTrue(StringUtils.isNotBlank(p.getProcessingchargecurrency().getValue() )));
|
||||
|
||||
publications.forEach(p -> p.getInstance().stream()
|
||||
.forEach(i -> assertTrue(i.getProcessingchargeamount() != null)));
|
||||
publications.forEach(p -> p.getInstance().stream()
|
||||
.forEach(i -> assertTrue(i.getProcessingchargecurrency() != null)));
|
||||
|
||||
publications.forEach(p -> p.getInstance().stream()
|
||||
.forEach(i -> assertTrue(StringUtils.isNotBlank(i.getProcessingchargeamount().getValue()))));
|
||||
publications.forEach(p -> p.getInstance().stream()
|
||||
.forEach(i -> assertTrue(StringUtils.isNotBlank(i.getProcessingchargecurrency().getValue()))));
|
||||
|
||||
Result p1 = publications.get(0);
|
||||
Result p2 = publications.get(1);
|
||||
|
||||
p1.mergeFrom(p2);
|
||||
|
||||
assertEquals("1721.47", p1.getProcessingchargeamount().getValue());
|
||||
assertEquals("EUR", p1.getProcessingchargecurrency().getValue());
|
||||
|
||||
assertEquals(2 , p1.getInstance().size());
|
||||
|
||||
p1.getInstance().stream().forEach(i -> assertTrue(i.getProcessingchargeamount() != null));
|
||||
p1.getInstance().stream().forEach(i -> assertTrue(i.getProcessingchargecurrency() != null));
|
||||
|
||||
p1.getInstance().stream().anyMatch(i -> i.getProcessingchargeamount().getValue().equals("2000.47"));
|
||||
p1.getInstance().stream().anyMatch(i -> i.getProcessingchargeamount().getValue().equals("1721.47"));
|
||||
|
||||
p1.getInstance().stream().anyMatch(i -> i.getProcessingchargecurrency().getValue().equals("EUR"));
|
||||
p1.getInstance().stream().anyMatch(i -> i.getProcessingchargecurrency().getValue().equals("USD"));
|
||||
System.out.println(new ObjectMapper().writeValueAsString(p1));
|
||||
}
|
||||
@Test
|
||||
void testAPCMerge2() throws Exception {
|
||||
List<Result> publications = loadResourceResult("/eu/dnetlib/dhp/schema/oaf/utils/publication_apc2.json", Publication.class);
|
||||
System.out.println(publications.size());
|
||||
publications.forEach(p -> assertEquals(1, p.getInstance().size()));
|
||||
assertTrue(publications.get(0).getProcessingchargeamount() != null );
|
||||
assertTrue(publications.get(0).getProcessingchargecurrency() != null );
|
||||
assertTrue(publications.get(1).getProcessingchargeamount() == null );
|
||||
|
||||
Result p1 = publications.get(1);
|
||||
Result p2 = publications.get(0);
|
||||
|
||||
//merge visible record with OpenAPC
|
||||
p1.mergeFrom(p2);
|
||||
|
||||
assertFalse(p1.getDataInfo().getInvisible());
|
||||
assertEquals("1721.47", p1.getProcessingchargeamount().getValue());
|
||||
assertEquals("EUR", p1.getProcessingchargecurrency().getValue());
|
||||
|
||||
assertEquals(2 , p1.getInstance().size());
|
||||
p1.getInstance().stream().anyMatch(i -> i.getProcessingchargeamount() != null);
|
||||
|
||||
p1.getInstance().stream().anyMatch(i -> i.getProcessingchargecurrency() != null);
|
||||
|
||||
assertEquals("1721.47", p1.getInstance().stream().filter(i -> i.getProcessingchargeamount() != null)
|
||||
.collect(Collectors.toList()).get(0).getProcessingchargeamount().getValue());
|
||||
|
||||
assertEquals("EUR", p1.getInstance().stream().filter(i -> i.getProcessingchargeamount() != null)
|
||||
.collect(Collectors.toList()).get(0).getProcessingchargecurrency().getValue());
|
||||
assertFalse(p1.getDataInfo().getInvisible());
|
||||
System.out.println(new ObjectMapper().writeValueAsString(p1));
|
||||
|
||||
//merge OpenAPC with visible record
|
||||
p2.mergeFrom(p1);
|
||||
assertFalse(p2.getDataInfo().getInvisible());
|
||||
assertEquals("1721.47", p2.getProcessingchargeamount().getValue());
|
||||
assertEquals("EUR", p2.getProcessingchargecurrency().getValue());
|
||||
|
||||
assertEquals(2 , p2.getInstance().size());
|
||||
p2.getInstance().stream().anyMatch(i -> i.getProcessingchargeamount() != null);
|
||||
|
||||
p2.getInstance().stream().anyMatch(i -> i.getProcessingchargecurrency() != null);
|
||||
|
||||
assertEquals("1721.47", p2.getInstance().stream().filter(i -> i.getProcessingchargeamount() != null)
|
||||
.collect(Collectors.toList()).get(0).getProcessingchargeamount().getValue());
|
||||
|
||||
assertEquals("EUR", p2.getInstance().stream().filter(i -> i.getProcessingchargeamount() != null)
|
||||
.collect(Collectors.toList()).get(0).getProcessingchargecurrency().getValue());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test enrichment function.
|
||||
*
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
@Test
|
||||
void testEnrichment() throws Exception {
|
||||
|
||||
|
||||
// 1 TEST UPDATING PID INSTANCE AND MERGE CURRENT PUBLICATION WITH ENRICHMENT
|
||||
// LOAD test publications
|
||||
List<Result> publications = loadResourceResult("/eu/dnetlib/dhp/schema/oaf/utils/publications.json", Publication.class);
|
||||
// Assert that each publication has only one instance and inside that all the measure field is empty
|
||||
publications.forEach(p -> {
|
||||
assertEquals(1, p.getInstance().size());
|
||||
final Instance currentInstance = Objects.requireNonNull(p.getInstance()).get(0);
|
||||
assertNull(currentInstance.getMeasures());
|
||||
});
|
||||
|
||||
// LOAD test enrichments
|
||||
List<Result> enrichment = loadResourceResult("/eu/dnetlib/dhp/schema/oaf/utils/enrichment.json", Result.class);
|
||||
|
||||
updatePidIntoPublicationInstance(publications, enrichment, false);
|
||||
applyAndVerifyEnrichment(publications, enrichment);
|
||||
|
||||
|
||||
// 2 TEST UPDATING ALTERNATE ID INSTANCE AND MERGE CURRENT PUBLICATION WITH ENRICHMENT
|
||||
publications = loadResourceResult("/eu/dnetlib/dhp/schema/oaf/utils/publications.json", Publication.class);
|
||||
enrichment = loadResourceResult("/eu/dnetlib/dhp/schema/oaf/utils/enrichment.json", Result.class);
|
||||
updatePidIntoPublicationInstance(publications, enrichment, true);
|
||||
applyAndVerifyEnrichment(publications, enrichment);
|
||||
|
||||
|
||||
// 3 TEST UPDATING PID INSTANCE AND MERGE ENRICHMENT WITH CURRENT PUBLICATION
|
||||
publications = loadResourceResult("/eu/dnetlib/dhp/schema/oaf/utils/publications.json", Publication.class);
|
||||
enrichment = loadResourceResult("/eu/dnetlib/dhp/schema/oaf/utils/enrichment.json", Result.class);
|
||||
updatePidIntoPublicationInstance(publications, enrichment, false);
|
||||
applyAndVerifyEnrichment( enrichment, publications);
|
||||
|
||||
// 4 TEST UPDATING ALTERNATE ID INSTANCE AND MERGE ENRICHMENT WITH CURRENT PUBLICATION
|
||||
publications = loadResourceResult("/eu/dnetlib/dhp/schema/oaf/utils/publications.json", Publication.class);
|
||||
enrichment = loadResourceResult("/eu/dnetlib/dhp/schema/oaf/utils/enrichment.json", Result.class);
|
||||
updatePidIntoPublicationInstance(publications, enrichment, true);
|
||||
applyAndVerifyEnrichment( enrichment, publications);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Merge publication date of acceptance test both present.
|
||||
*/
|
||||
@Test
|
||||
void mergePublicationDateOfAcceptanceTest_bothPresent() {
|
||||
|
||||
Publication a = publication();
|
||||
Publication b = publication();
|
||||
|
||||
a.setDateofacceptance(field("2021-06-18"));
|
||||
b.setDateofacceptance(field("2021-06-19"));
|
||||
|
||||
a.mergeFrom(b);
|
||||
|
||||
assertNotNull(a.getDateofacceptance());
|
||||
assertEquals("2021-06-18", a.getDateofacceptance().getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge publication date of acceptance test both present 1.
|
||||
*/
|
||||
@Test
|
||||
void mergePublicationDateOfAcceptanceTest_bothPresent_1() {
|
||||
|
||||
Publication a = publication("0.8");
|
||||
Publication b = publication("0.9");
|
||||
|
||||
a.setDateofacceptance(field("2021-06-18"));
|
||||
b.setDateofacceptance(field("2021-06-19"));
|
||||
|
||||
a.mergeFrom(b);
|
||||
|
||||
assertNotNull(a.getDateofacceptance());
|
||||
assertEquals("2021-06-19", a.getDateofacceptance().getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge publication date of acceptance test both present 2.
|
||||
*/
|
||||
@Test
|
||||
void mergePublicationDateOfAcceptanceTest_bothPresent_2() {
|
||||
|
||||
Publication a = publication("0.9");
|
||||
Publication b = publication("0.8");
|
||||
|
||||
a.setDateofacceptance(field("2021-06-18"));
|
||||
b.setDateofacceptance(field("2021-06-19"));
|
||||
|
||||
a.mergeFrom(b);
|
||||
|
||||
assertNotNull(a.getDateofacceptance());
|
||||
assertEquals("2021-06-18", a.getDateofacceptance().getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge publication date of acceptance test left missing.
|
||||
*/
|
||||
@Test
|
||||
void mergePublicationDateOfAcceptanceTest_leftMissing() {
|
||||
|
||||
Publication a = publication();
|
||||
Publication b = publication();
|
||||
|
||||
b.setDateofacceptance(field("2021-06-19"));
|
||||
|
||||
a.mergeFrom(b);
|
||||
|
||||
assertNotNull(a.getDateofacceptance());
|
||||
assertEquals("2021-06-19", a.getDateofacceptance().getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge publication date of acceptance test left missing 1.
|
||||
*/
|
||||
@Test
|
||||
void mergePublicationDateOfAcceptanceTest_leftMissing_1() {
|
||||
|
||||
Publication a = publication("0.9");
|
||||
Publication b = publication("0.8");
|
||||
|
||||
b.setDateofacceptance(field("2021-06-19"));
|
||||
|
||||
a.mergeFrom(b);
|
||||
|
||||
assertNotNull(a.getDateofacceptance());
|
||||
assertEquals("2021-06-19", a.getDateofacceptance().getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge publication date of acceptance test left missing 2.
|
||||
*/
|
||||
@Test
|
||||
void mergePublicationDateOfAcceptanceTest_leftMissing_2() {
|
||||
|
||||
Publication a = publication("0.8");
|
||||
Publication b = publication("0.9");
|
||||
|
||||
b.setDateofacceptance(field("2021-06-19"));
|
||||
|
||||
a.mergeFrom(b);
|
||||
|
||||
assertNotNull(a.getDateofacceptance());
|
||||
assertEquals("2021-06-19", a.getDateofacceptance().getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge publication date of acceptance test right missing.
|
||||
*/
|
||||
@Test
|
||||
void mergePublicationDateOfAcceptanceTest_rightMissing() {
|
||||
|
||||
Publication a = publication();
|
||||
Publication b = publication();
|
||||
|
||||
a.setDateofacceptance(field("2021-06-19"));
|
||||
|
||||
a.mergeFrom(b);
|
||||
|
||||
assertNotNull(a.getDateofacceptance());
|
||||
assertEquals("2021-06-19", a.getDateofacceptance().getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge publication date of acceptance test right missing 1.
|
||||
*/
|
||||
@Test
|
||||
void mergePublicationDateOfAcceptanceTest_rightMissing_1() {
|
||||
|
||||
Publication a = publication("0.8");
|
||||
Publication b = publication("0.9");
|
||||
|
||||
a.setDateofacceptance(field("2021-06-19"));
|
||||
|
||||
a.mergeFrom(b);
|
||||
|
||||
assertNotNull(a.getDateofacceptance());
|
||||
assertEquals("2021-06-19", a.getDateofacceptance().getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge publication date of acceptance test right missing 2.
|
||||
*/
|
||||
@Test
|
||||
void mergePublicationDateOfAcceptanceTest_rightMissing_2() {
|
||||
|
||||
Publication a = publication("0.9");
|
||||
Publication b = publication("0.8");
|
||||
|
||||
a.setDateofacceptance(field("2021-06-19"));
|
||||
|
||||
a.mergeFrom(b);
|
||||
|
||||
assertNotNull(a.getDateofacceptance());
|
||||
assertEquals("2021-06-19", a.getDateofacceptance().getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge publication subject test.
|
||||
*/
|
||||
@Test
|
||||
void mergePublicationSubjectTest() {
|
||||
|
||||
Publication a = publication();
|
||||
Publication b = publication();
|
||||
|
||||
a.setSubject(Arrays.asList(setSP("a", "open", "classe"), setSP("b", "open", "classe")));
|
||||
b.setSubject(Arrays.asList(setSP("A", "open", "classe"), setSP("c", "open", "classe")));
|
||||
|
||||
a.mergeFrom(b);
|
||||
|
||||
assertNotNull(a.getSubject());
|
||||
assertEquals(3, a.getSubject().size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge relation test.
|
||||
*/
|
||||
@Test
|
||||
void mergeRelationTest() {
|
||||
|
||||
Relation a = createRel(null, null);
|
||||
Relation b = createRel(null, null);
|
||||
a.mergeFrom(b);
|
||||
assertEquals(a, b);
|
||||
|
||||
a = createRel(true, null);
|
||||
b = createRel(null, null);
|
||||
a.mergeFrom(b);
|
||||
assertEquals(true, a.getValidated());
|
||||
|
||||
a = createRel(true, null);
|
||||
b = createRel(false, null);
|
||||
a.mergeFrom(b);
|
||||
assertEquals(true, a.getValidated());
|
||||
|
||||
a = createRel(true, null);
|
||||
b = createRel(true, "2016-04-05T12:41:19.202Z");
|
||||
a.mergeFrom(b);
|
||||
assertEquals("2016-04-05T12:41:19.202Z", a.getValidationDate());
|
||||
|
||||
a = createRel(true, "2016-05-07T12:41:19.202Z");
|
||||
b = createRel(true, "2016-04-05T12:41:19.202Z");
|
||||
a.mergeFrom(b);
|
||||
assertEquals("2016-04-05T12:41:19.202Z", a.getValidationDate());
|
||||
|
||||
a = createRel(true, "2020-09-10 11:08:52");
|
||||
b = createRel(true, "2021-09-10 11:08:52");
|
||||
a.mergeFrom(b);
|
||||
assertEquals("2020-09-10 11:08:52", a.getValidationDate());
|
||||
|
||||
a = createRel(true, "2021-03-16T10:32:42Z");
|
||||
b = createRel(true, "2020-03-16T10:32:42Z");
|
||||
a.mergeFrom(b);
|
||||
assertEquals("2020-03-16T10:32:42Z", a.getValidationDate());
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge relation test parse exception.
|
||||
*/
|
||||
@Test
|
||||
void mergeRelationTestParseException() {
|
||||
assertThrows(DateTimeParseException.class, () -> {
|
||||
Relation a = createRel(true, "Once upon a time ...");
|
||||
Relation b = createRel(true, "... in a far away land");
|
||||
a.mergeFrom(b);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create rel relation.
|
||||
*
|
||||
* @param validated the validated
|
||||
* @param validationDate the validation date
|
||||
* @return the relation
|
||||
*/
|
||||
private Relation createRel(Boolean validated, String validationDate) {
|
||||
Relation rel = new Relation();
|
||||
rel.setSource("1");
|
||||
rel.setTarget("2");
|
||||
rel.setRelType("reltype");
|
||||
rel.setSubRelType("subreltype");
|
||||
rel.setRelClass("relclass");
|
||||
rel.setValidated(validated);
|
||||
rel.setValidationDate(validationDate);
|
||||
return rel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets kv.
|
||||
*
|
||||
* @param key the key
|
||||
* @param value the value
|
||||
* @return the kv
|
||||
*/
|
||||
private KeyValue setKV(final String key, final String value) {
|
||||
|
||||
KeyValue k = new KeyValue();
|
||||
|
||||
k.setKey(key);
|
||||
k.setValue(value);
|
||||
|
||||
return k;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets sp.
|
||||
*
|
||||
* @param value the value
|
||||
* @param schema the schema
|
||||
* @param classname the classname
|
||||
* @return the sp
|
||||
*/
|
||||
private StructuredProperty setSP(
|
||||
final String value, final String schema, final String classname) {
|
||||
StructuredProperty s = new StructuredProperty();
|
||||
s.setValue(value);
|
||||
Qualifier q = new Qualifier();
|
||||
q.setClassname(classname);
|
||||
q.setClassid(classname);
|
||||
q.setSchemename(schema);
|
||||
q.setSchemeid(schema);
|
||||
s.setQualifier(q);
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Field field.
|
||||
*
|
||||
* @param <T> the type parameter
|
||||
* @param value the value
|
||||
* @return the field
|
||||
*/
|
||||
private <T> Field<T> field(T value) {
|
||||
Field<T> f = new Field();
|
||||
f.setValue(value);
|
||||
return f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Publication publication.
|
||||
*
|
||||
* @return the publication
|
||||
*/
|
||||
private Publication publication() {
|
||||
Publication p = new Publication();
|
||||
p.setDataInfo(df("0.9"));
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Publication publication.
|
||||
*
|
||||
* @param trust the trust
|
||||
* @return the publication
|
||||
*/
|
||||
private Publication publication(String trust) {
|
||||
Publication p = new Publication();
|
||||
p.setDataInfo(df(trust));
|
||||
return p;
|
||||
}
|
||||
|
||||
/**
|
||||
* Df data info.
|
||||
*
|
||||
* @param trust the trust
|
||||
* @return the data info
|
||||
*/
|
||||
private DataInfo df(String trust) {
|
||||
DataInfo d = new DataInfo();
|
||||
d.setTrust(trust);
|
||||
return d;
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
|
||||
package eu.dnetlib.dhp.schema.oaf.utils;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class BlackListProviderTest {
|
||||
|
||||
@Test
|
||||
void blackListTest() {
|
||||
|
||||
Assertions.assertNotNull(PidBlacklistProvider.getBlacklist());
|
||||
Assertions.assertNotNull(PidBlacklistProvider.getBlacklist().get("doi"));
|
||||
Assertions.assertTrue(PidBlacklistProvider.getBlacklist().get("doi").size() > 0);
|
||||
final Set<String> xxx = PidBlacklistProvider.getBlacklist("xxx");
|
||||
Assertions.assertNotNull(xxx);
|
||||
Assertions.assertEquals(0, xxx.size());
|
||||
}
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
|
||||
package eu.dnetlib.dhp.schema.oaf.utils;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import eu.dnetlib.dhp.schema.oaf.Publication;
|
||||
|
||||
class IdentifierFactoryTest {
|
||||
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper()
|
||||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
|
||||
@Test
|
||||
void testCreateIdentifierForPublication() throws IOException {
|
||||
|
||||
verifyIdentifier(
|
||||
"publication_doi1.json", "50|doi_________::79dbc7a2a56dc1532659f9038843256e", true);
|
||||
|
||||
verifyIdentifier(
|
||||
"publication_doi2.json", "50|doi_________::79dbc7a2a56dc1532659f9038843256e", true);
|
||||
|
||||
verifyIdentifier(
|
||||
"publication_doi3.json", "50|pmc_________::94e4cb08c93f8733b48e2445d04002ac", true);
|
||||
|
||||
verifyIdentifier(
|
||||
"publication_doi4.json", "50|od______2852::38861c44e6052a8d49f59a4c39ba5e66", true);
|
||||
|
||||
verifyIdentifier(
|
||||
"publication_doi5.json", "50|doi_________::3bef95c0ca26dd55451fc8839ea69d27", true);
|
||||
|
||||
verifyIdentifier(
|
||||
"publication_pmc1.json", "50|DansKnawCris::0829b5191605bdbea36d6502b8c1ce1f", true);
|
||||
|
||||
verifyIdentifier(
|
||||
"publication_pmc2.json", "50|pmc_________::94e4cb08c93f8733b48e2445d04002ac", true);
|
||||
|
||||
verifyIdentifier(
|
||||
"publication_openapc.json", "50|doi_________::79dbc7a2a56dc1532659f9038843256e", true);
|
||||
|
||||
final String defaultID = "50|DansKnawCris::0829b5191605bdbea36d6502b8c1ce1f";
|
||||
verifyIdentifier("publication_3.json", defaultID, true);
|
||||
verifyIdentifier("publication_4.json", defaultID, true);
|
||||
verifyIdentifier("publication_5.json", defaultID, true);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateIdentifierForPublicationNoHash() throws IOException {
|
||||
|
||||
verifyIdentifier("publication_doi1.json", "50|doi_________::10.1016/j.cmet.2010.03.013", false);
|
||||
verifyIdentifier("publication_doi2.json", "50|doi_________::10.1016/j.cmet.2010.03.013", false);
|
||||
verifyIdentifier("publication_pmc1.json", "50|DansKnawCris::0829b5191605bdbea36d6502b8c1ce1f", false);
|
||||
verifyIdentifier(
|
||||
"publication_urn1.json", "50|DansKnawCris::0829b5191605bdbea36d6502b8c1ce1f", false);
|
||||
|
||||
final String defaultID = "50|DansKnawCris::0829b5191605bdbea36d6502b8c1ce1f";
|
||||
verifyIdentifier("publication_3.json", defaultID, false);
|
||||
verifyIdentifier("publication_4.json", defaultID, false);
|
||||
verifyIdentifier("publication_5.json", defaultID, false);
|
||||
}
|
||||
|
||||
protected void verifyIdentifier(String filename, String expectedID, boolean md5) throws IOException {
|
||||
final String json = IOUtils.toString(getClass().getResourceAsStream(filename));
|
||||
final Publication pub = OBJECT_MAPPER.readValue(json, Publication.class);
|
||||
|
||||
String id = IdentifierFactory.createIdentifier(pub, md5);
|
||||
|
||||
assertNotNull(id);
|
||||
assertEquals(expectedID, id);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue