Click here to Skip to main content
15,911,306 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
am using Drools 5.x (drools-compiler 5.2.1.Final, drools-decisiontables 5.4.0.Final, and drools-templates 5.4.0.Final; jbpm-flow 5.1.1.Final, jbpm-bmpn2 5.1.1.Final and with their respective dependencies) for my Java job, I build/run it with Java 1.7.0_21. My current set up works properly. I am using a decision table (spreadsheet).

I am able to build/run my project with Java 1.8.0_162 using drools 5.x as described above; however, when the java job runs it loads the decision table (spreadsheet) but it does not fire up any of the rules, I am not getting an exception in the last line that gets executed:

Java
Properties props = new Properties();
    
    KnowledgeBuilderConfiguration configuration = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(props);
    
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newDecisionTableConfiguration(configuration);
    
    DecisionTableConfiguration config = KnowledgeBuilderFactory.newDecisionTableConfiguration();
    
    config.setInputType(DecisionTableInputType.XLS);
    
    kbuilder.add(ResourceFactory.newClassPathResource(spreadsheetFile), ResourcType.DTABLE, config);  // last line executed and then job exists and completes successfully.

Prior to the last line getting executed I put some debug logs and they show the following:

>> Properties (props):  {}

>> KnowledgeBuilderConfiguration (configuration): org.drools.compiler.PackageBuilderConfiguration@630cb4a4

>> KnowledgeBuilder (kbuilder):  org.drools.builder.impl.KnowledgeBuilderImpl@239bof9d

>> ResourceFactory.newClassPathResource(spreadsheetFile):  [ClassPathResource path='spreadsheet.xls']

>> ResourceType.DTABLE:  ResourceType = 'Decision Table'

>> DecisionTableConfiguration (config):  org.drools.builder.conf.impl.DecisionTableConfigurationImpl@150ab4ed

>> DecisionTableConfiguration (config.getInputType()):  XLS




So I decided to upgrade from drools 5.5.0 to 7.5.0 and use kie-api/kie-ci; I had to do some refactoring because now drools is part of the KIE (Knowledge Is Everything) umbrella, see the code below:

Java
KieServices ks = KieServices.Factory.get();
KieContainer kc = ks.getKieClasspathContainer();
KieSession ks = kc.newKieSession("ksession-dtables");  //stateful session
FactHandle fh = ks.insert(fact);
ks.fireAllRules();


....

The packages and rules are loaded into the Knowledge Base but only the first rules fire up and then it stops, do I need to upgrade my decision table (spreadsheet) in order to work for drools 7.5.0 with Java 8?



Any suggestions are welcome.



Thanks!!

What I have tried:

Figuring out if I need to modify my decision table (spreadsheet) and debug the code to find the culprit.
Posted
Updated 3-Aug-20 9:36am
v2

I used drools 6.5.0 and everything seems to work properly. It seems like drools 7.0.0 and higher use a different decision table (spreadsheet) format.
 
Share this answer
 
I worked on Drools on 2012 and again working on it now with 7 version.
Seems like Im able to make it work with this code

private void getKieRepository() {
if(kieServices == null) {
kieServices = KieServices.Factory.get();
}
final KieRepository kieRepository = kieServices.getRepository();
kieRepository.addKieModule(new KieModule() {
public ReleaseId getReleaseId() {
return kieRepository.getDefaultReleaseId();
}
});
}

@Bean
public KieSession getKieSession() {
System.setProperty("drools.dateformat","MMddyyyy");
getKieRepository();
generateDrl();
KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
kieFileSystem.write(ResourceFactory.newClassPathResource(RULES_PATH + "rules.xlsx"));
KieBuilder kb = kieServices.newKieBuilder(kieFileSystem);
kb.buildAll();
Results results = kb.getResults();
if(results.hasMessages(Message.Level.ERROR)) {
for(Message message : results.getMessages()) {
System.out.println(message.getText());
}
throw new IllegalStateException("###errrors###");
}
KieModule kieModule = kb.getKieModule();
KieContainer kContainer = kieServices.newKieContainer(kieServices.getRepository().getDefaultReleaseId());
KieSession kieSession = kContainer.newKieSession();
return kContainer.newKieSession();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900