Search in sources :

Example 1 with Consequence

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

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

Example 3 with Consequence

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

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

Example 5 with 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());
}
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)

Aggregations

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