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
    7  package "package_name";
    9  import ...;
    11 global ...;
    13 function ...;
    15 template "template_name"
    16 required_column_1
    17 required_column_2
    18 !excluded_column_3
    20 rule "rule_name $row.rowNumber$"
    21   rule_body
    22 end
    23 rule ...
    24 end
    25 end template
    27 template ...
    28 end template




    template header - required at start of file


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


    Standard package, import and global declarations


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


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


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


    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.


    Body of rule

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


    End of rule


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


    End of template


    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