use of io.openk9.entity.manager.model.payload.Response in project openk9 by smclab.
the class EntitySearchHTTPHandler method _searchHitToResponse.
private Response _searchHitToResponse(SearchHits searchHits) {
SearchHit[] hits = searchHits.getHits();
List<Map<String, Object>> result = new ArrayList<>(hits.length);
for (SearchHit hit : hits) {
Map<String, Object> sourceMap = new HashMap<>(hit.getSourceAsMap());
sourceMap.put("entityId", sourceMap.get("id"));
result.add(sourceMap);
}
TotalHits totalHits = searchHits.getTotalHits();
return new Response(result, totalHits.value);
}
use of io.openk9.entity.manager.model.payload.Response in project openk9 by smclab.
the class BaseSearchHTTPHandler method searchHitToResponse.
protected Object searchHitToResponse(SearchResponse searchResponse) {
SearchHits hits = searchResponse.getHits();
List<Map<String, Object>> result = new ArrayList<>();
for (SearchHit hit : hits.getHits()) {
Map<String, Object> sourceAsMap = hit.getSourceAsMap();
Map<String, Object> sourceMap = new HashMap<>(sourceAsMap.size() + 1, 1);
sourceMap.putAll(sourceAsMap);
sourceMap.put("id", hit.getId());
Map<String, HighlightField> highlightFields = hit.getHighlightFields();
Map<String, Object> highlightMap = new HashMap<>(highlightFields.size(), 1);
for (HighlightField value : highlightFields.values()) {
highlightMap.put(value.getName(), Arrays.stream(value.getFragments()).map(Text::string).toArray(String[]::new));
}
Map<String, Object> hitMap = new HashMap<>(2, 1);
hitMap.put("source", sourceMap);
hitMap.put("highlight", highlightMap);
result.add(hitMap);
}
TotalHits totalHits = hits.getTotalHits();
return new Response(result, totalHits.value);
}
use of io.openk9.entity.manager.model.payload.Response in project openk9 by smclab.
the class PluginDriverEndPoints method _findPluginDriverByName.
private Publisher<Void> _findPluginDriverByName(HttpServerRequest httpRequest, HttpServerResponse httpResponse) {
return Mono.defer(() -> {
String serviceDriverName = httpRequest.param("serviceDriverName");
PluginDriverDTO response = _pluginDriverDTOService.findPluginDriverDTOByName(serviceDriverName).orElseThrow(() -> new HttpException(404, "No Content. PluginDriver not found for serviceDriverName: " + serviceDriverName));
return Mono.from(_httpResponseWriter.write(httpResponse, response));
});
}
use of io.openk9.entity.manager.model.payload.Response in project openk9 by smclab.
the class EntityManagerConsumer method consume.
@Incoming("entity-manager-request")
@Outgoing("entity-manager-response")
@Blocking
public Message<JsonObject> consume(Object obj) throws InterruptedException {
JsonObject jsonObject = obj instanceof JsonObject ? (JsonObject) obj : new JsonObject(new String((byte[]) obj));
Payload payload = jsonObject.mapTo(Payload.class);
_entityManagerQueue.offer(payload, 45, TimeUnit.SECONDS);
String replyTo = payload.getReplyTo();
return Message.of(jsonObject, Metadata.of(new OutgoingRabbitMQMetadata.Builder().withRoutingKey(replyTo).withTimestamp(ZonedDateTime.now()).build()));
}
use of io.openk9.entity.manager.model.payload.Response 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);
}
Aggregations