diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2021-01-06 12:05:23 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2021-01-06 12:05:23 +0100 |
commit | b8699860653e593271e50c8ba1b73f66fcb6287c (patch) | |
tree | a7029ee71f1539d269fda241a3f345255783dcf1 /src/main/java/io/trygvis/rules/engine | |
parent | 9eac79348242b5dc33f4cccdd86beda2a4ed4746 (diff) | |
download | rules-sandbox-b8699860653e593271e50c8ba1b73f66fcb6287c.tar.gz rules-sandbox-b8699860653e593271e50c8ba1b73f66fcb6287c.tar.bz2 rules-sandbox-b8699860653e593271e50c8ba1b73f66fcb6287c.tar.xz rules-sandbox-b8699860653e593271e50c8ba1b73f66fcb6287c.zip |
Starting on splitting up into different modules.
Diffstat (limited to 'src/main/java/io/trygvis/rules/engine')
-rw-r--r-- | src/main/java/io/trygvis/rules/engine/KeyValue.java | 14 | ||||
-rw-r--r-- | src/main/java/io/trygvis/rules/engine/Main.java | 53 | ||||
-rw-r--r-- | src/main/java/io/trygvis/rules/engine/TemplateEngine.java | 30 |
3 files changed, 0 insertions, 97 deletions
diff --git a/src/main/java/io/trygvis/rules/engine/KeyValue.java b/src/main/java/io/trygvis/rules/engine/KeyValue.java deleted file mode 100644 index 5046169..0000000 --- a/src/main/java/io/trygvis/rules/engine/KeyValue.java +++ /dev/null @@ -1,14 +0,0 @@ -package io.trygvis.rules.engine; - -public class KeyValue { - public String key; - public String value; - - public KeyValue() { - } - - public KeyValue(String key, String value) { - this.key = key; - this.value = value; - } -} diff --git a/src/main/java/io/trygvis/rules/engine/Main.java b/src/main/java/io/trygvis/rules/engine/Main.java deleted file mode 100644 index 7c96be6..0000000 --- a/src/main/java/io/trygvis/rules/engine/Main.java +++ /dev/null @@ -1,53 +0,0 @@ -package io.trygvis.rules.engine; - -import io.trygvis.rules.acme.AcmeIo; -import io.trygvis.rules.dns.DnsEntry; -import io.trygvis.rules.machine.Machine; -import io.trygvis.rules.network.Ipv4Address; -import io.trygvis.rules.network.Ipv4Cidr; -import org.drools.core.audit.WorkingMemoryConsoleLogger; -import org.kie.api.KieServices; -import org.kie.api.event.rule.AgendaEventListener; -import org.kie.api.event.rule.RuleRuntimeEventListener; - -import java.io.IOException; - -public class Main { - public static void main(String[] args) throws IOException { - var services = KieServices.Factory.get(); - var container = services.getKieClasspathContainer(); - var kieBase = container.getKieBase(); - - var io = new AcmeIo(kieBase); - var objects = io.load("acme.yaml"); - - var session = container.newKieSession(); - - session.setGlobal("te", new TemplateEngine()); - - for (var object : objects) { - System.out.println("object = " + object); - session.insert(object); - } - - var logger = new WorkingMemoryConsoleLogger(session); - session.addEventListener((AgendaEventListener) logger); - session.addEventListener((RuleRuntimeEventListener) logger); - - session.getAgenda().getAgendaGroup("init").setFocus(); - - session.fireAllRules(); - - io.dump("phase-1", session.getFactHandles()); - - io.dump("vpn0", session.getFactHandles(), (Object o) -> - o.getClass().getName().contains("Wg") - || o instanceof Machine - || o instanceof DnsEntry - || o instanceof Ipv4Cidr - || o instanceof Ipv4Address - ); - - session.dispose(); - } -} diff --git a/src/main/java/io/trygvis/rules/engine/TemplateEngine.java b/src/main/java/io/trygvis/rules/engine/TemplateEngine.java deleted file mode 100644 index ace7aaf..0000000 --- a/src/main/java/io/trygvis/rules/engine/TemplateEngine.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.trygvis.rules.engine; - -import ch.qos.logback.core.util.FileUtil; -import com.hubspot.jinjava.Jinjava; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Map; - -public class TemplateEngine { - private final Jinjava jinjava = new Jinjava(); - - public void template(String name, String output, Map<String, Object> params) throws IOException { - var template = Files.readString(Path.of("j2", name + ".j2")); - String renderedTemplate = jinjava.render(template, params); -// System.out.println("-----------------------------------"); -// for (var item : params.entrySet()) { -// System.out.printf(" %s : %s%n", item.getKey(), item.getValue()); -// } - System.out.println("-----------------------------------"); - System.out.println(renderedTemplate); - System.out.println("-----------------------------------"); - - var f = new File("gen", output); - FileUtil.createMissingParentDirectories(f); - Files.writeString(f.toPath(), renderedTemplate); - } -} |