use of io.openk9.datasource.model.EnrichPipeline 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();
})));
}
use of io.openk9.datasource.model.EnrichPipeline 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();
}
Aggregations