use of io.openk9.json.api.ObjectNode 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.json.api.ObjectNode in project openk9 by smclab.
the class InsertIndexWriter method _createDocWriterRequest.
private Mono<DocWriteRequest> _createDocWriterRequest(String indexName, ObjectNode enrichProcessorContext) {
return Mono.defer(() -> {
ObjectNode objectNode = enrichProcessorContext.get("payload").toObjectNode();
String contentId = objectNode.get("contentId").asText();
return _search.search(factory -> {
SearchRequest searchRequest = new SearchRequest(indexName);
MatchQueryBuilder matchQueryBuilder = QueryBuilders.matchQuery("contentId", contentId);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(matchQueryBuilder);
return searchRequest.source(searchSourceBuilder);
}).onErrorReturn(SearchUtil.EMPTY_SEARCH_RESPONSE).filter(e -> e.getHits().getHits().length > 0).flatMapIterable(SearchResponse::getHits).next().map(e -> new UpdateRequest(indexName, e.getId()).doc(objectNode.toString(), XContentType.JSON)).cast(DocWriteRequest.class).switchIfEmpty(Mono.fromSupplier(() -> new IndexRequest(indexName).source(objectNode.toString(), XContentType.JSON)));
});
}
use of io.openk9.json.api.ObjectNode in project openk9 by smclab.
the class InsertIndexWriter method activate.
@Activate
void activate() {
_disposable = _receiverReactor.consumeAutoAck(_binding.getQueue()).flatMap(delivery -> {
ObjectNode enrichProcessorContext = _jsonFactory.fromJsonToJsonNode(delivery.getBody()).toObjectNode();
String routingKey = delivery.getEnvelope().getRoutingKey();
long tenantId = enrichProcessorContext.get("datasourceContext").get("tenant").get("tenantId").asLong();
String pluginDriverName = enrichProcessorContext.get("pluginDriver").get("name").asText();
String indexName = String.join("-", Long.toString(tenantId), pluginDriverName, "data");
if (routingKey.endsWith("entity")) {
return Mono.fromSupplier(() -> new IndexRequest(indexName).source(enrichProcessorContext.toString(), XContentType.JSON));
}
return _createDocWriterRequest(indexName, enrichProcessorContext);
}).onErrorContinue(this::_manageExceptions).doOnNext(_indexBus::sendRequest).subscribe();
}
use of io.openk9.json.api.ObjectNode 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.json.api.ObjectNode 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