use of io.georocket.index.xml.MetaIndexer in project georocket by georocket.
the class IndexerVerticle method openChunkToDocument.
/**
* Open a chunk and convert it to an Elasticsearch document. Retry operation
* several times before failing.
* @param path the path to the chunk to open
* @param chunkMeta metadata about the chunk
* @param indexMeta metadata used to index the chunk
* @return an observable that emits the document
*/
private Observable<Map<String, Object>> openChunkToDocument(String path, ChunkMeta chunkMeta, IndexMeta indexMeta) {
return Observable.defer(() -> store.rxGetOne(path).flatMapObservable(chunk -> {
List<? extends IndexerFactory> factories;
Operator<? extends StreamEvent, Buffer> parserOperator;
// select indexers and parser depending on the mime type
String mimeType = chunkMeta.getMimeType();
if (belongsTo(mimeType, "application", "xml") || belongsTo(mimeType, "text", "xml")) {
factories = xmlIndexerFactories;
parserOperator = new XMLParserOperator();
} else if (belongsTo(mimeType, "application", "json")) {
factories = jsonIndexerFactories;
parserOperator = new JsonParserOperator();
} else {
return Observable.error(new NoStackTraceThrowable(String.format("Unexpected mime type '%s' while trying to index " + "chunk '%s'", mimeType, path)));
}
// call meta indexers
Map<String, Object> metaResults = new HashMap<>();
for (MetaIndexerFactory metaIndexerFactory : metaIndexerFactories) {
MetaIndexer metaIndexer = metaIndexerFactory.createIndexer();
metaIndexer.onIndexChunk(path, chunkMeta, indexMeta);
metaResults.putAll(metaIndexer.getResult());
}
// convert chunk to document and close it
return chunkToDocument(chunk, indexMeta.getFallbackCRSString(), parserOperator, factories).doAfterTerminate(chunk::close).doOnNext(doc -> doc.putAll(metaResults));
})).retryWhen(makeRetry());
}
Aggregations