Search in sources :

Example 16 with DecisionTableConfiguration

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

the class UnicodeInCSVTest method testUnicodeCSVDecisionTable.

@Test
public void testUnicodeCSVDecisionTable() throws FileNotFoundException {
    DecisionTableConfiguration dtconf = KnowledgeBuilderFactory.newDecisionTableConfiguration();
    dtconf.setInputType(DecisionTableInputType.CSV);
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource("unicode.csv", 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 CSV 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 17 with DecisionTableConfiguration

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

the class DecisionTableConfigurationHandler method start.

public Object start(String uri, String localName, Attributes attrs, ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    String type = attrs.getValue("input-type");
    String worksheetName = attrs.getValue("worksheet-name");
    emptyAttributeCheck(localName, "input-type", type, parser);
    DecisionTableConfiguration dtConf = new DecisionTableConfigurationImpl();
    dtConf.setInputType(DecisionTableInputType.valueOf(type));
    if (!StringUtils.isEmpty(worksheetName)) {
        dtConf.setWorksheetName(worksheetName);
    }
    return dtConf;
}
Also used : DecisionTableConfiguration(org.kie.internal.builder.DecisionTableConfiguration) DecisionTableConfigurationImpl(org.drools.core.builder.conf.impl.DecisionTableConfigurationImpl)

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