Reputation: 1
I was trying to implement the drools BRE and for practice, I initially did it using a .drl file like this:
package com.example.droolstesting;
import com.example.droolstesting.Entities.Applicant;
rule "Suggest Manager Role"
when
applicant:Applicant(
experienceInYears > 10,
currentSalary > 1000000 && <= 2500000
)
then
applicant.setRole("Manager");
end
rule "Suggest Intern Role"
when
applicant:Applicant(
experienceInYears<3,
applicant.currentSalary<1000000
)
then
applicant.setRole("Intern");
end
Now, I want to do the same using Decision Table in excel.
This is my excel file: rules.xlsx
Here's the DroolsConfiguration:
@Configuration
public class DroolsConfiguration {
KieServices kieServices = KieServices.Factory.get();
@Bean
public KieFileSystem kieFileSystem() {
Resource dt = ResourceFactory.newClassPathResource("com\\example\\droolstesting\\rules.xlsx", getClass());
KieFileSystem kieFileSystem = kieServices.newKieFileSystem().write(dt);
// KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
// kieFileSystem.write(ResourceFactory.newClassPathResource("com/example/droolstesting/rules.drl"));
return kieFileSystem;
}
@Bean
public KieContainer kieContainer() {
KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem());
kieBuilder.buildAll();
KieRepository kieRepository = kieServices.getRepository();
ReleaseId krDefaultReleaseId = kieRepository.getDefaultReleaseId();
return kieServices.newKieContainer(krDefaultReleaseId);
}
@Bean
public KieSession kieSession() {
return kieContainer().newKieSession();
}
}
Service Function:
public Applicant suggestARoleForApplicant(Applicant applicant) {
kieSession.insert(applicant);
int rulesFired = kieSession.fireAllRules();
System.out.println("Number of rules fired: " + rulesFired);
return applicant;
}
It is not firing any rules for some reason. I get the Number Of Rules Fired as 0.
I know it might be a really basic issue but can someone please help as to why this is not working?
Upvotes: 0
Views: 161