Search in sources :

Example 1 with EnrichItem

use of io.openk9.model.EnrichItem in project openk9 by smclab.

the class JsEnrichProcessor method process.

@Override
public Mono<ObjectNode> process(ObjectNode objectNode, DatasourceContext context, EnrichItem enrichItem, PluginDriverDTO pluginDriverName) {
    return Mono.defer(() -> {
        JsonNode datasourceConfiguration = _jsonFactory.fromJsonToJsonNode(enrichItem.getJsonConfig());
        if (!datasourceConfiguration.isObject()) {
            return Mono.error(new RuntimeException("jsonConfig must be an instance of ObjectNode " + datasourceConfiguration.toString()));
        }
        ObjectNode request = prepareRequestRawContent(objectNode, datasourceConfiguration.toObjectNode(), context, pluginDriverName);
        return Mono.from(_httpClient.request(getMethod(), getPath(), request.toString(), getHeaders())).map(_jsonFactory::fromJsonToJsonNode).map(JsonNode::toObjectNode).map(objectNode::merge);
    });
}
Also used : ObjectNode(io.openk9.json.api.ObjectNode) JsonNode(io.openk9.json.api.JsonNode)

Example 2 with EnrichItem

use of io.openk9.model.EnrichItem in project openk9 by smclab.

the class DatasourceProcessor method process.

@Incoming("ingestion")
@Outgoing("ingestion-datasource")
public Uni<IngestionDatasourcePayload> process(Object obj) {
    JsonObject jsonObject = obj instanceof JsonObject ? (JsonObject) obj : new JsonObject(new String((byte[]) obj));
    long datasourceId = jsonObject.getLong("datasourceId");
    Uni<Datasource> datasourceUni = Datasource.findById(datasourceId);
    return Panache.withTransaction(() -> datasourceUni.flatMap(datasource -> EnrichPipeline.findByDatasourceId(datasource.getDatasourceId()).onItem().ifNull().continueWith(EnrichPipeline::new).flatMap(enrichPipeline -> {
        Uni<List<EnrichItem>> enrichItemUni;
        if (enrichPipeline.getEnrichPipelineId() != null) {
            enrichItemUni = EnrichItem.findByEnrichPipelineId(enrichPipeline.getEnrichPipelineId()).onItem().ifNull().continueWith(List::of);
        } else {
            enrichItemUni = Uni.createFrom().item(List.of());
        }
        return Uni.combine().all().unis(Tenant.findById(datasource.getTenantId()), enrichItemUni).combinedWith((tenantObj, enrichItemList) -> {
            Tenant tenant = (Tenant) tenantObj;
            IngestionPayload ingestionPayload = jsonObject.mapTo(IngestionPayload.class);
            ingestionPayload.setTenantId(tenant.getTenantId());
            DatasourceContext datasourceContext = DatasourceContext.of(datasource, tenant, enrichPipeline, enrichItemList);
            return IngestionDatasourcePayload.of(ingestionPayload, datasourceContext);
        });
    })).eventually(() -> Datasource.<Datasource>findById(datasourceId).flatMap(datasource -> {
        datasource.setLastIngestionDate(Instant.ofEpochMilli(jsonObject.getLong("parsingDate")));
        return datasource.persist();
    })));
}
Also used : Datasource(io.openk9.datasource.model.Datasource) Outgoing(org.eclipse.microprofile.reactive.messaging.Outgoing) Datasource(io.openk9.datasource.model.Datasource) EnrichItem(io.openk9.datasource.model.EnrichItem) Tenant(io.openk9.datasource.model.Tenant) Instant(java.time.Instant) Uni(io.smallrye.mutiny.Uni) DatasourceContext(io.openk9.datasource.processor.payload.DatasourceContext) List(java.util.List) IngestionDatasourcePayload(io.openk9.datasource.processor.payload.IngestionDatasourcePayload) IngestionPayload(io.openk9.datasource.processor.payload.IngestionPayload) EnrichPipeline(io.openk9.datasource.model.EnrichPipeline) JsonObject(io.vertx.core.json.JsonObject) ApplicationScoped(javax.enterprise.context.ApplicationScoped) Panache(io.quarkus.hibernate.reactive.panache.Panache) Incoming(org.eclipse.microprofile.reactive.messaging.Incoming) JsonObject(io.vertx.core.json.JsonObject) EnrichItem(io.openk9.datasource.model.EnrichItem) Uni(io.smallrye.mutiny.Uni) Tenant(io.openk9.datasource.model.Tenant) IngestionPayload(io.openk9.datasource.processor.payload.IngestionPayload) DatasourceContext(io.openk9.datasource.processor.payload.DatasourceContext) EnrichPipeline(io.openk9.datasource.model.EnrichPipeline) List(java.util.List) Incoming(org.eclipse.microprofile.reactive.messaging.Incoming) Outgoing(org.eclipse.microprofile.reactive.messaging.Outgoing)

Example 3 with EnrichItem

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

Example 4 with EnrichItem

use of io.openk9.model.EnrichItem in project openk9 by smclab.

the class InitDataActivator method activate.

@Activate
void activate(BundleContext bundleContext) throws Exception {
    Bundle bundle = bundleContext.getBundle();
    Tenant tenant = _jsonFileToObj(bundle, "tenant.json", Tenant.class);
    Datasource datasource = _jsonFileToObj(bundle, "datasource.json", Datasource.class);
    EnrichItem enrichItem = _jsonFileToObj(bundle, "enrich-item.json", EnrichItem.class);
    EnrichPipeline enrichPipeline = _jsonFileToObj(bundle, "enrich-pipeline.json", EnrichPipeline.class);
    _disposable = _tenantRepository.findByVirtualHost(tenant.getVirtualHost()).thenEmpty(_tenantRepository.insert(tenant).then(_datasourceRepository.insert(datasource)).then(_enrichItemRepository.insert(enrichItem)).then(_enrichPipelineRepository.insert(enrichPipeline)).then(Mono.empty())).subscribe();
}
Also used : Datasource(io.openk9.model.Datasource) Tenant(io.openk9.model.Tenant) Bundle(org.osgi.framework.Bundle) EnrichPipeline(io.openk9.model.EnrichPipeline) EnrichItem(io.openk9.model.EnrichItem) Activate(org.osgi.service.component.annotations.Activate)

Example 5 with EnrichItem

use of io.openk9.model.EnrichItem in project openk9 by smclab.

the class BaseNerEnrichProcessor method process.

@Override
public Mono<ObjectNode> process(ObjectNode objectNode, DatasourceContext context, EnrichItem enrichItem, PluginDriverDTO pluginDriverName) {
    return Mono.defer(() -> {
        JsonNode datasourceConfiguration = _jsonFactory.fromJsonToJsonNode(enrichItem.getJsonConfig());
        if (!datasourceConfiguration.isObject()) {
            return Mono.error(new RuntimeException("jsonConfig must be an instance of ObjectNode " + datasourceConfiguration.toString()));
        }
        ObjectNode request = prepareRequestRawContent(objectNode, datasourceConfiguration.toObjectNode(), context, pluginDriverName);
        return Mono.from(_httpClient.request(getMethod(), getPath(), request.toString(), getHeaders())).retry(5).map(_jsonFactory::fromJsonToJsonNode).map(JsonNode::toObjectNode).map(jsonNodes -> {
            jsonNodes.put(Constants.TENANT_ID, context.getTenant().getTenantId());
            jsonNodes.put(Constants.DATASOURCE_ID, context.getDatasource().getDatasourceId());
            jsonNodes.put(Constants.CONTENT_ID, objectNode.get(Constants.CONTENT_ID));
            jsonNodes.put(Constants.RAW_CONTENT, objectNode.get(Constants.RAW_CONTENT));
            jsonNodes.put(Constants.INGESTION_ID, objectNode.get(Constants.INGESTION_ID));
            return jsonNodes;
        }).flatMap(this::_getEntityOrCreate).map(entities -> objectNode.set(entitiesField(), entities));
    });
}
Also used : ObjectNode(io.openk9.json.api.ObjectNode) JsonNode(io.openk9.json.api.JsonNode)

Aggregations

ObjectNode (io.openk9.json.api.ObjectNode)3 JsonNode (io.openk9.json.api.JsonNode)2 Datasource (io.openk9.datasource.model.Datasource)1 EnrichItem (io.openk9.datasource.model.EnrichItem)1 EnrichPipeline (io.openk9.datasource.model.EnrichPipeline)1 Tenant (io.openk9.datasource.model.Tenant)1 DatasourceContext (io.openk9.datasource.processor.payload.DatasourceContext)1 IngestionDatasourcePayload (io.openk9.datasource.processor.payload.IngestionDatasourcePayload)1 IngestionPayload (io.openk9.datasource.processor.payload.IngestionPayload)1 Datasource (io.openk9.model.Datasource)1 EnrichItem (io.openk9.model.EnrichItem)1 EnrichPipeline (io.openk9.model.EnrichPipeline)1 Tenant (io.openk9.model.Tenant)1 Panache (io.quarkus.hibernate.reactive.panache.Panache)1 Uni (io.smallrye.mutiny.Uni)1 JsonObject (io.vertx.core.json.JsonObject)1 Instant (java.time.Instant)1 List (java.util.List)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Incoming (org.eclipse.microprofile.reactive.messaging.Incoming)1