use of io.openk9.datasource.model.Datasource 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();
}
use of io.openk9.datasource.model.Datasource in project openk9 by smclab.
the class BasePluginDriver method invokeDataParser.
@Override
public Mono<Void> invokeDataParser(Datasource datasource, Date fromDate, Date toDate) {
String jsonConfig = datasource.getJsonConfig();
JsonNode jsonNode = getJsonFactory().fromJsonToJsonNode(jsonConfig);
ObjectNode objectNode = jsonNode.toObjectNode();
ObjectNode requestJson = getJsonFactory().createObjectNode();
objectNode.stream().filter(e -> _containsKey(e.getKey())).forEach(e -> requestJson.set(e.getKey(), e.getValue()));
requestJson.put("timestamp", fromDate.getTime());
requestJson.put("datasourceId", datasource.getDatasourceId());
Map<String, Object> headers = headersObject();
Publisher<byte[]> request = getHttpClient().request(method(), path(), requestJson.toString(), headers);
return Mono.from(request).then();
}
use of io.openk9.datasource.model.Datasource in project openk9 by smclab.
the class SchedulerListHttpHandler method apply.
@Override
public Publisher<Void> apply(HttpServerRequest httpRequest, HttpServerResponse httpResponse) {
return _httpResponseWriter.write(httpResponse, Mono.defer(() -> {
Map<String, ScheduleOptions> jobs;
try {
jobs = _scheduler.getJobs();
} catch (SchedulerError schedulerError) {
throw new SchedulerException(schedulerError);
}
Set<String> jobNames = jobs.keySet();
Function<Datasource, Optional<String>> findJobName = datasource -> jobNames.stream().filter(e -> e.endsWith("-" + datasource.getName())).findFirst();
return _datasourceRepository.findAll(true).concatMap(datasource -> {
Optional<String> jobNameOptional = findJobName.apply(datasource);
if (jobNameOptional.isPresent()) {
ObjectNode objectNode = _jsonFactory.createObjectNode();
objectNode.put("datasourceId", datasource.getDatasourceId());
objectNode.put("scheduling", datasource.getScheduling());
objectNode.put("datasourceName", datasource.getName());
objectNode.put("jobName", jobNameOptional.get());
return Mono.just(objectNode.toMap());
} else {
return Mono.empty();
}
}).collectList();
}));
}
Aggregations