use of org.drools.template.model.Condition in project drools by kiegroup.
the class DefaultTemplateColumn method createColumnCondition.
private void createColumnCondition(final Rule rule, final String value) {
SnippetBuilder colSnip = new SnippetBuilder("$param : Column(name == \"$param\")");
Condition colCondition = new Condition();
colCondition.setSnippet(colSnip.build(value));
rule.addCondition(colCondition);
}
use of org.drools.template.model.Condition 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.Condition in project drools by kiegroup.
the class RuleMatrixSheetListener method preInitRuleTable.
/**
* This gets called each time a "new" rule table is found.
*/
protected void preInitRuleTable(final int row, final int column, final String value) {
this.ruleTableColumn = column;
this.ruleTableRow = row;
this.isInRuleTable = true;
this._currentAgendaGroup = getProperties().getSingleProperty(AGENDAGROUP_TAG);
this._action = getProperties().getSingleProperty(ACTION_TAG);
this._horizontalCondition = getProperties().getSingleProperty(HORIZONTALCONDITION_TAG);
this._verticalCondition = getProperties().getSingleProperty(VERTICALCONDITION_TAG);
String precondition = getProperties().getSingleProperty(PRECONDITION_TAG);
if (precondition != null) {
this._currentPrecondition = new Condition();
this._currentPrecondition.setSnippet(precondition);
}
}
use of org.drools.template.model.Condition 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());
}
use of org.drools.template.model.Condition in project drools by kiegroup.
the class RuleWorksheetParseTest method testNumericDisabled.
@Test
public void testNumericDisabled() throws Exception {
// DROOLS-1378
final InputStream stream = RuleWorksheetParseTest.class.getResourceAsStream("/data/NumericDisabled.xls");
final RuleSheetListener listener = getRuleSheetListener(stream);
final Package ruleset = listener.getRuleSet();
assertNotNull(ruleset);
DRLOutput dout = new DRLOutput();
ruleset.renderDRL(dout);
String drl = dout.getDRL();
System.out.println(drl);
// check rules
Rule rule = (Rule) ruleset.getRules().get(0);
Condition cond = (Condition) rule.getConditions().get(0);
assertEquals("Cheese(price == 6600)", cond.getSnippet());
}
Aggregations