I am using Spring Boot 2.1.6.RELEASE with drools version 7.28.0.Final.
We have two model classes and am trying to execute rules using DRL file on top of it
Model Classes
public class VendorReferences {
private String vendorCode;
private String vendorName;
private boolean isChecked;
private boolean isEnabled;
//gettters setters defult contructor and parametrized constructor for all args
}
public class Vendor {
private String vendorCode;
private String vendorName;
private boolean isChecked;
private boolean isEnabled;
//other additional attributes
}
public class SubmissionObject {
private String product;
}
Kie Container Config Class
@Configuration
public class RulesConfig {
@Bean
public KieContainer kieContainer() {
KieServices kieServices = KieServices.Factory.get();
KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
kieFileSystem.write(ResourceFactory.newClassPathResource(DRL_FILE));
KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem);
kieBuilder.buildAll();
KieModule kieModule = kieBuilder.getKieModule();
return kieServices.newKieContainer(kieModule.getReleaseId());
}
}
DRL file
//model classes imports
import java.util.ArrayList;
import java.util.Iterator;
import java.util.stream.Collectors;
global java.util.ArrayList vendorList;
global java.util.ArrayList lstDistributionVendor;
dialect "mvel"
rule "Product Rule"
no-loop true
when
$submissionObject: SubmissionObject(product!= null);
then
for(VendorReferences vendorRef:lstDistributionVendor){
VendorReferences vendorObj=new VendorReferences();
vendorObj.setVendorCode(vendorRef.getVendorCode());
vendorObj.setChecked(vendorRef.isChecked());
vendorList.add(vendorObj);
}
end
In above DRL file am trying to iterate the arraylist to set the limited properties of VendorReferences object and then trying to add in the arraylist.
public List<VendorReferences> applicableVendors(SubmissionObject submissionObject) {
KieSession kieSession = kieContainer.newKieSession();
ArrayList<VendorReferences> vendorList = new ArrayList<>();
kieSession.setGlobal("vendorList", vendorList);
kieSession.setGlobal("lstDistributionVendor", lstDistributionVendor);
kieSession.insert(submissionObject);
kieSession.fireAllRules();
kieSession.dispose();
return vendorList;
}
When I am trying to execute the DRL file using the above code I am getting below error.
Exception executing consequence for rule "Product Rule" in defaultpkg: [Error: unable to resolve method: org.drools.core.base.DefaultKnowledgeHelper.isChecked() [arglength=0]]
[Near : {... endorObj.setChecked(vendorRef.isChecked()); v ....}]
^
[Line: 1, Column: 269]
I am not able to understand why drools is trying to look into some different class DefaultKnowledgeHelper to check the method instead of model class.
How can I solve the above error?