use of io.openk9.plugin.driver.manager.model.PluginDriverDTO in project openk9 by smclab.
the class SuggestionsHTTPHandler method customizeSearchSourceBuilderMono.
@Override
protected Mono<org.elasticsearch.action.search.SearchRequest> customizeSearchSourceBuilderMono(Tenant tenant, List<Datasource> datasources, SearchRequest searchRequest, List<PluginDriverDTO> documentTypeList, SearchSourceBuilder searchSourceBuilder, org.elasticsearch.action.search.SearchRequest elasticSearchQuery) {
return Mono.defer(() -> {
Long suggestionCategoryId = searchRequest.getSuggestionCategoryId();
if (suggestionCategoryId == null) {
return _datasourceClient.findSuggestionCategoryFieldsByTenantId(tenant.getTenantId());
} else {
return _datasourceClient.findSuggestionCategoryFieldsByTenantIdAndCategoryId(tenant.getTenantId(), suggestionCategoryId);
}
}).map(fields -> {
if (!(fields == null || fields.isEmpty())) {
Function<String, CompositeValuesSourceBuilder<?>> fieldToTerms = nameField -> new TermsValuesSourceBuilder(nameField).field(nameField).missingBucket(true);
CompositeAggregationBuilder compositeAggregation = fields.stream().map(SuggestionCategoryField::getFieldName).map(fieldToTerms).collect(Collectors.collectingAndThen(Collectors.toList(), list -> AggregationBuilders.composite("composite", list)));
String afterKey = searchRequest.getAfterKey();
if (afterKey != null) {
byte[] afterKeyDecoded = Base64.getDecoder().decode(afterKey);
Map<String, Object> map = _jsonFactory.fromJsonMap(new String(afterKeyDecoded), Object.class);
compositeAggregation.aggregateAfter(map);
}
int[] range = searchRequest.getRange();
if (range != null && range.length == 2) {
int size = range[1];
compositeAggregation.size(size);
}
searchSourceBuilder.aggregation(compositeAggregation);
}
searchSourceBuilder.from(0);
searchSourceBuilder.size(0);
searchSourceBuilder.highlighter(null);
return elasticSearchQuery.source(searchSourceBuilder);
});
}
use of io.openk9.plugin.driver.manager.model.PluginDriverDTO in project openk9 by smclab.
the class JsEnrichProcessor method prepareRequestRawContent.
protected ObjectNode prepareRequestRawContent(ObjectNode objectNode, ObjectNode datasourceConfiguration, DatasourceContext context, PluginDriverDTO pluginDriverDTO) {
JsonNode rawContentNode = objectNode.get(Constants.RAW_CONTENT);
JsonNode codeNode = datasourceConfiguration.get(Constants.CODE);
ObjectNode request = _jsonFactory.createObjectNode();
request.put(Constants.CODE, codeNode);
request.put(Constants.CONTENT, rawContentNode);
JsonNode typeNode = objectNode.get(Constants.TYPE);
ObjectNode datasourcePayload = _jsonFactory.createObjectNode();
if (typeNode != null && typeNode.isArray()) {
ArrayNode types = typeNode.toArrayNode();
for (JsonNode typeJsonNode : types) {
String type = typeJsonNode.asText();
datasourcePayload.put(type, objectNode.get(type));
}
}
request.put(Constants.DATASOURCE_PAYLOAD, datasourcePayload);
request.put(Constants.TENANT_ID, context.getTenant().getTenantId());
request.put(Constants.DATASOURCE_ID, context.getDatasource().getDatasourceId());
request.put(Constants.CONTENT_ID, objectNode.get(Constants.CONTENT_ID));
return request;
}
use of io.openk9.plugin.driver.manager.model.PluginDriverDTO in project openk9 by smclab.
the class IndexWriterEndpoins method _deleteDataDocuments.
private Publisher<Void> _deleteDataDocuments(HttpServerRequest httpServerRequest, HttpServerResponse httpServerResponse) {
RestHighLevelClient restHighLevelClient = _restHighLevelClientProvider.get();
Mono<byte[]> body = ReactorNettyUtils.aggregateBodyAsByteArray(httpServerRequest);
Mono<String> responseMono = body.map(bytes -> _jsonFactory.fromJson(bytes, DeleteEntitiesRequest.class)).flatMap(deleteEntitiesRequest -> {
if (!deleteEntitiesRequest.getContentIds().isEmpty()) {
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
for (String contentId : deleteEntitiesRequest.getContentIds()) {
boolQuery.mustNot(matchQuery("contentId", contentId));
}
Mono<Datasource> datasourceMono = _datasourceClient.findDatasource(deleteEntitiesRequest.getDatasourceId());
return datasourceMono.flatMap(datasource -> _pluginDriverManagerClient.getPluginDriver(datasource.getDriverServiceName()).map(pluginDriverDTO -> datasource.getTenantId() + "-" + pluginDriverDTO.getName() + "-data").map(DeleteByQueryRequest::new).map(deleteByQueryRequest -> deleteByQueryRequest.setQuery(boolQuery)).flatMap(deleteByQueryRequest -> Mono.<BulkByScrollResponse>create(sink -> restHighLevelClient.deleteByQueryAsync(deleteByQueryRequest, RequestOptions.DEFAULT, new ReactorActionListener<>(sink)))).map(Object::toString).doOnNext(_log::info).flatMap(response -> Mono.fromRunnable(() -> _sendCleanOrphanEntitiesRequest(datasource.getTenantId())).thenReturn(response)));
}
return Mono.empty();
});
return _httpResponseWriter.write(httpServerResponse, responseMono);
}
use of io.openk9.plugin.driver.manager.model.PluginDriverDTO in project openk9 by smclab.
the class EnrichPipelineProcessor method _mapToEnrichProcessorContext.
private ObjectNode _mapToEnrichProcessorContext(Tuple3<DatasourceContext, ObjectNode, PluginDriverDTO> t3) {
List<String> dependencies = t3.getT1().getEnrichItems().stream().map(EnrichItem::getServiceName).collect(Collectors.toList());
ObjectNode objectNode = _jsonFactory.createObjectNode();
objectNode.put("pluginDriver", _jsonFactory.fromObjectToJsonNode(t3.getT3()));
objectNode.put("dependencies", _jsonFactory.fromObjectToJsonNode(dependencies));
objectNode.put("datasourceContext", _jsonFactory.fromObjectToJsonNode(t3.getT1()));
objectNode.put("payload", t3.getT2());
return objectNode;
}
use of io.openk9.plugin.driver.manager.model.PluginDriverDTO in project openk9 by smclab.
the class EnrichPipelineProcessor method _adaptIngestionPayload.
private Tuple3<DatasourceContext, ObjectNode, PluginDriverDTO> _adaptIngestionPayload(DatasourceContext datasourceContext, ObjectNode ingestionPayload, PluginDriverDTO pluginDriverDTO) {
ObjectNode newIngestionPayload = ingestionPayload;
if (newIngestionPayload.hasNonNull(io.openk9.core.api.constant.Constants.DATASOURCE_PAYLOAD)) {
JsonNode datasourcePayload = newIngestionPayload.remove(io.openk9.core.api.constant.Constants.DATASOURCE_PAYLOAD);
if (datasourcePayload.isObject()) {
ObjectNode jsonNodes = datasourcePayload.toObjectNode();
for (Map.Entry<String, JsonNode> field : jsonNodes.fields()) {
newIngestionPayload.set(field.getKey(), field.getValue());
}
}
}
if (!ingestionPayload.hasNonNull(Constants.DATASOURCE_NAME)) {
newIngestionPayload = newIngestionPayload.deepCopy().put(Constants.DATASOURCE_NAME, pluginDriverDTO.getName());
}
if (ingestionPayload.hasNonNull(io.openk9.core.api.constant.Constants.TYPE) && !ingestionPayload.get(io.openk9.core.api.constant.Constants.TYPE).toArrayNode().isEmpty()) {
return Tuples.of(datasourceContext, ingestionPayload, pluginDriverDTO);
}
DocumentTypeDTO documentType = pluginDriverDTO.getDefaultDocumentType();
return Tuples.of(datasourceContext, newIngestionPayload.set(io.openk9.core.api.constant.Constants.TYPE, _jsonFactory.createArrayNode().add(documentType.getName())), pluginDriverDTO);
}
Aggregations