1
0
Fork 0

[graph provision] fixed serialization of the instancetypes

This commit is contained in:
Claudio Atzori 2024-06-28 14:21:12 +02:00
parent 1ccf01cdb8
commit 1bc8c5d173
2 changed files with 26 additions and 12 deletions

View File

@ -1315,7 +1315,7 @@ public class XmlRecordFactory implements Serializable {
instance
.getCollectedfrom()
.stream()
.filter(cf -> kvNotBlank(cf))
.filter(XmlRecordFactory::kvNotBlank)
.map(cf -> XmlSerializationUtils.mapKeyValue("collectedfrom", cf))
.collect(Collectors.toList()));
}
@ -1326,7 +1326,7 @@ public class XmlRecordFactory implements Serializable {
instance
.getHostedby()
.stream()
.filter(hb -> kvNotBlank(hb))
.filter(XmlRecordFactory::kvNotBlank)
.map(hb -> XmlSerializationUtils.mapKeyValue("hostedby", hb))
.collect(Collectors.toList()));
}
@ -1336,7 +1336,7 @@ public class XmlRecordFactory implements Serializable {
instance
.getDateofacceptance()
.stream()
.filter(d -> isNotBlank(d))
.filter(StringUtils::isNotBlank)
.map(d -> XmlSerializationUtils.asXmlElement("dateofacceptance", d))
.collect(Collectors.toList()));
}
@ -1346,7 +1346,7 @@ public class XmlRecordFactory implements Serializable {
instance
.getInstancetype()
.stream()
.filter(t -> !StringUtils.isNotBlank(t.getClassid()))
.filter(t -> StringUtils.isNotBlank(t.getClassid()))
.map(t -> XmlSerializationUtils.mapQualifier("instancetype", t))
.collect(Collectors.toList()));
}
@ -1356,7 +1356,7 @@ public class XmlRecordFactory implements Serializable {
instance
.getDistributionlocation()
.stream()
.filter(d -> isNotBlank(d))
.filter(StringUtils::isNotBlank)
.map(d -> XmlSerializationUtils.asXmlElement("distributionlocation", d))
.collect(Collectors.toList()));
}
@ -1409,7 +1409,7 @@ public class XmlRecordFactory implements Serializable {
instance
.getLicense()
.stream()
.filter(d -> isNotBlank(d))
.filter(StringUtils::isNotBlank)
.map(d -> XmlSerializationUtils.asXmlElement("license", d))
.collect(Collectors.toList()));
}
@ -1540,11 +1540,16 @@ public class XmlRecordFactory implements Serializable {
.min(new RefereedComparator())
.orElse(XmlInstance.UNKNOWN_REVIEW_LEVEL));
Map<String, Qualifier> instanceTypes = Maps.newHashMap();
instances.forEach(p -> {
final Instance i = p.getRight();
instance.getCollectedfrom().add(i.getCollectedfrom());
instance.getHostedby().add(i.getHostedby());
instance.getInstancetype().add(i.getInstancetype());
if (Optional.ofNullable(i.getInstancetype()).map(Qualifier::getClassid).isPresent()) {
instanceTypes.putIfAbsent(i.getInstancetype().getClassid(), i.getInstancetype());
}
instance
.setProcessingchargeamount(
Optional.ofNullable(i.getProcessingchargeamount()).map(apc -> apc.getValue()).orElse(null));
@ -1571,6 +1576,8 @@ public class XmlRecordFactory implements Serializable {
.ifPresent(instance::setFulltext);
});
instance.getInstancetype().addAll(instanceTypes.values());
if (instance.getHostedby().size() > 1
&& instance.getHostedby().stream().anyMatch(hb -> ModelConstants.UNKNOWN_REPOSITORY.equals(hb))) {
instance.getHostedby().remove(ModelConstants.UNKNOWN_REPOSITORY);

View File

@ -5,6 +5,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.io.IOException;
import java.io.StringReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
@ -16,6 +17,9 @@ import javax.xml.transform.TransformerException;
import org.apache.commons.io.IOUtils;
import org.apache.solr.client.solrj.util.ClientUtils;
import org.apache.solr.common.SolrInputDocument;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -34,7 +38,6 @@ import eu.dnetlib.dhp.utils.saxon.SaxonTransformerFactory;
/**
* This test can be used to produce a record that can be manually fed to Solr in XML format.
*
* The input is a JoinedEntity, i.e. a json representation of an OpenAIRE entity that embeds all the linked entities.
*/
public class IndexRecordTransformerTest {
@ -54,7 +57,7 @@ public class IndexRecordTransformerTest {
}
@Test
public void testPublicationRecordTransformation() throws IOException, TransformerException {
public void testPublicationRecordTransformation() throws IOException, TransformerException, DocumentException {
final XmlRecordFactory xmlRecordFactory = new XmlRecordFactory(contextMapper, false,
PayloadConverterJob.schemaLocation);
@ -71,11 +74,15 @@ public class IndexRecordTransformerTest {
new RelatedEntityWrapper(rel,
CreateRelatedEntitiesJob_phase1.asRelatedEntity(pj, Project.class))));
final String record = xmlRecordFactory.build(je);
final String xmlRecord = xmlRecordFactory.build(je);
assertNotNull(record);
assertNotNull(xmlRecord);
testRecordTransformation(record);
Document doc = new SAXReader().read(new StringReader(xmlRecord));
assertEquals("Article", doc.valueOf("//children/instance/instancetype/@classname"));
testRecordTransformation(xmlRecord);
}
@Test