Search in sources :

Example 6 with Condition

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);
}
Also used : Condition(org.drools.template.model.Condition) SnippetBuilder(org.drools.template.model.SnippetBuilder)

Example 7 with Condition

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();
        }
    }
}
Also used : Condition(org.drools.template.model.Condition) Consequence(org.drools.template.model.Consequence)

Example 8 with Condition

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);
    }
}
Also used : Condition(org.drools.template.model.Condition)

Example 9 with Condition

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());
}
Also used : Condition(org.drools.template.model.Condition) Import(org.drools.template.model.Import) InputStream(java.io.InputStream) Consequence(org.drools.template.model.Consequence) Package(org.drools.template.model.Package) Rule(org.drools.template.model.Rule) Test(org.junit.Test)

Example 10 with Condition

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());
}
Also used : Condition(org.drools.template.model.Condition) DRLOutput(org.drools.template.model.DRLOutput) InputStream(java.io.InputStream) Package(org.drools.template.model.Package) Rule(org.drools.template.model.Rule) Test(org.junit.Test)

Aggregations

Condition (org.drools.template.model.Condition)11 Rule (org.drools.template.model.Rule)6 InputStream (java.io.InputStream)5 Package (org.drools.template.model.Package)5 Test (org.junit.Test)4 Consequence (org.drools.template.model.Consequence)3 DRLOutput (org.drools.template.model.DRLOutput)3 SnippetBuilder (org.drools.template.model.SnippetBuilder)3 Import (org.drools.template.model.Import)1