Search in sources :

Example 6 with DecisionTableConfiguration

use of org.kie.internal.builder.DecisionTableConfiguration in project drools by kiegroup.

the class DumpGeneratedDrlTest method testGeneratedDrlFromIsDumpedIfSpecified.

@Test
public void testGeneratedDrlFromIsDumpedIfSpecified() {
    DecisionTableConfiguration dtconf = KnowledgeBuilderFactory.newDecisionTableConfiguration();
    dtconf.setInputType(DecisionTableInputType.CSV);
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    Resource resource = ResourceFactory.newByteArrayResource(DUMMY_DTABLE_CSV_SOURCE.getBytes(IoUtils.UTF8_CHARSET));
    resource.setSourcePath("some/source/path/dummy-dtable.csv");
    kbuilder.add(resource, ResourceType.DTABLE, dtconf);
    if (kbuilder.hasErrors()) {
        Assert.fail("Unexpected Drools compilation errors: " + kbuilder.getErrors().toString());
    }
    assertGeneratedDrlExists(dumpDir, "some_source_path_dummy-dtable.csv.drl");
}
Also used : KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) DecisionTableConfiguration(org.kie.internal.builder.DecisionTableConfiguration) Resource(org.kie.api.io.Resource) Test(org.junit.Test)

Example 7 with DecisionTableConfiguration

use of org.kie.internal.builder.DecisionTableConfiguration in project drools by kiegroup.

the class UnicodeInXLSTest method testUnicodeXLSDecisionTable.

@Test
public void testUnicodeXLSDecisionTable() throws FileNotFoundException {
    DecisionTableConfiguration dtconf = KnowledgeBuilderFactory.newDecisionTableConfiguration();
    dtconf.setInputType(DecisionTableInputType.XLS);
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource("unicode.xls", getClass()), ResourceType.DTABLE, dtconf);
    if (kbuilder.hasErrors()) {
        System.out.println(kbuilder.getErrors().toString());
        System.out.println(DecisionTableFactory.loadFromInputStream(getClass().getResourceAsStream("unicode.xls"), dtconf));
        fail("Cannot build XLS decision table containing utf-8 characters\n" + kbuilder.getErrors().toString());
    }
    InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addPackages(kbuilder.getKnowledgePackages());
    KieSession ksession = kbase.newKieSession();
    List<Command<?>> commands = new ArrayList<Command<?>>();
    List<Člověk> dospělí = new ArrayList<Člověk>();
    commands.add(CommandFactory.newSetGlobal("dospělí", dospělí));
    Člověk Řehoř = new Člověk();
    Řehoř.setVěk(30);
    Řehoř.setJméno("Řehoř");
    commands.add(CommandFactory.newInsert(Řehoř));
    commands.add(CommandFactory.newFireAllRules());
    ksession.execute(CommandFactory.newBatchExecution(commands));
    // people with age greater than 18 should be added to list of adults
    assertNotNull(kbase.getRule("org.drools.decisiontable", "přidej k dospělým"));
    assertEquals(dospělí.size(), 5);
    assertEquals(dospělí.iterator().next().getJméno(), "Řehoř");
    assertNotNull(kbase.getRule("org.drools.decisiontable", "привет мир"));
    assertNotNull(kbase.getRule("org.drools.decisiontable", "你好世界"));
    assertNotNull(kbase.getRule("org.drools.decisiontable", "hallå världen"));
    assertNotNull(kbase.getRule("org.drools.decisiontable", "مرحبا العالم"));
    ksession.dispose();
}
Also used : KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) Command(org.kie.api.command.Command) DecisionTableConfiguration(org.kie.internal.builder.DecisionTableConfiguration) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Test(org.junit.Test)

Example 8 with DecisionTableConfiguration

use of org.kie.internal.builder.DecisionTableConfiguration in project drools by kiegroup.

the class MultipleSheetsLoadingTest method createXLSResourceConfig.

private ResourceConfiguration createXLSResourceConfig(final String worksheetName) {
    final DecisionTableConfiguration resourceConfig = new DecisionTableConfigurationImpl();
    resourceConfig.setInputType(DecisionTableInputType.XLS);
    resourceConfig.setWorksheetName(worksheetName);
    return resourceConfig;
}
Also used : DecisionTableConfiguration(org.kie.internal.builder.DecisionTableConfiguration) DecisionTableConfigurationImpl(org.drools.core.builder.conf.impl.DecisionTableConfigurationImpl)

Example 9 with DecisionTableConfiguration

use of org.kie.internal.builder.DecisionTableConfiguration in project drools by kiegroup.

the class ResourceUtil method getDecisionTableResourceFromClasspath.

public static Resource getDecisionTableResourceFromClasspath(final String resourceName, final Class classLoaderFromClass, final DecisionTableInputType type) {
    final Resource dtable = KieServices.Factory.get().getResources().newClassPathResource(resourceName, classLoaderFromClass);
    final DecisionTableConfiguration resourceConfig = new DecisionTableConfigurationImpl();
    resourceConfig.setInputType(type);
    dtable.setConfiguration(resourceConfig);
    return dtable;
}
Also used : DecisionTableConfiguration(org.kie.internal.builder.DecisionTableConfiguration) Resource(org.kie.api.io.Resource) DecisionTableConfigurationImpl(org.drools.core.builder.conf.impl.DecisionTableConfigurationImpl)

Example 10 with DecisionTableConfiguration

use of org.kie.internal.builder.DecisionTableConfiguration in project drools by kiegroup.

the class ChangeSetTest method testXmlParser.

@Test
public void testXmlParser() throws SAXException, IOException {
    KnowledgeBuilderConfigurationImpl conf = new KnowledgeBuilderConfigurationImpl();
    XmlChangeSetReader xmlReader = new XmlChangeSetReader(conf.getSemanticModules());
    xmlReader.setClassLoader(ChangeSetTest.class.getClassLoader(), ChangeSetTest.class);
    String str = "";
    str += "<change-set ";
    str += "xmlns='http://drools.org/drools-5.0/change-set' ";
    str += "xmlns:xs='http://www.w3.org/2001/XMLSchema-instance' ";
    str += "xs:schemaLocation='http://drools.org/drools-5.0/change-set http://anonsvn.jboss.org/repos/labs/labs/jbossrules/trunk/drools-api/src/main/resources/change-set-1.0.0.xsd' >";
    str += "    <add> ";
    str += "        <resource source='http://www.domain.com/test.drl' type='DRL' />";
    str += "        <resource source='http://www.domain.com/test.xls' type='DTABLE' >";
    str += "            <decisiontable-conf worksheet-name='sheet10' input-type='XLS' />";
    str += "        </resource>";
    str += "    </add> ";
    str += "</change-set>";
    StringReader reader = new StringReader(str);
    ChangeSet changeSet = xmlReader.read(reader);
    assertEquals(2, changeSet.getResourcesAdded().size());
    UrlResource resource = (UrlResource) ((List) changeSet.getResourcesAdded()).get(0);
    assertEquals("http://www.domain.com/test.drl", resource.getURL().toString());
    assertEquals(ResourceType.DRL, resource.getResourceType());
    resource = (UrlResource) ((List) changeSet.getResourcesAdded()).get(1);
    assertEquals("http://www.domain.com/test.xls", resource.getURL().toString());
    assertEquals(ResourceType.DTABLE, resource.getResourceType());
    DecisionTableConfiguration dtConf = (DecisionTableConfiguration) resource.getConfiguration();
    assertEquals(DecisionTableInputType.XLS, dtConf.getInputType());
}
Also used : KnowledgeBuilderConfigurationImpl(org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl) UrlResource(org.drools.core.io.impl.UrlResource) DecisionTableConfiguration(org.kie.internal.builder.DecisionTableConfiguration) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) List(java.util.List) XmlChangeSetReader(org.drools.core.xml.XmlChangeSetReader) ChangeSet(org.kie.internal.ChangeSet) Test(org.junit.Test)

Aggregations

DecisionTableConfiguration (org.kie.internal.builder.DecisionTableConfiguration)17 Test (org.junit.Test)10 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)10 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)6 ArrayList (java.util.ArrayList)5 Resource (org.kie.api.io.Resource)5 KieSession (org.kie.api.runtime.KieSession)5 DecisionTableConfigurationImpl (org.drools.core.builder.conf.impl.DecisionTableConfigurationImpl)3 Command (org.kie.api.command.Command)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 StringReader (java.io.StringReader)1 List (java.util.List)1 Driver (org.acme.insurance.Driver)1 Policy (org.acme.insurance.Policy)1 KnowledgeBuilderConfigurationImpl (org.drools.compiler.builder.impl.KnowledgeBuilderConfigurationImpl)1 CompositePackageDescr (org.drools.compiler.lang.descr.CompositePackageDescr)1 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)1 ResourceConfigurationImpl (org.drools.core.builder.conf.impl.ResourceConfigurationImpl)1 UrlResource (org.drools.core.io.impl.UrlResource)1