integration of openaire-solr-payload-mapper
This commit is contained in:
parent
f0dc26ca79
commit
541350e9e0
6
pom.xml
6
pom.xml
|
@ -162,6 +162,12 @@
|
|||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>eu.dnetlib.dhp</groupId>
|
||||
<artifactId>openaire-solr-payload-mapper</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Postgres Driver -->
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
|
|
|
@ -21,6 +21,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
|
||||
import eu.dnetlib.app.directindex.errors.DirectIndexApiException;
|
||||
import eu.dnetlib.dhp.schema.solr.SolrRecord;
|
||||
import eu.dnetlib.dhp.solr.mapping.SolrInputDocumentMapper;
|
||||
|
||||
public class SolrIndexClient {
|
||||
|
||||
|
@ -34,7 +35,7 @@ public class SolrIndexClient {
|
|||
|
||||
public void addRecords(final Stream<SolrRecord> records) throws DirectIndexApiException {
|
||||
try {
|
||||
solrClient.add(records.map(this::prepareSolrDocument).iterator());
|
||||
solrClient.add(records.map(this::prepareSolrDocument).filter(o -> o != null).iterator());
|
||||
solrClient.commit();
|
||||
} catch (final Throwable e) {
|
||||
throw new DirectIndexApiException("Error creating solr document", e);
|
||||
|
@ -58,13 +59,12 @@ public class SolrIndexClient {
|
|||
}
|
||||
|
||||
private SolrInputDocument prepareSolrDocument(final SolrRecord record) {
|
||||
|
||||
final String xml = XMLSolrSerializer.generateXML(record);
|
||||
|
||||
// TODO (usare classe condivisa preparata da Claudio)
|
||||
|
||||
return null;
|
||||
|
||||
try {
|
||||
return SolrInputDocumentMapper.map(record, XMLSolrSerializer.generateXML(record));
|
||||
} catch (final Throwable e) {
|
||||
log.error("Error preparing solr record", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public SolrRecord findRecord(final String id) throws DirectIndexApiException {
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
package eu.dnetlib.app.directindex.solr;
|
||||
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentHelper;
|
||||
import org.dom4j.Element;
|
||||
|
||||
import eu.dnetlib.dhp.schema.solr.SolrRecord;
|
||||
|
||||
public class XMLSolrSerializer {
|
||||
|
||||
public static String generateXML(final SolrRecord record) {
|
||||
final Document doc = DocumentHelper.createDocument();
|
||||
final Element root = DocumentHelper.createElement("record");
|
||||
|
||||
// TODO
|
||||
|
||||
return doc.asXML();
|
||||
return DocumentHelper.createDocument(root).asXML();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue