summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ri-engine/src/main/java/io/trygvis/rules/engine/DbIo.java9
-rw-r--r--src/ri-engine/src/main/java/io/trygvis/rules/engine/Engine.java1
-rw-r--r--src/ri-engine/src/main/java/io/trygvis/rules/engine/cli/NinjaCommand.java2
-rw-r--r--src/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java76
4 files changed, 49 insertions, 39 deletions
diff --git a/src/ri-engine/src/main/java/io/trygvis/rules/engine/DbIo.java b/src/ri-engine/src/main/java/io/trygvis/rules/engine/DbIo.java
index 7dc24ad..b2ed790 100644
--- a/src/ri-engine/src/main/java/io/trygvis/rules/engine/DbIo.java
+++ b/src/ri-engine/src/main/java/io/trygvis/rules/engine/DbIo.java
@@ -12,7 +12,7 @@ import com.fasterxml.jackson.databind.introspect.ObjectIdInfo;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
-import org.drools.core.common.DefaultFactHandle;
+import org.drools.core.common.InternalFactHandle;
import org.drools.core.factmodel.GeneratedFact;
import org.kie.api.KieBase;
import org.kie.api.runtime.KieContainer;
@@ -233,8 +233,9 @@ public class DbIo {
FileUtil.createMissingParentDirectories(file);
var facts = new TreeMap<Class<?>, FactCollection<Object>>(Comparator.comparing(Class::getName));
+ logger.info("The fact database has {} entries", factHandles.size());
for (var handle : factHandles) {
- if (handle instanceof DefaultFactHandle h) {
+ if (handle instanceof InternalFactHandle h) {
var obj = h.getObject();
if (!filter.apply(obj)) {
continue;
@@ -249,9 +250,13 @@ public class DbIo {
}
collection.values.add(obj);
+ } else {
+ logger.warn("Not a known FactHandle type when dumping fact: {}", handle.toExternalForm());
}
}
+ logger.info("Outputting {} facts", facts.size());
+
var objects = new ArrayList<DbObject2>(facts.size());
for (var e : facts.entrySet()) {
var name = e.getKey().getName();
diff --git a/src/ri-engine/src/main/java/io/trygvis/rules/engine/Engine.java b/src/ri-engine/src/main/java/io/trygvis/rules/engine/Engine.java
index f2247d3..4c32087 100644
--- a/src/ri-engine/src/main/java/io/trygvis/rules/engine/Engine.java
+++ b/src/ri-engine/src/main/java/io/trygvis/rules/engine/Engine.java
@@ -110,7 +110,6 @@ public class Engine implements Closeable {
logger.info("Loaded {} objects", allObjects.size());
for (var object : allObjects) {
- logger.info("object = " + object);
session.insert(object);
}
diff --git a/src/ri-engine/src/main/java/io/trygvis/rules/engine/cli/NinjaCommand.java b/src/ri-engine/src/main/java/io/trygvis/rules/engine/cli/NinjaCommand.java
index 9e9d5f9..fa32e51 100644
--- a/src/ri-engine/src/main/java/io/trygvis/rules/engine/cli/NinjaCommand.java
+++ b/src/ri-engine/src/main/java/io/trygvis/rules/engine/cli/NinjaCommand.java
@@ -122,7 +122,7 @@ public class NinjaCommand implements Callable<Integer> {
out.println(" output_state=--output-state %s".formatted(dbDir.resolve(output.name + ".yaml")));
if (!output.includes.isEmpty()) {
var str = output.includes.stream()
- .map(s -> "--output-include=" + s)
+ .map(s -> "--output-include='" + s + "'")
.collect(Collectors.joining(" $\n ", "\n ", ""));
out.println(" output_includes=$%s".formatted(str));
diff --git a/src/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java b/src/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java
index 35f30cd..9b57e4f 100644
--- a/src/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java
+++ b/src/ri-engine/src/main/java/io/trygvis/rules/engine/cli/RunCommand.java
@@ -39,44 +39,50 @@ public class RunCommand implements Callable<Integer> {
agendaGroups = new String[]{"init", "generate"};
}
+ if (outputIncludes == null) {
+ outputIncludes = new String[0];
+ }
+
try (var engine = new Engine(name, input, generatedOutput, agendaGroups, module)) {
- engine.io.dump(outputState, engine.session.getFactHandles(), (Object o) ->
- {
- if (outputIncludes == null || outputIncludes.length == 0) {
- return true;
- }
-
- var name = o.getClass().getName();
- var simpleName = o.getClass().getSimpleName();
-
- for (var i : outputIncludes) {
- var ok = false;
- if (i.startsWith("*")) {
- i = i.substring(1);
-
- if (i.endsWith("*")) {
- i = i.substring(1, i.length() - 2);
- ok = name.contains(i);
- } else {
- ok = name.startsWith(i) || simpleName.startsWith(i);
- }
- } 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) {
- return true;
- }
- }
-
- return false;
- }
- );
+ System.out.println("outputIncludes.length = " + outputIncludes.length);
+ engine.io.dump(outputState, engine.session.getFactHandles(), this::filter);
}
return 0;
}
+
+ private Boolean filter(Object o) {
+ if (outputIncludes.length == 0) {
+ return true;
+ }
+
+ var name = o.getClass().getName();
+ var simpleName = o.getClass().getSimpleName();
+ var packageName = o.getClass().getPackageName();
+
+ for (var i : outputIncludes) {
+ var ok = false;
+ if (i.startsWith("*")) {
+ i = i.substring(1);
+
+ if (i.endsWith("*")) {
+ i = i.substring(1, i.length() - 2);
+ ok = name.contains(i);
+ } else {
+ ok = name.endsWith(i) || simpleName.endsWith(i) || packageName.endsWith(i);
+ }
+ } else if (i.endsWith("*")) {
+ i = i.substring(0, i.length() - 2);
+ ok = name.startsWith(i) || simpleName.startsWith(i) || packageName.startsWith(i);
+ } else {
+ ok = name.equals(i) || simpleName.equals(i) || packageName.equals(i);
+ }
+
+ if (ok) {
+ return true;
+ }
+ }
+
+ return false;
+ }
}