Search in sources :

Example 76 with KieBuilder

use of org.kie.api.builder.KieBuilder in project drools by kiegroup.

the class GenericsWithModifyTest method initialize.

@Before
public void initialize() throws IOException {
    final Resource resource = KieServices.Factory.get().getResources().newByteArrayResource(DRL.getBytes(Charset.forName("UTF-8")));
    resource.setTargetPath(TestConstants.DRL_TEST_TARGET_PATH);
    final KieBuilder kbuilder = KieUtil.getKieBuilderFromResources(kieBaseTestConfiguration, true, resource);
    final KieContainer kieContainer = KieServices.Factory.get().newKieContainer(kbuilder.getKieModule().getReleaseId());
    this.kieSession = kieContainer.newKieSession();
}
Also used : Resource(org.kie.api.io.Resource) KieBuilder(org.kie.api.builder.KieBuilder) KieContainer(org.kie.api.runtime.KieContainer) Before(org.junit.Before)

Example 77 with KieBuilder

use of org.kie.api.builder.KieBuilder in project drools by kiegroup.

the class BenchmarkUtil method createJarFile.

public static KJarWithKnowledgeFiles createJarFile(KieServices kieServices, ReleaseId releaseId, int numberOfRules, int numberOfRulesPerFile, BenchmarkType type) {
    final KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
    kieFileSystem.writeKModuleXML(getDefaultKieModuleModel(kieServices).toXML());
    kieFileSystem.writePomXML(getPom(releaseId));
    writeDomainModelToKJar(kieServices, kieFileSystem);
    Collection<String> generatedKnowledge = type.useRuleModel ? generateRuleModelSourcesToKJar(kieFileSystem, numberOfRules, numberOfRulesPerFile, type.generateExprId) : generateDRLsToKJar(kieFileSystem, numberOfRules, numberOfRulesPerFile);
    final KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem);
    testGeneratedKnowledge(kieBuilder);
    final File jarFile = writeKJarToFile(kieBuilder, releaseId);
    return new KJarWithKnowledgeFiles(jarFile, generatedKnowledge);
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieBuilder(org.kie.api.builder.KieBuilder) File(java.io.File)

Example 78 with KieBuilder

use of org.kie.api.builder.KieBuilder in project drools by kiegroup.

the class DMNExtensionRegisterTest method testUsingKModuleProperty_WrongClasses.

@Test
public void testUsingKModuleProperty_WrongClasses() {
    final KieServices ks = KieServices.Factory.get();
    final KieFileSystem kfs = ks.newKieFileSystem();
    KieModuleModel kmm = ks.newKieModuleModel();
    kmm.setConfigurationProperty("org.kie.dmn.profiles.FirstNameLastNameProfile", "foo");
    kfs.writeKModuleXML(kmm.toXML());
    kfs.write(ks.getResources().newClassPathResource("0001-input-data-string-with-extensions.dmn", this.getClass()));
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
    Results results = kieBuilder.getResults();
    LOG.info("buildAll() completed.");
    results.getMessages(Level.WARNING).forEach(e -> LOG.warn("{}", e));
    assertTrue(results.getMessages(Level.WARNING).size() > 0);
    final KieContainer kieContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
    DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
    DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0001-input-data-string");
    assertThat(dmnModel, notNullValue());
    assertThat(formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    assertEquals(3, dmnModel.getDefinitions().getDrgElement().size());
    InputData inputData1 = (InputData) dmnModel.getDefinitions().getDrgElement().get(1);
    assertEquals("First Name", inputData1.getName());
    DMNElement.ExtensionElements id1elements = inputData1.getExtensionElements();
    assertTrue(id1elements != null);
    assertEquals(0, id1elements.getAny().size());
    InputData inputData2 = (InputData) dmnModel.getDefinitions().getDrgElement().get(2);
    assertEquals("Last Name", inputData2.getName());
    DMNElement.ExtensionElements id2elements = inputData2.getExtensionElements();
    assertTrue(id2elements != null);
    assertEquals(0, id2elements.getAny().size());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Results(org.kie.api.builder.Results) KieModuleModel(org.kie.api.builder.model.KieModuleModel) DMNElement(org.kie.dmn.model.v1_1.DMNElement) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) InputData(org.kie.dmn.model.v1_1.InputData) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 79 with KieBuilder

use of org.kie.api.builder.KieBuilder in project drools by kiegroup.

the class DMNExtensionRegisterTest method testUsingKModuleProperty.

@Test
public void testUsingKModuleProperty() {
    final KieServices ks = KieServices.Factory.get();
    final KieFileSystem kfs = ks.newKieFileSystem();
    KieModuleModel kmm = ks.newKieModuleModel();
    kmm.setConfigurationProperty("org.kie.dmn.profiles.FirstNameLastNameProfile", FirstNameLastNameProfile.class.getCanonicalName());
    kfs.writeKModuleXML(kmm.toXML());
    kfs.write(ks.getResources().newClassPathResource("0001-input-data-string-with-extensions.dmn", this.getClass()));
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
    Results results = kieBuilder.getResults();
    LOG.info("buildAll() completed.");
    results.getMessages(Level.WARNING).forEach(e -> LOG.warn("{}", e));
    assertTrue(results.getMessages(Level.WARNING).size() == 0);
    final KieContainer kieContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
    DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
    DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0001-input-data-string");
    assertThat(dmnModel, notNullValue());
    assertThat(formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    assertEquals(3, dmnModel.getDefinitions().getDrgElement().size());
    InputData inputData1 = (InputData) dmnModel.getDefinitions().getDrgElement().get(1);
    assertEquals("First Name", inputData1.getName());
    DMNElement.ExtensionElements id1elements = inputData1.getExtensionElements();
    assertTrue(id1elements != null);
    assertEquals(1, id1elements.getAny().size());
    FirstNameDescription firstNameDescription = (FirstNameDescription) id1elements.getAny().get(0);
    assertTrue(firstNameDescription.getContent().equals("First name in latin characters"));
    InputData inputData2 = (InputData) dmnModel.getDefinitions().getDrgElement().get(2);
    assertEquals("Last Name", inputData2.getName());
    DMNElement.ExtensionElements id2elements = inputData2.getExtensionElements();
    assertTrue(id2elements != null);
    assertEquals(1, id2elements.getAny().size());
    LastNameDescription lastNameDescription = (LastNameDescription) id2elements.getAny().get(0);
    assertTrue(lastNameDescription.getContent().equals("Last name in latin characters"));
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieServices(org.kie.api.KieServices) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) Results(org.kie.api.builder.Results) KieModuleModel(org.kie.api.builder.model.KieModuleModel) DMNElement(org.kie.dmn.model.v1_1.DMNElement) KieBuilder(org.kie.api.builder.KieBuilder) InputData(org.kie.dmn.model.v1_1.InputData) DMNModel(org.kie.dmn.api.core.DMNModel) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 80 with KieBuilder

use of org.kie.api.builder.KieBuilder in project drools by kiegroup.

the class DroolsAbstractPMMLTest method getModelSession.

protected KieSession getModelSession(String[] pmmlSources, boolean verbose) {
    KieServices ks = KieServices.Factory.get();
    KieRepository kr = ks.getRepository();
    KieFileSystem kfs = ks.newKieFileSystem();
    for (int j = 0; j < pmmlSources.length; j++) {
        Resource res = ResourceFactory.newClassPathResource(pmmlSources[j]).setResourceType(ResourceType.PMML);
        kfs.write(res);
    }
    KieModuleModel model = ks.newKieModuleModel();
    model.setConfigurationProperty("drools.propertySpecific", "ALLOWED");
    KieBaseModel kbModel = model.newKieBaseModel(DEFAULT_KIEBASE).addPackage(BASE_PACK).setEventProcessingMode(EventProcessingOption.CLOUD);
    kfs.writeKModuleXML(model.toXML());
    KieBuilder kb = ks.newKieBuilder(kfs);
    kb.buildAll();
    if (kb.getResults().hasMessages(Message.Level.ERROR)) {
        throw new RuntimeException("Build Errors:\n" + kb.getResults().toString());
    }
    KieContainer kContainer = ks.newKieContainer(kr.getDefaultReleaseId());
    // KieBase kieBase = kContainer.getKieBase("SampleMine_SampleMineSegmentation_SEGMENT_1");
    KieBase kieBase = kContainer.getKieBase();
    setKbase(kieBase);
    return kieBase.newKieSession();
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) KieRepository(org.kie.api.builder.KieRepository) KieFileSystem(org.kie.api.builder.KieFileSystem) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieBase(org.kie.api.KieBase) Resource(org.kie.api.io.Resource) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) KieContainer(org.kie.api.runtime.KieContainer)

Aggregations

KieBuilder (org.kie.api.builder.KieBuilder)211 KieFileSystem (org.kie.api.builder.KieFileSystem)179 KieServices (org.kie.api.KieServices)145 Test (org.junit.Test)134 KieSession (org.kie.api.runtime.KieSession)59 KieModuleModel (org.kie.api.builder.model.KieModuleModel)57 InternalKieBuilder (org.kie.internal.builder.InternalKieBuilder)54 KieContainer (org.kie.api.runtime.KieContainer)48 IncrementalResults (org.kie.internal.builder.IncrementalResults)35 ReleaseId (org.kie.api.builder.ReleaseId)34 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)33 Results (org.kie.api.builder.Results)32 Message (org.kie.api.builder.Message)30 KieBase (org.kie.api.KieBase)29 ArrayList (java.util.ArrayList)22 KieBaseModel (org.kie.api.builder.model.KieBaseModel)22 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)21 Resource (org.kie.api.io.Resource)19 FactType (org.kie.api.definition.type.FactType)16 KieModule (org.kie.api.builder.KieModule)12