integration of openaire-solr-payload-mapper

This commit is contained in:
Michele Artini 2024-12-05 12:35:28 +01:00
parent f0dc26ca79
commit 541350e9e0
3 changed files with 17 additions and 11 deletions

View File

@ -162,6 +162,12 @@
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>eu.dnetlib.dhp</groupId>
<artifactId>openaire-solr-payload-mapper</artifactId>
<version>1.0.0</version>
</dependency>
<!-- Postgres Driver --> <!-- Postgres Driver -->
<dependency> <dependency>
<groupId>org.postgresql</groupId> <groupId>org.postgresql</groupId>

View File

@ -21,6 +21,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import eu.dnetlib.app.directindex.errors.DirectIndexApiException; import eu.dnetlib.app.directindex.errors.DirectIndexApiException;
import eu.dnetlib.dhp.schema.solr.SolrRecord; import eu.dnetlib.dhp.schema.solr.SolrRecord;
import eu.dnetlib.dhp.solr.mapping.SolrInputDocumentMapper;
public class SolrIndexClient { public class SolrIndexClient {
@ -34,7 +35,7 @@ public class SolrIndexClient {
public void addRecords(final Stream<SolrRecord> records) throws DirectIndexApiException { public void addRecords(final Stream<SolrRecord> records) throws DirectIndexApiException {
try { try {
solrClient.add(records.map(this::prepareSolrDocument).iterator()); solrClient.add(records.map(this::prepareSolrDocument).filter(o -> o != null).iterator());
solrClient.commit(); solrClient.commit();
} catch (final Throwable e) { } catch (final Throwable e) {
throw new DirectIndexApiException("Error creating solr document", e); throw new DirectIndexApiException("Error creating solr document", e);
@ -58,13 +59,12 @@ public class SolrIndexClient {
} }
private SolrInputDocument prepareSolrDocument(final SolrRecord record) { private SolrInputDocument prepareSolrDocument(final SolrRecord record) {
try {
final String xml = XMLSolrSerializer.generateXML(record); return SolrInputDocumentMapper.map(record, XMLSolrSerializer.generateXML(record));
} catch (final Throwable e) {
// TODO (usare classe condivisa preparata da Claudio) log.error("Error preparing solr record", e);
return null;
return null; }
} }
public SolrRecord findRecord(final String id) throws DirectIndexApiException { public SolrRecord findRecord(final String id) throws DirectIndexApiException {

View File

@ -1,18 +1,18 @@
package eu.dnetlib.app.directindex.solr; package eu.dnetlib.app.directindex.solr;
import org.dom4j.Document;
import org.dom4j.DocumentHelper; import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import eu.dnetlib.dhp.schema.solr.SolrRecord; import eu.dnetlib.dhp.schema.solr.SolrRecord;
public class XMLSolrSerializer { public class XMLSolrSerializer {
public static String generateXML(final SolrRecord record) { public static String generateXML(final SolrRecord record) {
final Document doc = DocumentHelper.createDocument(); final Element root = DocumentHelper.createElement("record");
// TODO // TODO
return doc.asXML(); return DocumentHelper.createDocument(root).asXML();
} }
} }