diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2021-01-29 10:14:38 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2021-01-29 10:14:38 +0100 |
commit | bb92e6eaa9bca36d9f1e356a2f578d22c98af22f (patch) | |
tree | 6507fa866d5a4ee0f45500e8143c12638aafc07a /module/ri-engine | |
parent | d167fc9b40a83187c657f3a048f19ac56f529af3 (diff) | |
download | rules-sandbox-bb92e6eaa9bca36d9f1e356a2f578d22c98af22f.tar.gz rules-sandbox-bb92e6eaa9bca36d9f1e356a2f578d22c98af22f.tar.bz2 rules-sandbox-bb92e6eaa9bca36d9f1e356a2f578d22c98af22f.tar.xz rules-sandbox-bb92e6eaa9bca36d9f1e356a2f578d22c98af22f.zip |
IO: Making input and output files have the same format.
Diffstat (limited to 'module/ri-engine')
3 files changed, 9 insertions, 4 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 e2abd5a..7dc24ad 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 @@ -2,6 +2,7 @@ package io.trygvis.rules.engine; import ch.qos.logback.core.util.FileUtil; import com.fasterxml.jackson.annotation.ObjectIdGenerators; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.PropertyName; import com.fasterxml.jackson.databind.SerializationFeature; @@ -72,9 +73,9 @@ public class DbIo { public List<Object> load(File file) throws IOException { var parser = mapper.getFactory().createParser(file); - var objects = mapper.readValues(parser, DbObject.class).readAll(new ArrayList<>()); + var objects = parser.<List<DbObject>>readValueAs(new TypeReference<List<DbObject>>() {}); - List<Object> items = new ArrayList<>(objects.size()); + var items = new ArrayList<>(); for (DbObject object : objects) { try { var type = mapper.getTypeFactory().findClass(object.type); 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 fbb79aa..ef6b4b1 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 @@ -86,8 +86,10 @@ public class Engine implements Closeable { session.addEventListener((RuleRuntimeEventListener) l); var te = session.getGlobals().get("te"); - if (te != null) { + try { session.setGlobal("te", new JinjavaTemplateEngine(templateLoader, output)); + } catch (java.lang.RuntimeException ignore) { + // This happens if the rules doesn't need the template engine. } logger.info("Loading data"); @@ -102,7 +104,7 @@ public class Engine implements Closeable { return; } - logger.info("Loaded {} objects from {}", objects.size(), objects.size()); + logger.info("Loaded {} objects from {}", objects.size(), database); allObjects.addAll(objects); } logger.info("Loaded {} objects", allObjects.size()); 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 f61acbe..1f3e5ed 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 @@ -64,6 +64,8 @@ public class RunCommand implements Callable<Integer> { } else if (i.endsWith("*")) { i = i.substring(0, i.length() - 2); ok = name.startsWith(i) || simpleName.startsWith(i); + } else { + ok = name.equals(i) || simpleName.equals(i); } if (ok) { |