Search in sources :

Example 91 with KnowledgeBuilderImpl

use of org.drools.compiler.builder.impl.KnowledgeBuilderImpl in project drools by kiegroup.

the class TypeDeclarationMergingTest method testInheritExitenceFromParentClass.

@Test
public void testInheritExitenceFromParentClass() {
    // inherits role and typesafe
    String str = "" + "package org.drools.mvel.compiler.test \n" + "global java.util.List list \n" + "declare " + CImpl.class.getCanonicalName() + "\n" + "    @typesafe(true)\n" + "    @role(event)\n" + "end\n" + "declare " + DImpl.class.getCanonicalName() + "\n" + "end\n";
    KnowledgeBuilderImpl builder = getPackageBuilder(str);
    TypeDeclaration tdecl = builder.getTypeDeclaration(DImpl.class);
    assertEquals(true, tdecl.isTypesafe());
    assertEquals(Role.Type.EVENT, tdecl.getRole());
}
Also used : KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) TypeDeclaration(org.drools.core.rule.TypeDeclaration) Test(org.junit.Test)

Example 92 with KnowledgeBuilderImpl

use of org.drools.compiler.builder.impl.KnowledgeBuilderImpl in project drools by kiegroup.

the class TypeDeclarationMergingTest method testOverrideFromDeeperHierarchyParentInterface.

@Test
public void testOverrideFromDeeperHierarchyParentInterface() {
    // inherits role from and typesafe from the other
    String str = "" + "package org.drools.mvel.compiler.test \n" + "global java.util.List list \n" + "declare " + IA.class.getCanonicalName() + "\n" + "    @typesafe(true)\n" + "    @role(event)\n" + "end\n" + "declare " + IB.class.getCanonicalName() + "\n" + "    @role(fact)\n" + "end\n" + "declare " + DImpl.class.getCanonicalName() + "\n" + "end\n";
    KnowledgeBuilderImpl builder = getPackageBuilder(str);
    TypeDeclaration tdecl = builder.getTypeDeclaration(DImpl.class);
    assertEquals(true, tdecl.isTypesafe());
    assertEquals(Role.Type.FACT, tdecl.getRole());
}
Also used : KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) TypeDeclaration(org.drools.core.rule.TypeDeclaration) Test(org.junit.Test)

Example 93 with KnowledgeBuilderImpl

use of org.drools.compiler.builder.impl.KnowledgeBuilderImpl in project drools by kiegroup.

the class MemoryKieModule method afterKieBaseCreationUpdate.

@Override
public void afterKieBaseCreationUpdate(String kBaseName, InternalKnowledgeBase kBase) {
    KnowledgeBuilder knowledgeBuilderForKieBase = getKnowledgeBuilderForKieBase(kBaseName);
    if (knowledgeBuilderForKieBase instanceof KnowledgeBuilderImpl) {
        KnowledgeBuilderImpl knowledgeBuilderForImpl = (KnowledgeBuilderImpl) knowledgeBuilderForKieBase;
        KnowledgeBuilderConfigurationImpl builderConfiguration = knowledgeBuilderForImpl.getBuilderConfiguration();
        KieContainerImpl.CompositeRunnable compositeUpdater = new KieContainerImpl.CompositeRunnable();
        KieBaseUpdaterOptions kieBaseUpdaterOptions = new KieBaseUpdaterOptions(new KieBaseUpdaterOptions.OptionEntry(AlphaNetworkCompilerOption.class, builderConfiguration.getAlphaNetworkCompilerOption()));
        KieBaseUpdaters updaters = KieService.load(KieBaseUpdaters.class);
        updaters.getChildren().stream().map(kbu -> kbu.create(new KieBaseUpdatersContext(kieBaseUpdaterOptions, kBase.getRete(), kBase.getRootClassLoader()))).forEach(compositeUpdater::add);
        kBase.enqueueModification(compositeUpdater);
    }
}
Also used : KiePath(org.kie.memorycompiler.resources.KiePath) URL(java.net.URL) MemoryFileSystem(org.drools.compiler.compiler.io.memory.MemoryFileSystem) LoggerFactory(org.slf4j.LoggerFactory) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) Folder(org.drools.compiler.compiler.io.Folder) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) AlphaNetworkCompilerOption(org.kie.internal.builder.conf.AlphaNetworkCompilerOption) ReleaseId(org.kie.api.builder.ReleaseId) ResourceProvider(org.drools.wiring.api.ResourceProvider) ByteArrayInputStream(java.io.ByteArrayInputStream) URLConnection(java.net.URLConnection) KnowledgeBuilderConfigurationImpl(org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl) ResourceReader(org.kie.memorycompiler.resources.ResourceReader) InternalKnowledgeBase(org.drools.kiesession.rulebase.InternalKnowledgeBase) KieModuleModelImpl(org.drools.compiler.kproject.models.KieModuleModelImpl) Logger(org.slf4j.Logger) InternalResource(org.drools.core.io.internal.InternalResource) MalformedURLException(java.net.MalformedURLException) KieService(org.kie.api.internal.utils.KieService) Collection(java.util.Collection) IOException(java.io.IOException) KieBaseModel(org.kie.api.builder.model.KieBaseModel) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) Serializable(java.io.Serializable) FileSystemItem(org.drools.compiler.compiler.io.FileSystemItem) URLStreamHandler(java.net.URLStreamHandler) KieModuleModel(org.kie.api.builder.model.KieModuleModel) InputStream(java.io.InputStream) KnowledgeBuilderConfigurationImpl(org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) AlphaNetworkCompilerOption(org.kie.internal.builder.conf.AlphaNetworkCompilerOption) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl)

Example 94 with KnowledgeBuilderImpl

use of org.drools.compiler.builder.impl.KnowledgeBuilderImpl in project drools by kiegroup.

the class AssemblerTest method testBayesPackageAssembly.

@Test
public void testBayesPackageAssembly() throws Exception {
    KnowledgeBuilderImpl kbuilder = new KnowledgeBuilderImpl();
    kbuilder.add(ResourceFactory.newClassPathResource("Garden.xmlbif", AssemblerTest.class), ResourceType.BAYES);
    InternalKnowledgePackage kpkg = kbuilder.getPackageRegistry("org.drools.beliefs.bayes.integration").getPackage();
    BayesPackage bkpg = (BayesPackage) kpkg.getResourceTypePackages().get(ResourceType.BAYES);
    assertNotNull(bkpg.getJunctionTree("Garden"));
}
Also used : BayesPackage(org.drools.beliefs.bayes.assembler.BayesPackage) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage) Test(org.junit.Test)

Example 95 with KnowledgeBuilderImpl

use of org.drools.compiler.builder.impl.KnowledgeBuilderImpl in project drools by kiegroup.

the class Misc2Test method testFactTemplates.

@Test
public void testFactTemplates() {
    // DROOLS-600
    String drl = "package com.testfacttemplate;" + " rule \"test rule\" " + " dialect \"mvel\" " + " when " + " $test : TestFactTemplate( status == 1 ) " + " then " + " System.out.println( \"Hello World\" ); " + " end ";
    KnowledgePackageImpl kPackage = new KnowledgePackageImpl("com.testfacttemplate");
    FieldTemplate fieldTemplate = new FieldTemplateImpl("status", 0, Integer.class);
    FactTemplate factTemplate = new FactTemplateImpl(kPackage, "TestFactTemplate", new FieldTemplate[] { fieldTemplate });
    KnowledgeBuilder kBuilder = new KnowledgeBuilderImpl(kPackage);
    StringReader rule = new StringReader(drl);
    try {
        ((KnowledgeBuilderImpl) kBuilder).addPackageFromDrl(rule);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : FactTemplateImpl(org.drools.core.facttemplates.FactTemplateImpl) FieldTemplate(org.drools.core.facttemplates.FieldTemplate) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) FieldTemplateImpl(org.drools.core.facttemplates.FieldTemplateImpl) KnowledgeBuilderImpl(org.drools.compiler.builder.impl.KnowledgeBuilderImpl) StringReader(java.io.StringReader) KnowledgePackageImpl(org.drools.core.definitions.impl.KnowledgePackageImpl) DroolsParserException(org.drools.compiler.compiler.DroolsParserException) FactTemplate(org.drools.core.facttemplates.FactTemplate) Test(org.junit.Test)

Aggregations

KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)178 Test (org.junit.Test)122 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)56 PackageDescr (org.drools.drl.ast.descr.PackageDescr)50 RuleDescr (org.drools.drl.ast.descr.RuleDescr)32 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)30 DialectCompiletimeRegistry (org.drools.compiler.compiler.DialectCompiletimeRegistry)29 Pattern (org.drools.core.rule.Pattern)28 RuleBuildContext (org.drools.compiler.rule.builder.RuleBuildContext)24 StringReader (java.io.StringReader)23 KnowledgeBuilderConfigurationImpl (org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl)23 HashMap (java.util.HashMap)20 TypeDeclaration (org.drools.core.rule.TypeDeclaration)20 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)19 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)19 AndDescr (org.drools.drl.ast.descr.AndDescr)18 PatternDescr (org.drools.drl.ast.descr.PatternDescr)18 InternalKnowledgeBase (org.drools.kiesession.rulebase.InternalKnowledgeBase)18 PackageRegistry (org.drools.compiler.compiler.PackageRegistry)17 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)16