Introduced fields for the Irish tender

This commit is contained in:
Claudio Atzori 2023-10-16 12:59:29 +02:00
parent d56343164b
commit 9ec184ff15
5 changed files with 109 additions and 32 deletions

View File

@ -62,7 +62,9 @@ public class ModelConstants {
public static final String DNET_RELATION_RELTYPE = "dnet:relation_relType";
public static final String DNET_RELATION_SUBRELTYPE = "dnet:relation_subRelType";
public static final String DNET_RELATION_RELCLASS = "dnet:relation_relClass";
public static final String OPENAIRE_COAR_RESOURCE_TYPES_3_1 = "openaire::coar_resource_types_3_1";
public static final String OPENAIRE_USER_RESOURCE_TYPES = "openaire::user_resource_types";
public static final String OPENAIRE_META_RESOURCE_TYPE = "openaire::meta_resource_types";
public static final String PEER_REVIEWED_CLASSNAME = "nonPeerReviewed";
public static final String NON_PEER_REVIEWED_CLASSNAME = "nonPeerReviewed";
public static final String PEER_REVIEWED_CLASSID = "0001";

View File

@ -1,14 +1,19 @@
package eu.dnetlib.dhp.schema.oaf;
import static java.util.Objects.*;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import com.fasterxml.jackson.annotation.JsonProperty;
import eu.dnetlib.dhp.schema.common.AccessRightComparator;
import eu.dnetlib.dhp.schema.common.ModelConstants;
import eu.dnetlib.dhp.schema.oaf.utils.CleaningFunctions;
@ -39,6 +44,11 @@ public class Result extends OafEntity implements Serializable {
// resulttype allows subclassing results into publications | datasets | software
private Qualifier resulttype;
/**
* Temporary field suporting the analysis of the new COAR-based resource types
*/
private Qualifier metaResourceType;
/**
* The Language.
*/
@ -140,10 +150,12 @@ public class Result extends OafEntity implements Serializable {
*/
private List<EoscIfGuidelines> eoscifguidelines;
@JsonProperty("isGreen")
private Boolean isGreen;
private OpenAccessColor openAccessColor;
@JsonProperty("isInDiamondJournal")
private Boolean isInDiamondJournal;
private Boolean publiclyFunded;
@ -200,6 +212,14 @@ public class Result extends OafEntity implements Serializable {
this.resulttype = resulttype;
}
public Qualifier getMetaResourceType() {
return metaResourceType;
}
public void setMetaResourceType(Qualifier metaResourceType) {
this.metaResourceType = metaResourceType;
}
/**
* Gets language.
*
@ -550,11 +570,11 @@ public class Result extends OafEntity implements Serializable {
this.eoscifguidelines = eoscifguidelines;
}
public Boolean getGreen() {
public Boolean getIsGreen() {
return isGreen;
}
public void setGreen(Boolean green) {
public void setIsGreen(Boolean green) {
isGreen = green;
}
@ -566,11 +586,11 @@ public class Result extends OafEntity implements Serializable {
this.openAccessColor = openAccessColor;
}
public Boolean getInDiamondJournal() {
public Boolean getIsInDiamondJournal() {
return isInDiamondJournal;
}
public void setInDiamondJournal(Boolean inDiamondJournal) {
public void setIsInDiamondJournal(Boolean inDiamondJournal) {
isInDiamondJournal = inDiamondJournal;
}
@ -768,13 +788,25 @@ public class Result extends OafEntity implements Serializable {
Result r = (Result) e;
if(processingchargeamount == null || StringUtils.isBlank(processingchargeamount.getValue() )){
if(processingchargeamount == null || StringUtils.isBlank(processingchargeamount.getValue())){
processingchargeamount = r.getProcessingchargeamount();
processingchargecurrency = r.getProcessingchargecurrency();
}
eoscifguidelines = mergeLists(eoscifguidelines, r.getEoscifguidelines());
setIsGreen(mergeBooleanOR(getIsGreen(), r.getIsGreen()));
setIsInDiamondJournal(mergeBooleanOR(getIsInDiamondJournal(), r.getIsInDiamondJournal()));
setPubliclyFunded(mergeBooleanOR(getPubliclyFunded(), r.getPubliclyFunded()));
if (Boolean.logicalXor(nonNull(getOpenAccessColor()), nonNull(r.getOpenAccessColor()))) {
setOpenAccessColor(ObjectUtils.firstNonNull(getOpenAccessColor(), r.getOpenAccessColor()));
} else if (!Objects.equals(getOpenAccessColor(), r.getOpenAccessColor())) {
setOpenAccessColor(null);
}
if( !isAnEnrichment(this) && !isAnEnrichment(e))
instance = mergeLists(instance, r.getInstance());
else {
@ -795,8 +827,8 @@ public class Result extends OafEntity implements Serializable {
if (r.getLanguage() != null && compareTrust(this, r) < 0)
language = r.getLanguage();
if (Objects.nonNull(r.getDateofacceptance())) {
if (Objects.isNull(getDateofacceptance())) {
if (nonNull(r.getDateofacceptance())) {
if (isNull(getDateofacceptance())) {
dateofacceptance = r.getDateofacceptance();
} else if (compareTrust(this, r) < 0) {
dateofacceptance = r.getDateofacceptance();
@ -863,6 +895,16 @@ public class Result extends OafEntity implements Serializable {
externalReference = mergeLists(externalReference, r.getExternalReference());
}
private Boolean mergeBooleanOR(Boolean a, Boolean b) {
if (Boolean.logicalXor(isNull(a), isNull(b))) {
return ObjectUtils.firstNonNull(a, b);
} else if (nonNull(a) & nonNull(b)) {
return a || b;
} else {
return null;
}
}
/**
* Longest lists list.
*

View File

@ -143,20 +143,16 @@ class MergeTest {
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 -> assertNotNull(p.getProcessingchargeamount()));
publications.forEach(p -> assertNotNull(p.getProcessingchargecurrency()));
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().forEach(i -> assertNotNull(i.getProcessingchargeamount())));
publications.forEach(p -> p.getInstance().forEach(i -> assertNotNull(i.getProcessingchargecurrency())));
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()))));
publications.forEach(p -> p.getInstance().forEach(i -> assertTrue(StringUtils.isNotBlank(i.getProcessingchargeamount().getValue()))));
publications.forEach(p -> p.getInstance().forEach(i -> assertTrue(StringUtils.isNotBlank(i.getProcessingchargecurrency().getValue()))));
Result p1 = publications.get(0);
Result p2 = publications.get(1);
@ -168,24 +164,25 @@ class MergeTest {
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().forEach(i -> assertNotNull(i.getProcessingchargeamount()));
p1.getInstance().forEach(i -> assertNotNull(i.getProcessingchargecurrency()));
p1.getInstance().stream().anyMatch(i -> i.getProcessingchargeamount().getValue().equals("2000.47"));
p1.getInstance().stream().anyMatch(i -> i.getProcessingchargeamount().getValue().equals("1721.47"));
assertTrue(p1.getInstance().stream().anyMatch(i -> i.getProcessingchargeamount().getValue().equals("2000.47")));
assertTrue(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"));
assertTrue(p1.getInstance().stream().anyMatch(i -> i.getProcessingchargecurrency().getValue().equals("EUR")));
assertTrue(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 );
assertNotNull(publications.get(0).getProcessingchargeamount());
assertNotNull(publications.get(0).getProcessingchargecurrency());
assertNull(publications.get(1).getProcessingchargeamount());
Result p1 = publications.get(1);
Result p2 = publications.get(0);
@ -198,9 +195,9 @@ class MergeTest {
assertEquals("EUR", p1.getProcessingchargecurrency().getValue());
assertEquals(2 , p1.getInstance().size());
p1.getInstance().stream().anyMatch(i -> i.getProcessingchargeamount() != null);
assertTrue(p1.getInstance().stream().anyMatch(i -> i.getProcessingchargeamount() != null));
p1.getInstance().stream().anyMatch(i -> i.getProcessingchargecurrency() != null);
assertTrue(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());
@ -217,16 +214,47 @@ class MergeTest {
assertEquals("EUR", p2.getProcessingchargecurrency().getValue());
assertEquals(2 , p2.getInstance().size());
p2.getInstance().stream().anyMatch(i -> i.getProcessingchargeamount() != null);
assertTrue(p2.getInstance().stream().anyMatch(i -> i.getProcessingchargeamount() != null));
p2.getInstance().stream().anyMatch(i -> i.getProcessingchargecurrency() != null);
assertTrue(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
void test_merge_irish_1() throws Exception {
List<Result> publications = loadResourceResult("/eu/dnetlib/dhp/schema/oaf/utils/publication_irish_tender_1.json", Publication.class);
Publication p = new Publication();
publications.forEach(p::mergeFrom);
assertNotNull(p);
assertTrue(p.getIsGreen());
assertTrue(p.getIsInDiamondJournal());
assertFalse(p.getPubliclyFunded());
assertEquals(OpenAccessColor.gold, p.getOpenAccessColor());
}
@Test
void test_merge_irish_2() throws Exception {
List<Result> publications = loadResourceResult("/eu/dnetlib/dhp/schema/oaf/utils/publication_irish_tender_2.json", Publication.class);
Publication p = new Publication();
publications.forEach(p::mergeFrom);
assertNotNull(p);
assertTrue(p.getIsGreen());
assertTrue(p.getIsInDiamondJournal());
assertFalse(p.getPubliclyFunded());
assertNull(p.getOpenAccessColor());
}
/**
@ -274,7 +302,6 @@ class MergeTest {
updatePidIntoPublicationInstance(publications, enrichment, true);
applyAndVerifyEnrichment( enrichment, publications);
}

View File

@ -0,0 +1,3 @@
{"id":"50|DansKnawCris::0829b5191605bdbea36d6502b8c1ce1f", "resulttype" : { "classid" : "publication" }, "pid":[{"qualifier":{"classid":"doi"},"value":"10.1016/j.cmet.2011.03.013"},{"qualifier":{"classid":"urn"},"value":"urn:nbn:nl:ui:29-f3ed5f9e-edf6-457e-8848-61b58a4075e2"},{"qualifier":{"classid":"scp-number"},"value":"79953761260"},{"qualifier":{"classid":"pmc"},"value":"21459329"}], "collectedfrom" : [ { "key" : "10|openaire____::081b82f96300b6a6e3d282bad31cb6e2", "value" : "Crossref"} ], "isGreen": null, "openAccessColor": "gold", "isInDiamondJournal": null, "publiclyFunded": null}
{"id":"50|DansKnawCris::0829b5191605bdbea36d6502b8c1ce1g", "resulttype" : { "classid" : "publication" }, "isGreen": true, "openAccessColor": "gold", "isInDiamondJournal": true, "publiclyFunded": false }
{"id":"50|DansKnawCris::0829b5191605bdbea36d6502b8c1ce1h", "resulttype" : { "classid" : "publication" }, "isGreen": false, "openAccessColor": null, "isInDiamondJournal": true, "publiclyFunded": false }

View File

@ -0,0 +1,3 @@
{"id":"50|DansKnawCris::0829b5191605bdbea36d6502b8c1ce1f", "resulttype" : { "classid" : "publication" }, "pid":[{"qualifier":{"classid":"doi"},"value":"10.1016/j.cmet.2011.03.013"},{"qualifier":{"classid":"urn"},"value":"urn:nbn:nl:ui:29-f3ed5f9e-edf6-457e-8848-61b58a4075e2"},{"qualifier":{"classid":"scp-number"},"value":"79953761260"},{"qualifier":{"classid":"pmc"},"value":"21459329"}], "collectedfrom" : [ { "key" : "10|openaire____::081b82f96300b6a6e3d282bad31cb6e2", "value" : "Crossref"} ], "isGreen": null, "openAccessColor": "gold", "isInDiamondJournal": null, "publiclyFunded": null}
{"id":"50|DansKnawCris::0829b5191605bdbea36d6502b8c1ce1g", "resulttype" : { "classid" : "publication" }, "isGreen": true, "openAccessColor": "bronze", "isInDiamondJournal": true, "publiclyFunded": false }
{"id":"50|DansKnawCris::0829b5191605bdbea36d6502b8c1ce1h", "resulttype" : { "classid" : "publication" }, "isGreen": false, "openAccessColor": null, "isInDiamondJournal": true, "publiclyFunded": false }