Search in sources :

Example 1 with Condition

use of org.drools.template.model.Condition in project drools by kiegroup.

the class RuleMatrixSheetListener method createCondition.

private Condition createCondition(final String value, final String conditionTemplate) {
    SnippetBuilder snip = new SnippetBuilder(conditionTemplate);
    String result = snip.build(value);
    Condition condition = new Condition();
    condition.setSnippet(result);
    return condition;
}
Also used : Condition(org.drools.template.model.Condition) SnippetBuilder(org.drools.template.model.SnippetBuilder)

Example 2 with Condition

use of org.drools.template.model.Condition in project drools by kiegroup.

the class DefaultTemplateColumn method createCellCondition.

private void createCellCondition(final Rule rule) {
    StringBuffer conditionString = new StringBuffer();
    Column column = templateContainer.getColumn(columnName);
    column.getCondition(condition, index);
    if (notCondition) {
        conditionString.append("not ");
    }
    conditionString.append("exists ");
    conditionString.append(column.getCondition(condition, index));
    SnippetBuilder snip = new SnippetBuilder(conditionString.toString());
    Condition condition = new Condition();
    condition.setSnippet(snip.build(columnName));
    rule.addCondition(condition);
}
Also used : Condition(org.drools.template.model.Condition) SnippetBuilder(org.drools.template.model.SnippetBuilder)

Example 3 with Condition

use of org.drools.template.model.Condition in project drools by kiegroup.

the class RuleWorksheetParseTest method testQuoteEscapingDisabled.

@Test
public void testQuoteEscapingDisabled() throws Exception {
    final InputStream stream = RuleWorksheetParseTest.class.getResourceAsStream("/data/QuoteEscapeDisabledWorkbook.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("Foo(myObject.getColour().equals(red), myObject.size () > \"12\")", cond.getSnippet());
    rule = ruleset.getRules().get(1);
    cond = rule.getConditions().get(0);
    assertEquals("Foo(myObject.getColour().equals(blue), myObject.size () > 12\")", 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)

Example 4 with Condition

use of org.drools.template.model.Condition in project drools by kiegroup.

the class RuleWorksheetParseTest method testQuoteEscapingEnabled.

@Test
public void testQuoteEscapingEnabled() throws Exception {
    final InputStream stream = RuleWorksheetParseTest.class.getResourceAsStream("/data/QuoteEscapeEnabledWorkbook.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 = ruleset.getRules().get(0);
    Condition cond = rule.getConditions().get(0);
    assertEquals("Foo(myObject.getColour().equals(red), myObject.size () > 12\\\")", 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)

Example 5 with Condition

use of org.drools.template.model.Condition in project drools by kiegroup.

the class DefaultTemplateRuleBase method createTemplateRule.

private void createTemplateRule(org.drools.template.model.Package p, int index, RuleTemplate template) {
    Rule rule = new Rule(template.getName(), null, index);
    Condition condition = new Condition();
    condition.setSnippet("r : Row()");
    rule.addCondition(condition);
    createColumnConditions(template, rule);
    rule.addConsequence(createConsequence(template));
    p.addRule(rule);
}
Also used : Condition(org.drools.template.model.Condition) Rule(org.drools.template.model.Rule)

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