summaryrefslogtreecommitdiff
path: root/module
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2021-01-28 15:52:17 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2021-01-28 15:52:17 +0100
commitd167fc9b40a83187c657f3a048f19ac56f529af3 (patch)
tree2a8fb8e64e3348a9e60727b5fc9d8cc3ec14faa7 /module
parent0ae7ecd47fd76921e8e1137739497578fe703354 (diff)
downloadrules-sandbox-d167fc9b40a83187c657f3a048f19ac56f529af3.tar.gz
rules-sandbox-d167fc9b40a83187c657f3a048f19ac56f529af3.tar.bz2
rules-sandbox-d167fc9b40a83187c657f3a048f19ac56f529af3.tar.xz
rules-sandbox-d167fc9b40a83187c657f3a048f19ac56f529af3.zip
Better main().
* More than one input database. * Only creating templating engine if the rules require it.
Diffstat (limited to 'module')
-rw-r--r--module/ri-engine/pom.xml2
-rw-r--r--module/ri-engine/src/main/java/io/trygvis/rules/engine/Engine.java27
-rw-r--r--module/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java2
-rw-r--r--module/ri-engine/src/test/java/io/trygvis/rules/engine/AcmeAppsTestMain.java2
-rw-r--r--module/ri-engine/src/test/java/io/trygvis/rules/engine/AcmeWireguardTestMain.java2
5 files changed, 22 insertions, 13 deletions
diff --git a/module/ri-engine/pom.xml b/module/ri-engine/pom.xml
index c667145..01a72cc 100644
--- a/module/ri-engine/pom.xml
+++ b/module/ri-engine/pom.xml
@@ -169,7 +169,7 @@
<executable>java</executable>
<arguments>
<argument>-Dpicocli.autocomplete.systemExitOnError</argument>
- <argument>--enable-preview</argument>
+ <argument>${java.preview}</argument>
<argument>-cp</argument>
<classpath/>
<argument>picocli.AutoComplete</argument>
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 4a49ca2..fbb79aa 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
@@ -29,7 +29,7 @@ public class Engine implements Closeable {
public final DbIo io;
public final KieSession session;
- public Engine(String name, File database, File output, String[] agendaGroups, File[] modules) throws IOException {
+ public Engine(String name, File[] databases, File output, String[] agendaGroups, File[] modules) throws IOException {
logger.info("Getting KieServices");
var services = KieServices.Factory.get();
@@ -85,20 +85,29 @@ public class Engine implements Closeable {
session.addEventListener((AgendaEventListener) l);
session.addEventListener((RuleRuntimeEventListener) l);
- session.setGlobal("te", new JinjavaTemplateEngine(templateLoader, output));
+ var te = session.getGlobals().get("te");
+ if (te != null) {
+ session.setGlobal("te", new JinjavaTemplateEngine(templateLoader, output));
+ }
logger.info("Loading data");
io = new DbIo(container, kieBase);
- var objects = io.load(database);
- if (objects.isEmpty()) {
- logger.warn("Did not load any objects, something is wrong");
- return;
- }
+ List<Object> allObjects = new ArrayList<>();
+ for (File database : databases) {
+ var objects = io.load(database);
- logger.info("Loaded {} objects", objects.size());
+ if (objects.isEmpty()) {
+ logger.warn("Did not load any objects, something is wrong");
+ return;
+ }
+
+ logger.info("Loaded {} objects from {}", objects.size(), objects.size());
+ allObjects.addAll(objects);
+ }
+ logger.info("Loaded {} objects", allObjects.size());
- for (var object : objects) {
+ for (var object : allObjects) {
logger.info("object = " + object);
session.insert(object);
}
diff --git a/module/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java b/module/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java
index 203a9b0..f61acbe 100644
--- a/module/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java
+++ b/module/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java
@@ -15,7 +15,7 @@ public class RunCommand implements Callable<Integer> {
public String name;
@Option(names = {"-i", "--input"})
- public File input;
+ public File[] input;
@Option(names = {"--output-state"})
public File outputState;
diff --git a/module/ri-engine/src/test/java/io/trygvis/rules/engine/AcmeAppsTestMain.java b/module/ri-engine/src/test/java/io/trygvis/rules/engine/AcmeAppsTestMain.java
index 17b7950..37e8787 100644
--- a/module/ri-engine/src/test/java/io/trygvis/rules/engine/AcmeAppsTestMain.java
+++ b/module/ri-engine/src/test/java/io/trygvis/rules/engine/AcmeAppsTestMain.java
@@ -10,7 +10,7 @@ class AcmeAppsTestMain {
public static void main(String[] args) throws Exception {
var c = new RunCommand();
c.name = "acme-apps";
- c.input = new File("acme.yaml");
+ c.input = new File[]{new File("acme.yaml")};
c.outputState = new File("out/acme/apps.yaml");
c.agendaGroups = new String[]{"init", "generate"};
c.generatedOutput = new File("acme-apps");
diff --git a/module/ri-engine/src/test/java/io/trygvis/rules/engine/AcmeWireguardTestMain.java b/module/ri-engine/src/test/java/io/trygvis/rules/engine/AcmeWireguardTestMain.java
index 2bb5513..4d88e39 100644
--- a/module/ri-engine/src/test/java/io/trygvis/rules/engine/AcmeWireguardTestMain.java
+++ b/module/ri-engine/src/test/java/io/trygvis/rules/engine/AcmeWireguardTestMain.java
@@ -10,7 +10,7 @@ class AcmeWireguardTestMain {
public static void main(String[] args) throws Exception {
var c = new RunCommand();
c.name = "acme-wireguard";
- c.input = new File("acme.yaml");
+ c.input = new File[]{new File("acme.yaml")};
c.outputState = new File("out/acme/wireguard.yaml");
c.agendaGroups = new String[]{"init", "generate"};
c.generatedOutput = new File("acme-wireguard");