Search in sources :

Example 1 with ArrayDataProvider

use of org.drools.template.objects.ArrayDataProvider in project drools by kiegroup.

the class TemplatesTest method loadingFromDLRArrayCorrectnessCheck.

@Test
public void loadingFromDLRArrayCorrectnessCheck() throws Exception {
    final String[][] rows = new String[3][6];
    rows[0] = new String[] { "tomato", "weight", "200", "1000", "6", "== Taste.GOOD || == Taste.EXCELENT" };
    rows[1] = new String[] { "cucumber", "length", "20", "40", "15", "== Taste.EXCELENT" };
    rows[2] = new String[] { "carrot", "weight", "0", "1000", "2", "== Taste.HORRIBLE" };
    final ArrayDataProvider adp = new ArrayDataProvider(rows);
    final DataProviderCompiler converter = new DataProviderCompiler();
    try (InputStream resourceStream = KieServices.Factory.get().getResources().newClassPathResource("template_1.drl", getClass()).getInputStream()) {
        final String drl = converter.compile(adp, resourceStream);
        // prints rules generated from template
        LOGGER.debug(drl);
        assertEqualsIgnoreWhitespace(EXPECTED_RULES.toString(), drl);
        testCorrectnessCheck(drl);
    }
}
Also used : InputStream(java.io.InputStream) ArrayDataProvider(org.drools.template.objects.ArrayDataProvider) DataProviderCompiler(org.drools.template.DataProviderCompiler) Test(org.junit.Test)

Example 2 with ArrayDataProvider

use of org.drools.template.objects.ArrayDataProvider in project drools by kiegroup.

the class RuleTemplateModelDRLPersistenceImpl method chooseDataProvider.

private DataProvider chooseDataProvider(final RuleModel model) {
    DataProvider dataProvider;
    TemplateModel tplModel = (TemplateModel) model;
    if (tplModel.getRowsCount() > 0) {
        dataProvider = new ArrayDataProvider(tplModel.getTableAsArray());
    } else {
        dataProvider = generateEmptyIterator();
    }
    return dataProvider;
}
Also used : DataProvider(org.drools.template.DataProvider) ArrayDataProvider(org.drools.template.objects.ArrayDataProvider) ArrayDataProvider(org.drools.template.objects.ArrayDataProvider) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel)

Aggregations

ArrayDataProvider (org.drools.template.objects.ArrayDataProvider)2 InputStream (java.io.InputStream)1 DataProvider (org.drools.template.DataProvider)1 DataProviderCompiler (org.drools.template.DataProviderCompiler)1 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)1 Test (org.junit.Test)1