use of org.drools.template.DataProviderCompiler in project drools by kiegroup.
the class DataDrivenTemplateExample method testCompiler.
public void testCompiler() {
ArrayList<FeeScheduleRule> rules = new ArrayList<FeeScheduleRule>();
FeeScheduleType standard = new FeeScheduleType("STANDARD");
FeeScheduleType flat = new FeeScheduleType("FLAT");
ProductType sblc = new ProductType("SBLC");
ProductType rrc = new ProductType("RRC");
ActivityType iss = new ActivityType("ISS");
ActivityType osx = new ActivityType("OSX");
FeeType commission = new FeeType("Commission");
FeeType postage = new FeeType("Postage");
FeeType telex = new FeeType("Telex");
rules.add(createRule(1, flat, "", sblc, iss, commission, "Party 1", "USD", "", 0, 750, true));
rules.add(createRule(2, standard, "Entity Branch 1", rrc, iss, commission, "", "YEN", "", 0, 1600, false));
rules.add(createRule(3, standard, "", sblc, iss, postage, "", "YEN", "", 0, 40, true));
rules.add(createRule(4, flat, "", sblc, osx, telex, "", "YEN", "<", 30000, 45, false));
TestDataProvider tdp = new TestDataProvider(rules);
final DataProviderCompiler converter = new DataProviderCompiler();
final String drl = converter.compile(tdp, getTemplate());
System.out.println(drl);
}
use of org.drools.template.DataProviderCompiler 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);
}
}
use of org.drools.template.DataProviderCompiler 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;
}
Aggregations