From e4821f82249bddb443a1f6a6e403087cab659c6d Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Fri, 1 Jan 2021 20:35:28 +0100 Subject: Migrating to Drools. --- src/main/java/io/trygvis/rules/engine/Main.java | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/main/java/io/trygvis/rules/engine/Main.java (limited to 'src/main/java/io/trygvis/rules/engine') diff --git a/src/main/java/io/trygvis/rules/engine/Main.java b/src/main/java/io/trygvis/rules/engine/Main.java new file mode 100644 index 0000000..3730c28 --- /dev/null +++ b/src/main/java/io/trygvis/rules/engine/Main.java @@ -0,0 +1,36 @@ +package io.trygvis.rules.engine; + +import io.trygvis.rules.acme.AcmeIo; +import org.drools.core.audit.WorkingMemoryConsoleLogger; +import org.drools.core.common.DefaultFactHandle; +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 io = new AcmeIo(); + + var objects = io.load("acme.yaml"); + + var services = KieServices.Factory.get(); + var container = services.getKieClasspathContainer(); + var session = container.newKieSession(); + + 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.fireAllRules(); + + io.dump("phase-1", session.getFactHandles()); + + session.dispose(); + } +} -- cgit v1.2.3