use of org.kie.internal.builder.DecisionTableConfiguration in project drools by kiegroup.
the class KnowledgeBuilderImpl method decisionTableToPackageDescr.
PackageDescr decisionTableToPackageDescr(Resource resource, ResourceConfiguration configuration) throws DroolsParserException, IOException {
DecisionTableConfiguration dtableConfiguration = configuration instanceof DecisionTableConfiguration ? (DecisionTableConfiguration) configuration : null;
if (dtableConfiguration != null && !dtableConfiguration.getRuleTemplateConfigurations().isEmpty()) {
List<String> generatedDrls = DecisionTableFactory.loadFromInputStreamWithTemplates(resource, dtableConfiguration);
if (generatedDrls.size() == 1) {
return generatedDrlToPackageDescr(resource, generatedDrls.get(0));
}
CompositePackageDescr compositePackageDescr = null;
for (String generatedDrl : generatedDrls) {
PackageDescr packageDescr = generatedDrlToPackageDescr(resource, generatedDrl);
if (packageDescr != null) {
if (compositePackageDescr == null) {
compositePackageDescr = new CompositePackageDescr(resource, packageDescr);
} else {
compositePackageDescr.addPackageDescr(resource, packageDescr);
}
}
}
return compositePackageDescr;
}
String generatedDrl = DecisionTableFactory.loadFromResource(resource, dtableConfiguration);
return generatedDrlToPackageDescr(resource, generatedDrl);
}
use of org.kie.internal.builder.DecisionTableConfiguration in project drools by kiegroup.
the class AbstractKieModule method addResourceToCompiler.
public final boolean addResourceToCompiler(CompositeKnowledgeBuilder ckbuilder, KieBaseModel kieBaseModel, String fileName, ResourceChangeSet rcs) {
ResourceConfiguration conf = getResourceConfiguration(fileName);
Resource resource = getResource(fileName);
if (resource != null) {
ResourceType resourceType = conf instanceof ResourceConfigurationImpl && ((ResourceConfigurationImpl) conf).getResourceType() != null ? ((ResourceConfigurationImpl) conf).getResourceType() : ResourceType.determineResourceType(fileName);
if (resourceType == ResourceType.DTABLE && conf instanceof DecisionTableConfiguration) {
for (RuleTemplateModel template : kieBaseModel.getRuleTemplates()) {
if (template.getDtable().equals(fileName)) {
Resource templateResource = getResource(template.getTemplate());
if (templateResource != null) {
((DecisionTableConfiguration) conf).addRuleTemplateConfiguration(templateResource, template.getRow(), template.getCol());
}
}
}
}
if (conf == null) {
ckbuilder.add(resource, resourceType, rcs);
} else {
ckbuilder.add(resource, resourceType, conf, rcs);
}
return true;
}
return false;
}
use of org.kie.internal.builder.DecisionTableConfiguration in project drools by kiegroup.
the class PricingRuleLauncher method executeExample.
public int executeExample() throws Exception {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
DecisionTableConfiguration dtconf = KnowledgeBuilderFactory.newDecisionTableConfiguration();
dtconf.setInputType(DecisionTableInputType.XLS);
kbuilder.add(ResourceFactory.newClassPathResource("/data/ExamplePolicyPricing.xls", getClass()), ResourceType.DTABLE, dtconf);
if (kbuilder.hasErrors()) {
throw new RuntimeException(kbuilder.getErrors().toString());
}
// BUILD RULEBASE
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
// NEW WORKING MEMORY
final KieSession session = kbase.newKieSession();
// now create some test data
Driver driver = new Driver();
Policy policy = new Policy();
session.insert(driver);
session.insert(policy);
session.fireAllRules();
System.out.println("BASE PRICE IS: " + policy.getBasePrice());
System.out.println("DISCOUNT IS: " + policy.getDiscountPercent());
return policy.getBasePrice();
}
use of org.kie.internal.builder.DecisionTableConfiguration in project drools by kiegroup.
the class ColumnReplaceTest method testAutoFocusToLockOnActiveReplacement.
@Test
public void testAutoFocusToLockOnActiveReplacement() throws FileNotFoundException {
DecisionTableConfiguration dTableConfiguration = KnowledgeBuilderFactory.newDecisionTableConfiguration();
dTableConfiguration.setInputType(DecisionTableInputType.CSV);
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("columnReplaceTest.csv", getClass()), ResourceType.DTABLE, dTableConfiguration);
if (kbuilder.hasErrors()) {
System.out.println(kbuilder.getErrors());
fail("Knowledge builder cannot compile package!");
}
System.out.println(DecisionTableFactory.loadFromInputStream(new FileInputStream(new File("src/test/resources/org/drools/decisiontable/columnReplaceTest.csv")), dTableConfiguration));
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
assertTrue(((RuleImpl) kbase.getRule("org.drools.decisiontable", "lockOnActiveRule")).isLockOnActive());
// lock-on-active was not set on autoFocusRule, so it should be by default false
assertFalse(((RuleImpl) kbase.getRule("org.drools.decisiontable", "autoFocusRule")).isLockOnActive());
assertFalse(((RuleImpl) kbase.getRule("org.drools.decisiontable", "lockOnActiveRule")).getAutoFocus());
// auto-focus was set to be true, so it should be true
assertTrue(((RuleImpl) kbase.getRule("org.drools.decisiontable", "autoFocusRule")).getAutoFocus());
}
use of org.kie.internal.builder.DecisionTableConfiguration in project drools by kiegroup.
the class DumpGeneratedDrlTest method testDTableWithNullSrcPathIsCorrectlyDumped.
@Test
public void testDTableWithNullSrcPathIsCorrectlyDumped() {
DecisionTableConfiguration dtconf = KnowledgeBuilderFactory.newDecisionTableConfiguration();
dtconf.setInputType(DecisionTableInputType.CSV);
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
Resource resource = ResourceFactory.newByteArrayResource(DUMMY_DTABLE_CSV_SOURCE.getBytes(IoUtils.UTF8_CHARSET));
kbuilder.add(resource, ResourceType.DTABLE, dtconf);
if (kbuilder.hasErrors()) {
Assert.fail("Unexpected Drools compilation errors: " + kbuilder.getErrors().toString());
}
assertGeneratedDrlExists(dumpDir, null);
}
Aggregations