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();
}
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;
}
Aggregations