use of org.drools.template.parser.TemplateDataListener 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));
}
use of org.drools.template.parser.TemplateDataListener in project drools by kiegroup.
the class ExternalSpreadsheetCompilerTest method testPricing.
@Test
public void testPricing() throws Exception {
final ExternalSpreadsheetCompiler converter = new ExternalSpreadsheetCompiler();
final List<DataListener> listeners = new ArrayList<DataListener>();
TemplateDataListener l1 = new TemplateDataListener(10, 3, "/templates/test_pricing1.drl");
listeners.add(l1);
TemplateDataListener l2 = new TemplateDataListener(30, 3, "/templates/test_pricing2.drl");
listeners.add(l2);
converter.compile("/data/ExamplePolicyPricing.xls", InputType.XLS, listeners);
// COMPILE
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(l1.renderDRL().getBytes()), ResourceType.DRL);
kbuilder.add(ResourceFactory.newByteArrayResource(l2.renderDRL().getBytes()), ResourceType.DRL);
assertFalse(kbuilder.hasErrors());
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
KieSession kSession = kbase.newKieSession();
// now create some test data
Driver driver = new Driver();
Policy policy = new Policy();
kSession.insert(driver);
kSession.insert(policy);
kSession.fireAllRules();
System.out.println("BASE PRICE IS: " + policy.getBasePrice());
System.out.println("DISCOUNT IS: " + policy.getDiscountPercent());
int basePrice = policy.getBasePrice();
assertEquals(120, basePrice);
}
use of org.drools.template.parser.TemplateDataListener 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));
}
use of org.drools.template.parser.TemplateDataListener 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));
}
use of org.drools.template.parser.TemplateDataListener 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));
}
Aggregations