I am upgrading an existing project from an ancient drools version to 9.44. I have successfully used the following code to compile and test a spreadsheet and now I need it to work against one of my CSV files currently in production.
Here is my utility method that returns a KieContainer
/**
* From a decision table, create a rule container.
* @param decisionTableFilename the file name of a decision table to be found on the classpath
* @return a rule base
*/
public KieContainer getKieContainer(final String decisionTableFilename){
KieServices kieServices = KieServices.Factory.get();
Resource resource = ResourceFactory.newClassPathResource(decisionTableFilename, getClass());
KieFileSystem kieFileSystem = kieServices.newKieFileSystem().write(resource);
KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem);
kieBuilder.buildAll();
KieRepository kieRepository = kieServices.getRepository();
ReleaseId krDefaultReleaseId = kieRepository.getDefaultReleaseId();
KieContainer kieContainer = kieServices.newKieContainer(krDefaultReleaseId);
return kieContainer;
}
And here is my test that is running this:
Participant part = ParticipantTest.getSummonedParticipant();
PoolInfo poolInfo = part.getActivePool();
final String courtLocation = "001";
poolInfo.setCourtLocation(courtLocation);
PostponementRequest postponementRequest = new PostponementRequest();
postponementRequest.setPart(part);
GregorianCalendar requestDate = new GregorianCalendar(2025, GregorianCalendar.MAY, 5);
postponementRequest.setRequestDate(requestDate);
assertEquals(courtLocation, poolInfo.getCourtLocation());
assertEquals(2, postponementRequest.getRequestedDayOfWeek());
LinkedList<String> list = new LinkedList<>();
KieContainer kieContainer = droolsUtil.getKieContainer(POSTPONE_RULES_CSV);
StatelessKieSession kieSession = kieContainer.newStatelessKieSession();
List<Object> parms = Arrays.asList(poolInfo, postponementRequest, list);
kieSession.execute(parms);
assertTrue(postponementRequest.isAllowed());
And here is the output I'm getting:
WARN Environment variable M2_HOME is not set
WARN File 'rules/postponementRules.drl.csv' is in folder 'rules' but declares package 'postponementRules'. It is advised to have a correspondance between package and folder names.
ERROR Unable to build KieBaseModel:defaultKieBase
Unable to resolve ObjectType 'PoolInfo' : [Rule name='postponePart_14']
Unable to resolve ObjectType 'LinkedList' : [Rule name='postponePart_14']
Unable to resolve ObjectType 'PostponementRequest' : [Rule name='postponePart_14']
Unable to resolve ObjectType 'PoolInfo' : [Rule name='postponePart_15']
Unable to resolve ObjectType 'LinkedList' : [Rule name='postponePart_15']
Unable to resolve ObjectType 'PostponementRequest' : [Rule name='postponePart_15']
Unable to resolve ObjectType 'PoolInfo' : [Rule name='postponePart_11']
Unable to resolve ObjectType 'LinkedList' : [Rule name='postponePart_11']
Unable to resolve ObjectType 'PostponementRequest' : [Rule name='postponePart_11']
Unable to resolve ObjectType 'PoolInfo' : [Rule name='postponePart_17']
Unable to resolve ObjectType 'LinkedList' : [Rule name='postponePart_17']
Unable to resolve ObjectType 'PostponementRequest' : [Rule name='postponePart_17']
Unable to resolve ObjectType 'PoolInfo' : [Rule name='postponePart_18']
Unable to resolve ObjectType 'LinkedList' : [Rule name='postponePart_18']
Unable to resolve ObjectType 'PostponementRequest' : [Rule name='postponePart_18']
Unable to resolve ObjectType 'PoolInfo' : [Rule name='postponePart_8']
Unable to resolve ObjectType 'LinkedList' : [Rule name='postponePart_8']
Unable to resolve ObjectType 'PostponementRequest' : [Rule name='postponePart_8']
Unable to resolve ObjectType 'PoolInfo' : [Rule name='postponePart_16']
Unable to resolve ObjectType 'LinkedList' : [Rule name='postponePart_16']
Unable to resolve ObjectType 'PostponementRequest' : [Rule name='postponePart_16']
Unable to resolve ObjectType 'PoolInfo' : [Rule name='postponePart_9']
Unable to resolve ObjectType 'LinkedList' : [Rule name='postponePart_9']
Unable to resolve ObjectType 'PostponementRequest' : [Rule name='postponePart_9']
Unable to resolve ObjectType 'PoolInfo' : [Rule name='postponePart_10']
Unable to resolve ObjectType 'LinkedList' : [Rule name='postponePart_10']
Unable to resolve ObjectType 'PostponementRequest' : [Rule name='postponePart_10']
Unable to resolve ObjectType 'PoolInfo' : [Rule name='postponePart_19']
Unable to resolve ObjectType 'LinkedList' : [Rule name='postponePart_19']
Unable to resolve ObjectType 'PostponementRequest' : [Rule name='postponePart_19']
Unable to resolve ObjectType 'PoolInfo' : [Rule name='postponePart_12']
Unable to resolve ObjectType 'LinkedList' : [Rule name='postponePart_12']
Unable to resolve ObjectType 'PostponementRequest' : [Rule name='postponePart_12']
Unable to resolve ObjectType 'PoolInfo' : [Rule name='postponePart_13']
Unable to resolve ObjectType 'LinkedList' : [Rule name='postponePart_13']
Unable to resolve ObjectType 'PostponementRequest' : [Rule name='postponePart_13']
Rule Compilation error : [Rule name='postponePart_16']
cannot find symbol
symbol: variable postponementRequest
location: class rule_table.Rule_postponePart_161987693659
Rule Compilation error : [Rule name='postponePart_11']
cannot find symbol
symbol: variable postponementRequest
location: class rule_table.Rule_postponePart_111987693659
Rule Compilation error : [Rule name='postponePart_8']
cannot find symbol
symbol: variable postponementRequest
location: class rule_table.Rule_postponePart_81987693659
Rule Compilation error : [Rule name='postponePart_14']
cannot find symbol
symbol: variable postponementRequest
location: class rule_table.Rule_postponePart_141987693659
Rule Compilation error : [Rule name='postponePart_18']
cannot find symbol
symbol: variable postponementRequest
location: class rule_table.Rule_postponePart_181987693659
Rule Compilation error : [Rule name='postponePart_13']
cannot find symbol
symbol: variable postponementRequest
location: class rule_table.Rule_postponePart_131987693659
Rule Compilation error : [Rule name='postponePart_10']
cannot find symbol
symbol: variable postponementRequest
location: class rule_table.Rule_postponePart_101987693659
Rule Compilation error : [Rule name='postponePart_9']
cannot find symbol
symbol: variable postponementRequest
location: class rule_table.Rule_postponePart_91987693659
Rule Compilation error : [Rule name='postponePart_15']
cannot find symbol
symbol: variable postponementRequest
location: class rule_table.Rule_postponePart_151987693659
Rule Compilation error : [Rule name='postponePart_17']
cannot find symbol
symbol: variable postponementRequest
location: class rule_table.Rule_postponePart_171987693659
Rule Compilation error : [Rule name='postponePart_19']
cannot find symbol
symbol: variable postponementRequest
location: class rule_table.Rule_postponePart_191987693659
Rule Compilation error : [Rule name='postponePart_12']
cannot find symbol
symbol: variable postponementRequest
location: class rule_table.Rule_postponePart_121987693659
WARN Unable to resolve artifact: org.default:artifact:1.0.0
WARN Unable to resolve artifact: org.default:artifact:pom:1.0.0
java.lang.RuntimeException: Cannot find KieModule: org.default:artifact:1.0.0
at org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieContainer(KieServicesImpl.java:192)
at org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieContainer(KieServicesImpl.java:178)
at com.gs.jxx.util.DroolsUtil.getKieContainer(DroolsUtil.java:70)
at com.gs.jxx.util.DroolsUtilTest.getKieContainer(DroolsUtilTest.java:69)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
The research I've done leads me to believe that the RuntimeException is due to the compiler errors, so that's what I'm focusing on.
I'm also working under the assumption that the cannot find symbol
errors are a result of the unable to resolve ObjectType
, so that's what I'm focusing on.
After lots of searching and reading code, I'm still nowhere to the cause of this. My best guess is that it's not finding my java file for the object type.
Here is the csv file I'm passing in:
Postponement,1,RuleSet,postponementRules,,,,,,,
Postponement,2,Import,"com.gs.jxx.bo.PoolInfo,com.gs.jxx.request.PostponementRequest,java.util.LinkedList",,,,,,,
Postponement,3,RuleTable postponePart,,,,,,,,
Postponement,4,CONDITION,CONDITION,CONDITION,CONDITION,CONDITION,CONDITION,ACTION,,
Postponement,5,pool:PoolInfo...,pool:PoolInfo...,pool:PoolInfo...,list:LinkedList,postponementRequest:PostponementRequest...,postponementRequest:PostponementRequest...,,,
Postponement,6,courtLocation,"daysBeforeSummons >= $1, daysBeforeSummons <= $2",ignoreLeadTime,size >= $param,"requestDaysAfterSummons >= $1, requestDaysAfterSummons <= $2","requestedDayOfWeek >= $1, requestedDayOfWeek <= $2",postponementRequest.setAllowed($param);,,
Postponement,7,Court Location,Lead Time before summons date,IgnoreLeadTime,Always Zero,Postponement Window,Days of Week (2=Monday),Allowed,,
Postponement,8,111,"13,999",false,0,"65,155","2,5",true,,
Postponement,9,111,,true,0,"65,155","2,5",true,,
Postponement,10,222,"13,999",false,0,"65,155","2,5",true,,
Postponement,11,222,,true,0,"65,155","2,5",true,,
Postponement,12,333,"13,999",false,0,"65,155","2,4",true,,
Postponement,13,333,,true,0,"65,155","2,4",true,,
Postponement,14,801,"13,999",false,0,"65,155","2,4",true,,
Postponement,15,801,,true,0,"65,155","2,4",true,,
Postponement,16,401,"13,999",false,0,"65,155","2,5",true,,
Postponement,17,401,,true,0,"65,155","2,5",true,,
Postponement,18,701,"13,999",false,0,"65,155","2,4",true,,
Postponement,19,701,,true,0,"65,155","2,4",true,,
When I run it through the compiler, it appears to be compiling OK.
package rule_table;
//generated from Decision Table
// rule values at C8, header at C3
rule "postponePart_8"
when
pool:PoolInfo(courtLocation == "111", daysBeforeSummons >= 13, daysBeforeSummons <= 999, ignoreLeadTime == "false")
list:LinkedList(size >= 0)
postponementRequest:PostponementRequest(requestDaysAfterSummons >= 65, requestDaysAfterSummons <= 155, requestedDayOfWeek >= 2, requestedDayOfWeek <= 5)
then
postponementRequest.setAllowed(true);
end
// rule values at C9, header at C3
rule "postponePart_9"
when
pool:PoolInfo(courtLocation == "111", ignoreLeadTime == "true")
list:LinkedList(size >= 0)
postponementRequest:PostponementRequest(requestDaysAfterSummons >= 65, requestDaysAfterSummons <= 155, requestedDayOfWeek >= 2, requestedDayOfWeek <= 5)
then
postponementRequest.setAllowed(true);
end
// rule values at C10, header at C3
rule "postponePart_10"
when
pool:PoolInfo(courtLocation == "222", daysBeforeSummons >= 13, daysBeforeSummons <= 999, ignoreLeadTime == "false")
list:LinkedList(size >= 0)
postponementRequest:PostponementRequest(requestDaysAfterSummons >= 65, requestDaysAfterSummons <= 155, requestedDayOfWeek >= 2, requestedDayOfWeek <= 5)
then
postponementRequest.setAllowed(true);
end
// rule values at C11, header at C3
rule "postponePart_11"
when
pool:PoolInfo(courtLocation == "222", ignoreLeadTime == "true")
list:LinkedList(size >= 0)
postponementRequest:PostponementRequest(requestDaysAfterSummons >= 65, requestDaysAfterSummons <= 155, requestedDayOfWeek >= 2, requestedDayOfWeek <= 5)
then
postponementRequest.setAllowed(true);
end
// rule values at C12, header at C3
rule "postponePart_12"
when
pool:PoolInfo(courtLocation == "333", daysBeforeSummons >= 13, daysBeforeSummons <= 999, ignoreLeadTime == "false")
list:LinkedList(size >= 0)
postponementRequest:PostponementRequest(requestDaysAfterSummons >= 65, requestDaysAfterSummons <= 155, requestedDayOfWeek >= 2, requestedDayOfWeek <= 4)
then
postponementRequest.setAllowed(true);
end
// rule values at C13, header at C3
rule "postponePart_13"
when
pool:PoolInfo(courtLocation == "333", ignoreLeadTime == "true")
list:LinkedList(size >= 0)
postponementRequest:PostponementRequest(requestDaysAfterSummons >= 65, requestDaysAfterSummons <= 155, requestedDayOfWeek >= 2, requestedDayOfWeek <= 4)
then
postponementRequest.setAllowed(true);
end
// rule values at C14, header at C3
rule "postponePart_14"
when
pool:PoolInfo(courtLocation == "801", daysBeforeSummons >= 13, daysBeforeSummons <= 999, ignoreLeadTime == "false")
list:LinkedList(size >= 0)
postponementRequest:PostponementRequest(requestDaysAfterSummons >= 65, requestDaysAfterSummons <= 155, requestedDayOfWeek >= 2, requestedDayOfWeek <= 4)
then
postponementRequest.setAllowed(true);
end
// rule values at C15, header at C3
rule "postponePart_15"
when
pool:PoolInfo(courtLocation == "801", ignoreLeadTime == "true")
list:LinkedList(size >= 0)
postponementRequest:PostponementRequest(requestDaysAfterSummons >= 65, requestDaysAfterSummons <= 155, requestedDayOfWeek >= 2, requestedDayOfWeek <= 4)
then
postponementRequest.setAllowed(true);
end
// rule values at C16, header at C3
rule "postponePart_16"
when
pool:PoolInfo(courtLocation == "401", daysBeforeSummons >= 13, daysBeforeSummons <= 999, ignoreLeadTime == "false")
list:LinkedList(size >= 0)
postponementRequest:PostponementRequest(requestDaysAfterSummons >= 65, requestDaysAfterSummons <= 155, requestedDayOfWeek >= 2, requestedDayOfWeek <= 5)
then
postponementRequest.setAllowed(true);
end
// rule values at C17, header at C3
rule "postponePart_17"
when
pool:PoolInfo(courtLocation == "401", ignoreLeadTime == "true")
list:LinkedList(size >= 0)
postponementRequest:PostponementRequest(requestDaysAfterSummons >= 65, requestDaysAfterSummons <= 155, requestedDayOfWeek >= 2, requestedDayOfWeek <= 5)
then
postponementRequest.setAllowed(true);
end
// rule values at C18, header at C3
rule "postponePart_18"
when
pool:PoolInfo(courtLocation == "701", daysBeforeSummons >= 13, daysBeforeSummons <= 999, ignoreLeadTime == "false")
list:LinkedList(size >= 0)
postponementRequest:PostponementRequest(requestDaysAfterSummons >= 65, requestDaysAfterSummons <= 155, requestedDayOfWeek >= 2, requestedDayOfWeek <= 4)
then
postponementRequest.setAllowed(true);
end
// rule values at C19, header at C3
rule "postponePart_19"
when
pool:PoolInfo(courtLocation == "701", ignoreLeadTime == "true")
list:LinkedList(size >= 0)
postponementRequest:PostponementRequest(requestDaysAfterSummons >= 65, requestDaysAfterSummons <= 155, requestedDayOfWeek >= 2, requestedDayOfWeek <= 4)
then
postponementRequest.setAllowed(true);
end
But it won't run. Like I said, the CSV is running in production with drools, so it used to be valid syntax, so it's something that's changed with the versions.
I'm not sure what to do next.
EDIT
After trying many things, I used a spreadsheet we used in production and ran it through the compiler. The interesting difference is that the compiler spat out import statements while there are no import statements coming out of my CSV file. This is the root of the issue.
Now I just need to figure out why.
The issue was apparently being caused by the two extra columns at the beginning of the CSV lines. This was not a problem in previous versions, but evidently is now. Removing those two columns caused the rules to start compiling correctly.