Version 6

    Here are some quick notes on how to use the new Decision Table rule templates, which is currently an incubating/experimental technology.

     

    The new process separates the rule template from the data. This allows much more flexibility in how rules are created and will also make it easier to use databases and web-based spreadsheets.

     

    Use the following code to use a Decision Table template:

    ExternalSpreadsheetCompiler converter = new ExternalSpreadsheetCompiler();
    String drl = converter.compile("path_to_xls", "path_to_template", start_row, start_column);
    

    For example:

    ExternalSpreadsheetCompiler converter = new ExternalSpreadsheetCompiler();
    String drl = converter.compile("/data/IntegrationExampleTest.xls", "/templates/test_integration.drl", 18, 3);
    

    This will apply the test_integration.drl template against IntegrationExampleTest.xls where the decision table starts in row 18, column 3.

     

    A decision table template is a file with the following format:

     

    1  template header
    2  column1
    3  column2
    4  column3[]
    5  column4
    6
    7  package "package_name";
    8
    9  import ...;
    10
    11 global ...;
    12
    13 function ...;
    14
    15 template "template_name"
    16 required_column_1
    17 required_column_2
    18 !excluded_column_3
    19 
    20 rule "rule_name $row.rowNumber$"
    21   rule_body
    22 end
    23 rule ...
    24 end
    25 end template
    26
    27 template ...
    28 end template
    

    Line

    Description

    1

    template header - required at start of file

    2-5

    Columns in decision table starting from left. {FOOTNOTE DEF  } marks the column as an array (comma-separated)

    7-13

    Standard package, import and global declarations

    15

    Start of first template definition. Template name must be unique in file.

    16-17

    Columns (as defined in lines 2-5) that must have a value for this rule to be generated for the row

    18

    Column that must not have a value for this rule to be generated for the row

    20

    Rule name - must be unique when generated, hence @{row.rowNumber}. The templates are currently evaluated using StringTemplate, the row object is added by the engine. At some point in the future we will switch to MVEL. Note that you can have multiple rules within the one template definition.

    21

    Body of rule

    The body of a rule takes the same form as a normal DRL rule with the exceptions as listed below.

    22

    End of rule

    23

    You can have more than one rule within a template definition.

    28

    End of template

    27-28

    Additional templates

     

    Rule body restrictions:

    • you can use @ anywhere in the rule, which will be replaced with the value in the column

    • any line referring to an empty column will not be generated into the rule

    • to refer to an array column use @{columnnameindex} (ie. @, @)

     

    For more info look at ExternalSpreadsheetCompilerIntegrationTest in the drools-decisiontables project for an example of how to use the templates.

     

    Future enhancements:

    • web-based decision tables

    • using database result set as decision table

    • provision of generic templates for standard decision tables