Revision 57157
Added by Enrico Ottonello over 4 years ago
SolrDocumentMapperFactory.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.util.Map; |
4 | 4 |
import java.util.function.Function; |
5 |
|
|
5 | 6 |
import javax.xml.stream.XMLStreamException; |
6 | 7 |
|
8 |
import org.springframework.beans.factory.annotation.Required; |
|
9 |
|
|
7 | 10 |
import eu.dnetlib.clients.index.model.Any.ValueType; |
8 | 11 |
import eu.dnetlib.clients.index.model.document.IndexDocument; |
9 | 12 |
import eu.dnetlib.clients.index.model.document.Status; |
10 |
import eu.dnetlib.utils.MetadataReference; |
|
11 | 13 |
import eu.dnetlib.index.feed.DocumentMapperFactory; |
12 | 14 |
import eu.dnetlib.index.solr.model.SolrIndexDocument; |
13 |
import org.springframework.beans.factory.annotation.Required;
|
|
15 |
import eu.dnetlib.utils.MetadataReference;
|
|
14 | 16 |
|
15 | 17 |
/** |
16 | 18 |
* A factory for creating SolrDocumentMapper objects. |
17 | 19 |
*/ |
18 | 20 |
public class SolrDocumentMapperFactory implements DocumentMapperFactory { |
19 | 21 |
|
20 |
protected static final String DNETRESULT = "result";
|
|
21 |
/**
|
|
22 |
* document factory used for the feed process.
|
|
23 |
*/
|
|
24 |
private InputDocumentFactory documentFactory;
|
|
22 |
protected static final String DNETRESULT = "result";
|
|
23 |
/**
|
|
24 |
* document factory used for the feed process.
|
|
25 |
*/
|
|
26 |
private InputDocumentFactory documentFactory;
|
|
25 | 27 |
|
26 |
private Function<String, IndexDocument> getRecordMapper(final Map<String, ValueType> schema, |
|
27 |
final String dsId, |
|
28 |
final String version) { |
|
29 | 28 |
|
30 |
return doc -> { |
|
31 |
SolrIndexDocument indexDocument = new SolrIndexDocument(schema, dsId); |
|
32 |
try { |
|
33 |
indexDocument.setContent(documentFactory.parseDocument(version, doc, dsId, DNETRESULT)); |
|
34 |
} catch (XMLStreamException e) { |
|
35 |
return indexDocument.setMarked(); |
|
36 |
} |
|
37 |
indexDocument.setStatus(Status.OK); |
|
38 |
return indexDocument; |
|
39 |
}; |
|
40 |
} |
|
29 |
private Function<String, IndexDocument> getRecordMapper(final Map<String, ValueType> schema, |
|
30 |
final String dsId, |
|
31 |
final String version) { |
|
41 | 32 |
|
42 |
@Override
|
|
43 |
public Function<String, IndexDocument> getRecordMapper(final Map<String, ValueType> schema,
|
|
44 |
final MetadataReference mdRef,
|
|
45 |
final String dsId,
|
|
46 |
final String version,
|
|
47 |
final boolean emptyResult) {
|
|
48 |
if (!emptyResult) return getRecordMapper(schema, dsId, version);
|
|
49 |
else {
|
|
50 |
return doc -> {
|
|
51 |
SolrIndexDocument indexDocument = new SolrIndexDocument(schema, dsId);
|
|
52 |
try {
|
|
33 |
return doc -> {
|
|
34 |
SolrIndexDocument indexDocument = new SolrIndexDocument(schema, dsId);
|
|
35 |
try {
|
|
36 |
indexDocument.setContent(documentFactory.parseDocument(version, doc, dsId, DNETRESULT));
|
|
37 |
} catch (XMLStreamException e) {
|
|
38 |
return indexDocument.setMarked();
|
|
39 |
}
|
|
40 |
indexDocument.setStatus(Status.OK);
|
|
41 |
return indexDocument;
|
|
42 |
};
|
|
43 |
}
|
|
53 | 44 |
|
54 |
ResultTransformer transformer = new ResultTransformer(ResultTransformer.Mode.empty) { |
|
55 |
@Override |
|
56 |
public String apply(String input) { |
|
57 |
return input; |
|
58 |
} |
|
59 |
}; |
|
60 |
indexDocument.setContent(documentFactory.parseDocument(version, doc, dsId, DNETRESULT, transformer)); |
|
61 |
} catch (XMLStreamException e) { |
|
62 |
return indexDocument.setMarked(); |
|
63 |
} |
|
64 |
indexDocument.setStatus(Status.OK); |
|
65 |
return indexDocument; |
|
66 |
}; |
|
67 |
} |
|
68 |
} |
|
45 |
@Override |
|
46 |
public Function<String, IndexDocument> getRecordMapper(final Map<String, ValueType> schema, final MetadataReference mdRef, final String dsId, final String version, final boolean emptyResult) { |
|
47 |
if (emptyResult == false) return getRecordMapper(schema, dsId, version); |
|
48 |
else { |
|
49 |
return doc -> { |
|
50 |
SolrIndexDocument indexDocument = new SolrIndexDocument(schema, dsId); |
|
51 |
try { |
|
69 | 52 |
|
70 |
/** |
|
71 |
* Gets the document factory. |
|
72 |
* |
|
73 |
* @return the documentFactory |
|
74 |
*/ |
|
75 |
public InputDocumentFactory getDocumentFactory() { |
|
76 |
return documentFactory; |
|
77 |
} |
|
53 |
ResultTransformer transformer = new ResultTransformer(ResultTransformer.Mode.empty) { |
|
54 |
@Override |
|
55 |
public String apply(String input) { |
|
56 |
return input; |
|
57 |
} |
|
58 |
}; |
|
59 |
indexDocument.setContent(documentFactory.parseDocument(version, doc, dsId, DNETRESULT, transformer)); |
|
60 |
} catch (XMLStreamException e) { |
|
61 |
return indexDocument.setMarked(); |
|
62 |
} |
|
63 |
indexDocument.setStatus(Status.OK); |
|
64 |
return indexDocument; |
|
65 |
}; |
|
66 |
} |
|
67 |
} |
|
78 | 68 |
|
79 |
/** |
|
80 |
* Sets the document factory. |
|
81 |
* |
|
82 |
* @param documentFactory the documentFactory to set |
|
83 |
*/ |
|
84 |
@Required |
|
85 |
public void setDocumentFactory(final InputDocumentFactory documentFactory) { |
|
86 |
this.documentFactory = documentFactory; |
|
87 |
} |
|
69 |
/** |
|
70 |
* Gets the document factory. |
|
71 |
* |
|
72 |
* @return the documentFactory |
|
73 |
*/ |
|
74 |
public InputDocumentFactory getDocumentFactory() { |
|
75 |
return documentFactory; |
|
76 |
} |
|
88 | 77 |
|
78 |
/** |
|
79 |
* Sets the document factory. |
|
80 |
* |
|
81 |
* @param documentFactory the documentFactory to set |
|
82 |
*/ |
|
83 |
@Required |
|
84 |
public void setDocumentFactory(final InputDocumentFactory documentFactory) { |
|
85 |
this.documentFactory = documentFactory; |
|
86 |
} |
|
87 |
|
|
89 | 88 |
} |
Also available in: Unified diff
solr 772 integration