use of org.drools.template.model.Consequence in project drools by kiegroup.
the class DefaultTemplateRuleBase method createConsequence.
private Consequence createConsequence(RuleTemplate template) {
StringBuffer action = new StringBuffer();
action.append("generator.generate( \"");
action.append(template.getName()).append("\", r);");
final Consequence consequence = new Consequence();
consequence.setSnippet(action.toString());
return consequence;
}
use of org.drools.template.model.Consequence in project drools by kiegroup.
the class DefaultRuleSheetListener method flushRule.
/**
* This makes sure that the rules have all their components added.
* As when there are merged/spanned cells, they may be left out.
*/
private void flushRule() {
for (SourceBuilder src : sourceBuilders) {
if (src.hasValues()) {
switch(src.getActionTypeCode()) {
case CONDITION:
Condition cond = new Condition();
cond.setSnippet(src.getResult());
_currentRule.addCondition(cond);
break;
case ACTION:
Consequence cons = new Consequence();
cons.setSnippet(src.getResult());
_currentRule.addConsequence(cons);
break;
case METADATA:
_currentRule.addMetadata(src.getResult());
break;
}
src.clearValues();
}
}
}
use of org.drools.template.model.Consequence in project drools by kiegroup.
the class RuleMatrixSheetListener method createRule.
private void createRule(final int row, final int column, final String value) {
final Consequence consequence = createConsequence(value);
Rule rule = firstRule;
if (rule == null) {
rule = new Rule("rule_" + row + "_" + column, null, row);
addRule(rule);
} else {
firstRule = null;
rule.setName("rule_" + row + "_" + column);
}
rule.setAgendaGroup(this._currentAgendaGroup);
rule.addCondition(this._currentPrecondition);
rule.addCondition(_currentVerticalCondition);
rule.addCondition((Condition) _horizontalConditions.get(column - (ruleTableColumn + 1)));
rule.addConsequence(consequence);
}
use of org.drools.template.model.Consequence in project drools by kiegroup.
the class RuleMatrixSheetListener method createConsequence.
private Consequence createConsequence(final String value) {
final SnippetBuilder snip = new SnippetBuilder(_action);
final String result = snip.build(value);
final Consequence consequence = new Consequence();
consequence.setSnippet(result);
return consequence;
}
use of org.drools.template.model.Consequence in project drools by kiegroup.
the class RuleWorksheetParseTest method testWorkbookParse.
@Test
public void testWorkbookParse() throws Exception {
final InputStream stream = RuleWorksheetParseTest.class.getResourceAsStream("/data/BasicWorkbook.xls");
final RuleSheetListener listener = getRuleSheetListener(stream);
final Package ruleset = listener.getRuleSet();
assertNotNull(ruleset);
final Rule firstRule = (Rule) ruleset.getRules().get(0);
assertNotNull(firstRule.getSalience());
assertTrue(Integer.parseInt(firstRule.getSalience()) > 0);
// System.out.println(ruleset.toXML());
assertEquals("myruleset", ruleset.getName());
assertEquals(3, ruleset.getImports().size());
assertEquals(6, ruleset.getRules().size());
// check imports
Import imp = (Import) ruleset.getImports().get(0);
assertEquals("blah.class1", imp.getClassName());
imp = (Import) ruleset.getImports().get(1);
assertEquals("blah.class2", imp.getClassName());
imp = (Import) ruleset.getImports().get(2);
assertEquals("lah.di.dah", imp.getClassName());
// check rules
Rule rule = (Rule) ruleset.getRules().get(0);
Condition cond = (Condition) rule.getConditions().get(0);
assertEquals("Foo(myObject.getColour().equals(red), myObject.size () > 12\\\")", cond.getSnippet());
Consequence cons = (Consequence) rule.getConsequences().get(0);
assertNotNull(cons);
assertEquals("myObject.setIsValid(Y);", cons.getSnippet());
rule = (Rule) ruleset.getRules().get(5);
cond = (Condition) rule.getConditions().get(1);
assertEquals("myObject.size () > 7", cond.getSnippet());
cons = (Consequence) rule.getConsequences().get(0);
assertEquals("myObject.setIsValid(10-Jul-1974)", cons.getSnippet());
}
Aggregations