use of org.kie.api.KieBaseConfiguration in project drools by kiegroup.
the class CanonicalKieModule method createKieBase.
@Override
public InternalKnowledgeBase createKieBase(KieBaseModelImpl kBaseModel, KieProject kieProject, ResultsImpl messages, KieBaseConfiguration conf) {
this.moduleClassLoader = ((ProjectClassLoader) kieProject.getClassLoader());
KieBaseConfiguration kBaseConf = getKieBaseConfiguration(kBaseModel, moduleClassLoader, conf);
CanonicalKiePackages kpkgs = pkgsInKbase.computeIfAbsent(kBaseModel.getName(), k -> createKiePackages(kBaseModel, kBaseConf));
return new KieBaseBuilder(kBaseModel, kBaseConf).createKieBase(kpkgs);
}
use of org.kie.api.KieBaseConfiguration in project drools by kiegroup.
the class KieBaseBuilder method createKieBaseFromModel.
public static InternalKnowledgeBase createKieBaseFromModel(Model model, KieBaseOption... options) {
KieBaseConfiguration kieBaseConf = KieServices.get().newKieBaseConfiguration();
if (options == null || options.length == 0) {
for (KieBaseOption option : options) {
kieBaseConf.setOption(option);
}
}
KiePackagesBuilder builder = new KiePackagesBuilder(kieBaseConf, ProjectClassLoader.createProjectClassLoader(kieBaseConf.getClass().getClassLoader()));
builder.addModel(model);
return new KieBaseBuilder(kieBaseConf).createKieBase(builder.build());
}
use of org.kie.api.KieBaseConfiguration in project drools by kiegroup.
the class TruthMaintenanceTest method testStatedShadowLogicalWithSingleOccurance.
@Test(timeout = 10000)
public void testStatedShadowLogicalWithSingleOccurance() {
String droolsSource = "package org.drools.tms.test; \n" + "global java.util.List list; \n" + "rule Justify \n" + "when \n" + " String( this == 'go1' ) " + "then \n" + " insertLogical( 'f1' ); \n" + "end \n" + "rule StillHere \n" + "when \n" + " String( this == 'go2' ) " + " s : String( this == 'f1' ) " + "then \n" + " list.add( s ); \n" + "end \n" + "";
KieBaseConfiguration kieConf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kieConf.setOption(EqualityBehaviorOption.IDENTITY);
KieBase kbase = loadKnowledgeBaseFromString(kieConf, droolsSource);
KieSession session = kbase.newKieSession();
List list = new ArrayList();
session.setGlobal("list", list);
InternalFactHandle fh1 = (InternalFactHandle) session.insert("f1");
InternalFactHandle fh2 = (InternalFactHandle) session.insert("f2");
session.insert("go1");
session.fireAllRules();
session.insert("go2");
session.fireAllRules();
// Make sure f1 only occurs once
assertEquals(1, list.size());
assertEquals("f1", list.get(0));
}
use of org.kie.api.KieBaseConfiguration in project drools by kiegroup.
the class UnmarshallingTest method initializeKnowledgeBase.
private KieBase initializeKnowledgeBase(String rule) {
// Setup knowledge base
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newReaderResource(new StringReader(rule)), ResourceType.DRL);
if (kbuilder.hasErrors()) {
throw new RuntimeException(kbuilder.getErrors().toString());
}
KieBaseConfiguration config = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
config.setOption(EventProcessingOption.STREAM);
InternalKnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase(config);
knowledgeBase.addPackages(kbuilder.getKnowledgePackages());
return knowledgeBase;
}
use of org.kie.api.KieBaseConfiguration in project drools by kiegroup.
the class WindowTest method initialization.
@Before
public void initialization() {
KieFileSystem kfs = KieServices.Factory.get().newKieFileSystem();
kfs.write("src/main/resources/kbase1/window_test.drl", drl);
KieBuilder kbuilder = KieServices.Factory.get().newKieBuilder(kfs);
kbuilder.buildAll();
List<Message> res = kbuilder.getResults().getMessages(Level.ERROR);
assertEquals(res.toString(), 0, res.size());
KieBaseConfiguration kbconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kbconf.setOption(EventProcessingOption.STREAM);
KieBase kbase = KieServices.Factory.get().newKieContainer(kbuilder.getKieModule().getReleaseId()).newKieBase(kbconf);
KieSessionConfiguration ksconfig = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
ksconfig.setOption(ClockTypeOption.get("pseudo"));
ksession = kbase.newKieSession(ksconfig, null);
clock = ksession.getSessionClock();
}
Aggregations