Search in sources :

Example 6 with ArrayNode

use of io.openk9.json.api.ArrayNode in project openk9 by smclab.

the class ApplicationPluginDriver method invokeDataParser.

@Override
public Publisher<Void> invokeDataParser(Datasource datasource, Date fromDate, Date toDate) {
    JsonNode jsonNode = _jsonFactory.fromJsonToJsonNode(datasource.getJsonConfig());
    if (jsonNode.isArray()) {
        ArrayNode arrayJson = jsonNode.toArrayNode();
        for (int i = 0; i < arrayJson.size(); i++) {
            JsonNode node = arrayJson.get(i);
            if (node.hasNonNull("title")) {
                node = node.toObjectNode().set("applicationName", node.get("title"));
            }
            _ingestionLogicSender.send(IngestionPayload.builder().ingestionId(UUID.randomUUID().toString()).datasourceId(datasource.getDatasourceId()).rawContent(node.toString()).contentId(Integer.toString(i)).tenantId(datasource.getTenantId()).datasourcePayload(_jsonFactory.createObjectNode().set(getName(), node.toObjectNode()).toMap()).parsingDate(toDate.getTime()).documentTypes(new String[] { getName() }).build());
        }
    }
    return Mono.empty();
}
Also used : JsonNode(io.openk9.json.api.JsonNode) ArrayNode(io.openk9.json.api.ArrayNode)

Example 7 with ArrayNode

use of io.openk9.json.api.ArrayNode 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;
}
Also used : ObjectNode(io.openk9.json.api.ObjectNode) JsonNode(io.openk9.json.api.JsonNode) ArrayNode(io.openk9.json.api.ArrayNode)

Example 8 with ArrayNode

use of io.openk9.json.api.ArrayNode in project openk9 by smclab.

the class BaseNerEnrichProcessor method _getEntityOrCreate.

private Mono<JsonNode> _getEntityOrCreate(ObjectNode jsonNode) {
    return _entityManagerClient.getOrAddEntities(_jsonFactory.fromJsonNode(jsonNode, Request.class)).map(httpResponse -> {
        List<Response> responseList = httpResponse.getResponse();
        JsonNode entitiesJsonNode = jsonNode.get(entitiesField());
        ArrayNode entitiesArrayNode = entitiesJsonNode.toArrayNode();
        ArrayNode arrayNode = _jsonFactory.createArrayNode();
        for (JsonNode node : entitiesArrayNode) {
            Optional<Response> responseOptional = responseList.stream().filter(response -> node.get("tmpId").asLong() == response.getTmpId()).findFirst();
            if (responseOptional.isPresent()) {
                Entity entity = responseOptional.get().getEntity();
                ObjectNode result = _jsonFactory.createObjectNode();
                result.put("entityType", entity.getType());
                result.put("id", entity.getId());
                result.put("context", node.get("context"));
                arrayNode.add(result);
            }
        }
        return arrayNode;
    });
}
Also used : Response(io.openk9.entity.manager.model.payload.Response) EnrichItem(io.openk9.model.EnrichItem) PluginDriverDTO(io.openk9.plugin.driver.manager.model.PluginDriverDTO) Response(io.openk9.entity.manager.model.payload.Response) JsonNode(io.openk9.json.api.JsonNode) Mono(reactor.core.publisher.Mono) Entity(io.openk9.entity.manager.model.Entity) ArrayNode(io.openk9.json.api.ArrayNode) JsonFactory(io.openk9.json.api.JsonFactory) DatasourceContext(io.openk9.model.DatasourceContext) List(java.util.List) EntityManagerClient(io.openk9.entity.manager.client.api.EntityManagerClient) Map(java.util.Map) Optional(java.util.Optional) Request(io.openk9.entity.manager.model.payload.Request) ObjectNode(io.openk9.json.api.ObjectNode) HttpClient(io.openk9.http.client.HttpClient) Constants(io.openk9.core.api.constant.Constants) Entity(io.openk9.entity.manager.model.Entity) ObjectNode(io.openk9.json.api.ObjectNode) JsonNode(io.openk9.json.api.JsonNode) ArrayNode(io.openk9.json.api.ArrayNode)

Aggregations

ArrayNode (io.openk9.json.api.ArrayNode)8 JsonNode (io.openk9.json.api.JsonNode)7 ObjectNode (io.openk9.json.api.ObjectNode)4 Entity (io.openk9.entity.manager.model.Entity)2 Request (io.openk9.entity.manager.model.payload.Request)2 Response (io.openk9.entity.manager.model.payload.Response)2 JsonFactory (io.openk9.json.api.JsonFactory)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Optional (java.util.Optional)2 Constants (io.openk9.core.api.constant.Constants)1 EntityManagerClient (io.openk9.entity.manager.client.api.EntityManagerClient)1 EntityRequest (io.openk9.entity.manager.model.payload.EntityRequest)1 RelationRequest (io.openk9.entity.manager.model.payload.RelationRequest)1 ResponseList (io.openk9.entity.manager.model.payload.ResponseList)1 HttpClient (io.openk9.http.client.HttpClient)1 Binding (io.openk9.ingestion.api.Binding)1 BundleSender (io.openk9.ingestion.api.BundleSender)1 OutboundMessageFactory (io.openk9.ingestion.api.OutboundMessageFactory)1 ReceiverReactor (io.openk9.ingestion.api.ReceiverReactor)1