use of io.openk9.plugin.driver.manager.model.PluginDriverDTO in project openk9 by smclab.
the class ReindexDatasourceConsumer method activate.
@Activate
void activate() {
RestHighLevelClient restHighLevelClient = _restHighLevelClientProvider.get();
_disposable = _datasourceEventConsumer.datasourceUpdateEvents().flatMap(datasource -> _pluginDriverManagerClient.getPluginDriver(datasource.getDriverServiceName()).onErrorResume(throwable -> {
if (_log.isErrorEnabled()) {
_log.error(throwable.getMessage());
}
return Mono.empty();
}).map(pluginDriverDTO -> Tuples.of(datasource, datasource.getTenantId() + "-" + pluginDriverDTO.getName() + "-data"))).filterWhen(t2 -> Mono.create(sink -> restHighLevelClient.indices().existsAsync(new GetIndexRequest(t2.getT2()), RequestOptions.DEFAULT, new ReactorActionListener<>(sink)))).flatMap(t2 -> Mono.<GetSettingsResponse>create(sink -> restHighLevelClient.indices().getSettingsAsync(new GetSettingsRequest().indices(t2.getT2()).names("index.creation_date"), RequestOptions.DEFAULT, new ReactorActionListener<>(sink))).map(response -> Tuples.of(t2.getT1(), t2.getT2(), Instant.ofEpochMilli(Long.parseLong(response.getSetting(t2.getT2(), "index.creation_date")))))).log().filter(t3 -> t3.getT1().getLastIngestionDate().isBefore(t3.getT3())).flatMap(t3 -> Mono.<AcknowledgedResponse>create(sink -> restHighLevelClient.indices().deleteAsync(new DeleteIndexRequest(t3.getT2()), RequestOptions.DEFAULT, new ReactorActionListener<>(sink)))).onErrorContinue((throwable, ignore) -> {
if (_log.isErrorEnabled()) {
_log.error(throwable.getMessage());
}
}).subscribe();
}
use of io.openk9.plugin.driver.manager.model.PluginDriverDTO in project openk9 by smclab.
the class SupportedDatasourcesEndpoint method _mapToResponse.
private SupportedDatasourcesResponse _mapToResponse(Tuple2<Datasource, PluginDriverDTO> t2) {
Datasource t1 = t2.getT1();
PluginDriverDTO pluginDriver = t2.getT2();
return SupportedDatasourcesResponse.of(t1.getName(), t1.getActive(), pluginDriver.getDocumentTypes().stream().map(documentTypeDTO -> SupportedDatasourcesDocumentType.of(documentTypeDTO.getName(), documentTypeDTO.getIcon())).collect(Collectors.toList()), SupportedDatasourcesDocumentType.of(pluginDriver.getDefaultDocumentType().getName(), pluginDriver.getDefaultDocumentType().getIcon()));
}
use of io.openk9.plugin.driver.manager.model.PluginDriverDTO in project openk9 by smclab.
the class DateOrderQueryParser method apply.
@Override
public Mono<Consumer<BoolQueryBuilder>> apply(Context context) {
return Mono.fromSupplier(() -> (bool) -> {
List<PluginDriverDTO> pluginDriverDocumentTypeList = context.getPluginDriverDocumentTypeList();
Iterator<String> iterator = pluginDriverDocumentTypeList.stream().map(PluginDriverDTO::getDocumentTypes).flatMap(Collection::stream).map(DocumentTypeDTO::getSearchKeywords).flatMap(Collection::stream).filter(SearchKeywordDTO::isDate).distinct().map(SearchKeywordDTO::getKeyword).iterator();
if (iterator.hasNext()) {
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.boost(_boost);
while (iterator.hasNext()) {
String keyword = iterator.next();
FunctionScoreQueryBuilder.FilterFunctionBuilder filterFunctionBuilder = new FunctionScoreQueryBuilder.FilterFunctionBuilder(ScoreFunctionBuilders.linearDecayFunction(keyword, null, _scale));
boolQueryBuilder.should(QueryBuilders.functionScoreQuery(QueryBuilders.existsQuery(keyword), new FunctionScoreQueryBuilder.FilterFunctionBuilder[] { filterFunctionBuilder }));
}
bool.should(boolQueryBuilder);
}
});
}
use of io.openk9.plugin.driver.manager.model.PluginDriverDTO in project openk9 by smclab.
the class DateQueryParser method _rangeQuery.
private void _rangeQuery(List<SearchToken> searchTokens, List<PluginDriverDTO> pluginDriverDocumentTypeList, BoolQueryBuilder bool) {
if (searchTokens.isEmpty()) {
return;
}
List<SearchKeywordToken> collect = pluginDriverDocumentTypeList.stream().map(PluginDriverDTO::getDocumentTypes).flatMap(Collection::stream).map(DocumentTypeDTO::getSearchKeywords).flatMap(Collection::stream).filter(SearchKeywordDTO::isDate).flatMap(searchKeywordDTO -> {
for (SearchToken searchToken : searchTokens) {
if (searchToken.getKeywordKey() != null && searchToken.getKeywordKey().equals(searchKeywordDTO.getKeyword())) {
return Stream.of(SearchKeywordToken.of(searchKeywordDTO, searchToken));
}
}
return Stream.empty();
}).collect(Collectors.toList());
if (!collect.isEmpty()) {
BoolQueryBuilder internalBool = QueryBuilders.boolQuery();
boolean flag = false;
for (SearchKeywordToken searchKeywordToken : collect) {
SearchToken searchToken = searchKeywordToken.getSearchToken();
Map<String, Object> extra = searchToken.getExtra();
if (extra == null) {
String[] values = searchToken.getValues();
String gte;
String lte;
if (values.length != 0) {
RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery(searchToken.getKeywordKey());
if (values.length == 1) {
gte = values[0];
rangeQueryBuilder.gte(gte);
} else if (values.length == 2) {
gte = values[0];
lte = values[1];
if (gte == null || gte.isBlank()) {
rangeQueryBuilder.lte(lte);
} else {
rangeQueryBuilder.gte(gte).lte(lte);
}
}
flag = true;
internalBool.should(rangeQueryBuilder);
}
} else {
Object gte = extra.get("gte");
Object lte = extra.get("lte");
Object lt = extra.get("lt");
Object gt = extra.get("gt");
String format = (String) extra.get("format");
String timeZone = (String) extra.get("time_zone");
String relation = (String) extra.get("relation");
RangeQueryBuilder rangeQueryBuilder = QueryBuilders.rangeQuery(searchToken.getKeywordKey());
if (gte != null) {
rangeQueryBuilder.gte(gte);
}
if (lte != null) {
rangeQueryBuilder.lte(lte);
}
if (gt != null) {
rangeQueryBuilder.gt(gt);
}
if (lt != null) {
rangeQueryBuilder.lt(lt);
}
if (format != null) {
rangeQueryBuilder.format(format);
}
if (timeZone != null) {
rangeQueryBuilder.timeZone(timeZone);
}
if (relation != null && (relation.equals("INTERSECTS") || relation.equals("CONTAINS") || relation.equals("WITHIN"))) {
rangeQueryBuilder.relation(relation);
}
flag = true;
internalBool.should(rangeQueryBuilder);
}
}
if (flag) {
bool.must(internalBool);
}
}
}
use of io.openk9.plugin.driver.manager.model.PluginDriverDTO in project openk9 by smclab.
the class DocumentTypesEndpoint method _mapToResponse.
private Object _mapToResponse(List<Tuple2<Datasource, PluginDriverDTO>> list) {
Map<String, Collection<String>> response = new HashMap<>();
for (Tuple2<Datasource, PluginDriverDTO> t2 : list) {
PluginDriverDTO pluginDriver = t2.getT2();
for (DocumentTypeDTO documentType : pluginDriver.getDocumentTypes()) {
String name = documentType.getName();
List<SearchKeywordDTO> searchKeywords = documentType.getSearchKeywords();
List<String> keywords = searchKeywords.stream().map(SearchKeywordDTO::getKeyword).collect(Collectors.toList());
Collection<String> prevKeywords = response.get(name);
Set<String> combine = new HashSet<>(keywords);
if (prevKeywords != null) {
combine.addAll(prevKeywords);
}
response.put(name, combine);
}
}
return response;
}
Aggregations