Search in sources :

Example 1 with TemplateContainer

use of org.drools.template.parser.TemplateContainer 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 TemplateContainer

use of org.drools.template.parser.TemplateContainer 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 3 with TemplateContainer

use of org.drools.template.parser.TemplateContainer 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 4 with TemplateContainer

use of org.drools.template.parser.TemplateContainer 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)

Example 5 with TemplateContainer

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

the class ExternalSpreadsheetCompiler method compile.

public String compile(final InputStream xlsStream, final InputStream templateStream, InputType type, int startRow, int startCol) {
    TemplateContainer tc = new DefaultTemplateContainer(templateStream);
    closeStream(templateStream);
    return compile(xlsStream, type, 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)

Aggregations

DefaultTemplateContainer (org.drools.template.parser.DefaultTemplateContainer)5 TemplateContainer (org.drools.template.parser.TemplateContainer)5 TemplateDataListener (org.drools.template.parser.TemplateDataListener)4 InputStream (java.io.InputStream)1 ObjectDataProvider (org.drools.template.objects.ObjectDataProvider)1 Column (org.drools.template.parser.Column)1 Test (org.junit.Test)1