summaryrefslogtreecommitdiff
path: root/module/ri-engine/src
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2021-01-06 15:20:40 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2021-01-06 15:21:16 +0100
commite84ef1adb8ff0d3b121ea12b2d3e15fa52eb2f00 (patch)
treeafb7c00c654c122a313acaba8630708a87ae4ffd /module/ri-engine/src
parent9504c7efb9b57aeacf5e2717a43c3cf178a65aee (diff)
downloadrules-sandbox-e84ef1adb8ff0d3b121ea12b2d3e15fa52eb2f00.tar.gz
rules-sandbox-e84ef1adb8ff0d3b121ea12b2d3e15fa52eb2f00.tar.bz2
rules-sandbox-e84ef1adb8ff0d3b121ea12b2d3e15fa52eb2f00.tar.xz
rules-sandbox-e84ef1adb8ff0d3b121ea12b2d3e15fa52eb2f00.zip
Splitting Main into two runs, Vpn and AcmeApps.
Diffstat (limited to 'module/ri-engine/src')
-rw-r--r--module/ri-engine/src/main/java/io/trygvis/rules/engine/DbIo.java13
-rw-r--r--module/ri-engine/src/main/java/io/trygvis/rules/engine/Engine.java6
2 files changed, 8 insertions, 11 deletions
diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/engine/DbIo.java b/module/ri-engine/src/main/java/io/trygvis/rules/engine/DbIo.java
index b835da5..7f946d9 100644
--- a/module/ri-engine/src/main/java/io/trygvis/rules/engine/DbIo.java
+++ b/module/ri-engine/src/main/java/io/trygvis/rules/engine/DbIo.java
@@ -1,5 +1,6 @@
package io.trygvis.rules.engine;
+import ch.qos.logback.core.util.FileUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
@@ -41,7 +42,7 @@ public class DbIo {
var x = mapper.treeToValue(object.data, type);
items.add(x);
} catch (ClassNotFoundException e) {
- throw new IOException(e);
+ // ignore
}
}
@@ -183,13 +184,9 @@ public class DbIo {
}
public void dump(String s, Collection<FactHandle> factHandles, Function<Object, Boolean> filter) throws IOException {
- var out = new File("out");
+ var yamlFile = new File("out", s + ".yaml");
- if (!out.isDirectory()) {
- if (!out.mkdirs()) {
- throw new IOException("Could not create directory: " + out);
- }
- }
+ FileUtil.createMissingParentDirectories(yamlFile);
var facts = new TreeMap<Class<?>, FactCollection<Object>>(Comparator.comparing(Class::getName));
for (var handle : factHandles) {
@@ -212,7 +209,7 @@ public class DbIo {
}
var factory = mapper.getFactory();
- try (var writer = new FileWriter(new File(out, s + ".yaml"));
+ try (var writer = new FileWriter(yamlFile);
var g = factory.createGenerator(writer)) {
for (var e : facts.entrySet()) {
var name = e.getKey().getName();
diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/engine/Engine.java b/module/ri-engine/src/main/java/io/trygvis/rules/engine/Engine.java
index 2565112..f624603 100644
--- a/module/ri-engine/src/main/java/io/trygvis/rules/engine/Engine.java
+++ b/module/ri-engine/src/main/java/io/trygvis/rules/engine/Engine.java
@@ -13,15 +13,15 @@ public class Engine implements Closeable {
public final DbIo io;
public final KieSession session;
- public Engine(String database) throws IOException {
+ public Engine(String k, String database) throws IOException {
var services = KieServices.Factory.get();
var container = services.getKieClasspathContainer();
- var kieBase = container.getKieBase();
+ var kieBase = container.getKieBase(k);
io = new DbIo(kieBase);
var objects = io.load(database);
- session = container.newKieSession();
+ session = container.newKieSession(k);
session.setGlobal("te", new TemplateEngine());