Merge pull request 'XML serialisation of instances with the same URLs - 2nd round' (#204) from instance_group_by_url into beta

Reviewed-on: D-Net/dnet-hadoop#204
This commit is contained in:
Claudio Atzori 2022-03-28 09:24:00 +02:00
commit 5d53ac95aa
4 changed files with 47 additions and 14 deletions

View File

@ -12,6 +12,7 @@ import scala.Serializable;
public class XmlInstance implements Serializable {
public static final AccessRight UNKNOWN_ACCESS_RIGHT;
public static final Qualifier UNKNOWN_REVIEW_LEVEL;
static {
UNKNOWN_ACCESS_RIGHT = new AccessRight();
@ -19,6 +20,12 @@ public class XmlInstance implements Serializable {
UNKNOWN_ACCESS_RIGHT.setClassname(ModelConstants.UNKNOWN);
UNKNOWN_ACCESS_RIGHT.setSchemeid(ModelConstants.DNET_ACCESS_MODES);
UNKNOWN_ACCESS_RIGHT.setSchemename(ModelConstants.DNET_ACCESS_MODES);
UNKNOWN_REVIEW_LEVEL = new Qualifier();
UNKNOWN_REVIEW_LEVEL.setClassid("0000");
UNKNOWN_REVIEW_LEVEL.setClassname(ModelConstants.UNKNOWN);
UNKNOWN_ACCESS_RIGHT.setSchemeid(ModelConstants.DNET_REVIEW_LEVELS);
UNKNOWN_REVIEW_LEVEL.setSchemename(ModelConstants.DNET_REVIEW_LEVELS);
}
private String url;
@ -50,7 +57,7 @@ public class XmlInstance implements Serializable {
// typed results
private String processingchargecurrency;
private Set<Qualifier> refereed = Sets.newHashSet();; // peer-review status
private Qualifier refereed; // peer-review status
public String getUrl() {
return url;
@ -148,11 +155,11 @@ public class XmlInstance implements Serializable {
this.processingchargecurrency = processingchargecurrency;
}
public Set<Qualifier> getRefereed() {
public Qualifier getRefereed() {
return refereed;
}
public void setRefereed(Set<Qualifier> refereed) {
public void setRefereed(Qualifier refereed) {
this.refereed = refereed;
}
}

View File

@ -31,6 +31,7 @@ import org.dom4j.Node;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
import org.json4s.Xml;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Joiner;
@ -1208,14 +1209,8 @@ public class XmlRecordFactory implements Serializable {
if (instance.getRefereed() != null) {
fields
.addAll(
instance
.getRefereed()
.stream()
.filter(Objects::nonNull)
.filter(r -> !r.isBlank())
.map(r -> XmlSerializationUtils.mapQualifier("refereed", r))
.collect(Collectors.toList()));
.add(
XmlSerializationUtils.mapQualifier("refereed", instance.getRefereed()));
}
if (instance.getProcessingchargeamount() != null
&& isNotBlank(instance.getProcessingchargeamount())) {
@ -1359,13 +1354,20 @@ public class XmlRecordFactory implements Serializable {
.map(Instance::getAccessright)
.min(new AccessRightComparator<AccessRight>())
.orElse(XmlInstance.UNKNOWN_ACCESS_RIGHT));
instance
.setRefereed(
instances
.stream()
.map(Pair::getValue)
.map(i -> Optional.ofNullable(i.getRefereed()).orElse(XmlInstance.UNKNOWN_REVIEW_LEVEL))
.min(new RefereedComparator())
.orElse(XmlInstance.UNKNOWN_REVIEW_LEVEL));
instances.forEach(p -> {
final Instance i = p.getRight();
instance.getCollectedfrom().add(i.getCollectedfrom());
instance.getHostedby().add(i.getHostedby());
instance.getInstancetype().add(i.getInstancetype());
instance.getRefereed().add(i.getRefereed());
instance
.setProcessingchargeamount(
Optional.ofNullable(i.getProcessingchargeamount()).map(apc -> apc.getValue()).orElse(null));

View File

@ -66,7 +66,7 @@ public class XmlRecordFactoryTest {
assertEquals("doi", doc.valueOf("//instance/alternateidentifier/@classid"));
assertEquals("10.5689/LIB.2018.2853550", doc.valueOf("//instance/alternateidentifier/text()"));
assertEquals(3, doc.selectNodes("//instance").size());
assertEquals(2, doc.selectNodes("//instance").size());
assertEquals("1721.47", doc.valueOf("//processingchargeamount/text()"));
assertEquals("EUR", doc.valueOf("//processingchargecurrency/text()"));

View File

@ -453,6 +453,12 @@
"schemeid": "dnet:dataCite_resource",
"schemename": "dnet:dataCite_resource"
},
"refereed": {
"classid": "0001",
"classname": "peerReviewed",
"schemeid": "dnet:review_levels",
"schemename": "dnet:review_levels"
},
"license": {
"dataInfo": {
"deletedbyinference": false,
@ -585,6 +591,12 @@
"schemeid": "dnet:dataCite_resource",
"schemename": "dnet:dataCite_resource"
},
"refereed": {
"classid": "0000",
"classname": "UNKNOWN",
"schemeid": "dnet:review_levels",
"schemename": "dnet:review_levels"
},
"license": {
"dataInfo": {
"deletedbyinference": false,
@ -717,6 +729,12 @@
"schemeid": "dnet:dataCite_resource",
"schemename": "dnet:dataCite_resource"
},
"refereed": {
"classid": "0002",
"classname": "nonPeerReviewed",
"schemeid": "dnet:review_levels",
"schemename": "dnet:review_levels"
},
"license": {
"dataInfo": {
"deletedbyinference": false,
@ -849,6 +867,12 @@
"schemeid": "dnet:dataCite_resource",
"schemename": "dnet:dataCite_resource"
},
"refereed": {
"classid": "0001",
"classname": "peerReviewed",
"schemeid": "dnet:review_levels",
"schemename": "dnet:review_levels"
},
"license": {
"dataInfo": {
"deletedbyinference": false,
@ -866,7 +890,7 @@
"value": ""
},
"url": [
"http://dx.doi.org/10.1109/TED.2018.2853552",
"http://dx.doi.org/10.1109/TED.2018.2853551",
"http://dx.doi.org/10.1109/TED.2018.2853554"
]
},