From b8699860653e593271e50c8ba1b73f66fcb6287c Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Wed, 6 Jan 2021 12:05:23 +0100 Subject: Starting on splitting up into different modules. --- .../java/io/trygvis/rules/engine/KeyValue.java | 14 ------ src/main/java/io/trygvis/rules/engine/Main.java | 53 ---------------------- .../io/trygvis/rules/engine/TemplateEngine.java | 30 ------------ 3 files changed, 97 deletions(-) delete mode 100644 src/main/java/io/trygvis/rules/engine/KeyValue.java delete mode 100644 src/main/java/io/trygvis/rules/engine/Main.java delete mode 100644 src/main/java/io/trygvis/rules/engine/TemplateEngine.java (limited to 'src/main/java/io/trygvis/rules/engine') 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 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); - } -} -- cgit v1.2.3