Search in sources :

Example 1 with DefaultTemplateContainer

use of org.drools.template.parser.DefaultTemplateContainer in project drools by kiegroup.

the class ExternalSpreadsheetCompiler method compile.

public String compile(final InputStream xlsStream, final String worksheetName, final InputStream templateStream, int startRow, int startCol) {
    TemplateContainer tc = new DefaultTemplateContainer(templateStream);
    closeStream(templateStream);
    return compile(xlsStream, worksheetName, new TemplateDataListener(startRow, startCol, tc));
}
Also used : TemplateContainer(org.drools.template.parser.TemplateContainer) DefaultTemplateContainer(org.drools.template.parser.DefaultTemplateContainer) DefaultTemplateContainer(org.drools.template.parser.DefaultTemplateContainer) TemplateDataListener(org.drools.template.parser.TemplateDataListener)

Example 2 with DefaultTemplateContainer

use of org.drools.template.parser.DefaultTemplateContainer in project drools by kiegroup.

the class DataProviderCompiler method compile.

/**
 * Generates DRL from a data provider for the spreadsheet data and templates.
 *
 * @param dataProvider   the data provider for the spreadsheet data
 * @param templateStream the InputStream for reading the templates
 * @return the generated DRL text as a String
 */
public String compile(final DataProvider dataProvider, final InputStream templateStream, boolean replaceOptionals) {
    DefaultTemplateContainer tc = new DefaultTemplateContainer(templateStream, replaceOptionals);
    closeStream(templateStream);
    return compile(dataProvider, new TemplateDataListener(tc));
}
Also used : DefaultTemplateContainer(org.drools.template.parser.DefaultTemplateContainer) TemplateDataListener(org.drools.template.parser.TemplateDataListener)

Example 3 with DefaultTemplateContainer

use of org.drools.template.parser.DefaultTemplateContainer in project drools by kiegroup.

the class ObjectDataCompiler method compile.

/**
 * Compile templates, substituting from a collection of maps or objects
 * into the given template.
 *
 * @param objs           objs the collection of maps or objects
 * @param templateStream the template as a stream
 * @return the expanded rules as a string
 */
public String compile(final Collection<?> objs, final InputStream templateStream) {
    TemplateContainer tc = new DefaultTemplateContainer(templateStream);
    closeStream(templateStream);
    return compile(new ObjectDataProvider(tc, objs), new TemplateDataListener(tc));
}
Also used : TemplateContainer(org.drools.template.parser.TemplateContainer) DefaultTemplateContainer(org.drools.template.parser.DefaultTemplateContainer) DefaultTemplateContainer(org.drools.template.parser.DefaultTemplateContainer) ObjectDataProvider(org.drools.template.objects.ObjectDataProvider) TemplateDataListener(org.drools.template.parser.TemplateDataListener)

Example 4 with DefaultTemplateContainer

use of org.drools.template.parser.DefaultTemplateContainer in project drools by kiegroup.

the class ResultSetGenerator method compile.

/**
 * Generates DRL from a data provider for the spreadsheet data and templates.
 *
 * @param rs             the resultset for the table data
 * @param templateStream the InputStream for reading the templates
 * @return the generated DRL text as a String
 */
public String compile(final ResultSet rs, final InputStream templateStream) {
    TemplateContainer tc = new DefaultTemplateContainer(templateStream);
    closeStream(templateStream);
    return compile(rs, new TemplateDataListener(tc));
}
Also used : TemplateContainer(org.drools.template.parser.TemplateContainer) DefaultTemplateContainer(org.drools.template.parser.DefaultTemplateContainer) DefaultTemplateContainer(org.drools.template.parser.DefaultTemplateContainer) TemplateDataListener(org.drools.template.parser.TemplateDataListener)

Example 5 with DefaultTemplateContainer

use of org.drools.template.parser.DefaultTemplateContainer in project drools by kiegroup.

the class DataProviderCompilerTest method testCompilerMaps.

@Test
public void testCompilerMaps() throws Exception {
    Collection<Map<String, Object>> maps = new ArrayList<Map<String, Object>>();
    final ObjectDataCompiler converter = new ObjectDataCompiler();
    InputStream templateStream = this.getClass().getResourceAsStream("/templates/rule_template_1.drl");
    TemplateContainer tc = new DefaultTemplateContainer(templateStream);
    Column[] columns = tc.getColumns();
    for (String[] row : rows) {
        Map<String, Object> map = new HashMap<String, Object>();
        for (int icol = 0; icol < columns.length; icol++) {
            Object value = row[icol];
            if (value != null) {
                map.put(columns[icol].getName(), value);
            }
        }
        maps.add(map);
    }
    templateStream = this.getClass().getResourceAsStream("/templates/rule_template_1.drl");
    final String drl = converter.compile(maps, templateStream);
    Assertions.assertThat(EXPECTED_RULES.toString()).isEqualToIgnoringWhitespace(drl);
}
Also used : TemplateContainer(org.drools.template.parser.TemplateContainer) DefaultTemplateContainer(org.drools.template.parser.DefaultTemplateContainer) InputStream(java.io.InputStream) DefaultTemplateContainer(org.drools.template.parser.DefaultTemplateContainer) Column(org.drools.template.parser.Column) Test(org.junit.Test)

Aggregations

DefaultTemplateContainer (org.drools.template.parser.DefaultTemplateContainer)7 TemplateDataListener (org.drools.template.parser.TemplateDataListener)6 TemplateContainer (org.drools.template.parser.TemplateContainer)5 InputStream (java.io.InputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataProvider (org.drools.template.DataProvider)1 DataProviderCompiler (org.drools.template.DataProviderCompiler)1 ArrayDataProvider (org.drools.template.objects.ArrayDataProvider)1 ObjectDataProvider (org.drools.template.objects.ObjectDataProvider)1 Column (org.drools.template.parser.Column)1 Test (org.junit.Test)1