Issue defining evidence in drl - related evidence java file is not getting generated

51 views
Skip to first unread message

Polly D

unread,
Mar 23, 2022, 9:02:11 AM3/23/22
to Drools Usage
Hi there, 

I am trying to convert the java defined evidence classes that is being used within the drools rules implementation in to drl files using the declare definition. When I add the evidence to the drl files and install & build the changes the related java files for the evidence is not getting generated so can not be found in the rules implementation or tests.  I have outlined a simple example and the steps I followed  below. If anyone has come across this issue or can identify any step I may have missed any help would be appreciated.


Issue - related drl java file is not generated

Error details - "java.lang.NullPointerException: Cannot invoke "org.kie.api.definition.type.FactType.newInstance()" because "caseHeaderFactType" is null"

The definition of the fact type 'CaseHeaderFact' is not available as a fact type to create an instance of this object in a test. This java generated definition file is not getting created.  


Steps to define  an evidence file in drl. 


package evidence;
 
declare CaseHeaderFact
  long : caseID;
  CaseType : caseType;
end
  • Update the pom xml file to include the dependencies for model generation and complete a maven update, and install

    <dependency>

      <groupId>org.drools</groupId>
      <artifactId>drools-model-compiler</artifactId>
      <version>${drools.version}</version>
    </dependency>
    <dependency>
      <groupId>org.drools</groupId>
      <artifactId>drools-canonical-model</artifactId>
      <version>${drools.version}</version>
    </dependency>
  • Create an instance of the evidence fact from a unit test 

     FactType caseHeaderFactType = session.getKieBase().getFactType("evidence",  "CaseHeaderFact");
     Object caseHeader = caseHeaderFactType.newInstance(); 
     caseHeaderFactType.set(caseHeader, "caseID", 101);
     caseHeaderFactType.set(caseHeader, "caseType", CaseType.PRODUCTDELIVERY);
     factList.add(caseHeaderFactType); 


Reply all
Reply to author
Forward
0 new messages