Search in sources :

Example 1 with DataProvider

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

Example 2 with DataProvider

use of org.drools.template.DataProvider in project drools by kiegroup.

the class RuleTemplateModelDRLPersistenceImpl method marshal.

@Override
public String marshal(final RuleModel model) {
    // Build rule
    final String ruleTemplate = marshalRule(model);
    log.debug("ruleTemplate:\n{}", ruleTemplate);
    log.debug("generated template:\n{}", ruleTemplate);
    final DataProvider dataProvider = chooseDataProvider(model);
    final DataProviderCompiler tplCompiler = new DataProviderCompiler();
    final InputStream templateStream = new ByteArrayInputStream(ruleTemplate.getBytes(IoUtils.UTF8_CHARSET));
    final DefaultTemplateContainer tc = new DefaultTemplateContainer(templateStream, false);
    final TemplateDataListener listener = new TemplateDataListener(tc, false);
    final String generatedDrl = tplCompiler.compile(dataProvider, listener);
    log.debug("generated drl:\n{}", generatedDrl);
    return generatedDrl;
}
Also used : DataProvider(org.drools.template.DataProvider) ArrayDataProvider(org.drools.template.objects.ArrayDataProvider) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DataProviderCompiler(org.drools.template.DataProviderCompiler) DefaultTemplateContainer(org.drools.template.parser.DefaultTemplateContainer) TemplateDataListener(org.drools.template.parser.TemplateDataListener)

Aggregations

DataProvider (org.drools.template.DataProvider)2 ArrayDataProvider (org.drools.template.objects.ArrayDataProvider)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 DataProviderCompiler (org.drools.template.DataProviderCompiler)1 DefaultTemplateContainer (org.drools.template.parser.DefaultTemplateContainer)1 TemplateDataListener (org.drools.template.parser.TemplateDataListener)1 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)1