Drools - Using “from” in decision table

冷暖自知 提交于 2019-12-09 03:44:25

The pattern format you want to have is not possible with the Drools spreadsheet compiler. If you read the documentation, it will say that the cell under CONDITION provides the pattern CE, typically a class name, and the next cell below specifies a constraint, i.e., an expression that must fit between the pair of parentheses added to the pattern above. The placeholder $param will then repeatedly be replaced by cell values further down the column.

Adding the missing parentheses, your condition expands into (invalid) DRL code:

$person:Person( ArrayList( size >= 1 ) 
from collect( TestResult( name in ("TestA","TestB"), result == 'high' ) 
   from $person.getLabResults() ) )

This causes just the error message you've reported, due to the misplaced from.

I have this snippet of code lying around, and if you can import class SpreadsheetCompiler from wherever it is, a call will display the generated DRL, right or wrong.

private void testSpreadsheet(String dtPath){
  File dtf = new File( dtPath );
  InputStream is;
  try {
    is = new FileInputStream( dtf );
    SpreadsheetCompiler ssComp = new SpreadsheetCompiler();
    String s = ssComp.compile( is, InputType.XLS );
    System.out.println( "=== Begin generated DRL ===" );
    System.out.println( s );
    System.out.println( "=== End generated DRL ===" );
  } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
}

If you need to generate lots of rules with lists of test results you should look into Drools templates. With this technique, parameter insertion into arbitrary rule text is possible. Other workarounds may also be viable, e.g., a combination of DRL and spreadsheet rules.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!