Search in sources :

Example 6 with DRLOutput

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

the class DefaultTemplateRuleBase method getDTRules.

/**
 * @param templates
 * @return
 */
private String getDTRules(Map<String, RuleTemplate> templates) {
    org.drools.template.model.Package p = new org.drools.template.model.Package(DefaultTemplateRuleBase.class.getPackage().getName());
    addImports(p);
    addGlobals(p);
    int i = 1;
    for (RuleTemplate template : templates.values()) {
        createTemplateRule(p, i++, template);
    }
    DRLOutput out = new DRLOutput();
    p.renderDRL(out);
    return out.getDRL();
}
Also used : DRLOutput(org.drools.template.model.DRLOutput) InternalKnowledgePackage(org.drools.core.definitions.InternalKnowledgePackage)

Example 7 with DRLOutput

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

the class SpreadsheetCompiler method listenerToString.

public String listenerToString(RuleSheetListener listener) {
    final Package rulePackage = listener.getRuleSet();
    final DRLOutput out = new DRLOutput();
    rulePackage.renderDRL(out);
    return out.getDRL();
}
Also used : DRLOutput(org.drools.template.model.DRLOutput) Package(org.drools.template.model.Package)

Example 8 with DRLOutput

use of org.drools.template.model.DRLOutput 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)

Example 9 with DRLOutput

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

the class RuleWorksheetParseTest method testMissingCodeSnippetAction.

/**
 * Must have a code snippet in an action.
 */
@Test
public void testMissingCodeSnippetAction() {
    try {
        makeRuleSet();
        makeRuleTable();
        makeRow(11, "C", "A");
        makeRow(12, "foo: Foo", "Bar()");
        makeRow(13, "attr == $param");
        makeRow(15, "1", "1");
        makeRow(16, "2", "2");
        listener.finishSheet();
        Package p = listener.getRuleSet();
        DRLOutput dout = new DRLOutput();
        p.renderDRL(dout);
        String drl = dout.getDRL();
        System.out.println(drl);
        fail("should have failed");
    } catch (DecisionTableParseException e) {
        String badCell = RuleSheetParserUtil.rc2name(13, 2);
        System.err.println(e.getMessage());
        assertTrue(e.getMessage().contains(badCell));
    }
}
Also used : DRLOutput(org.drools.template.model.DRLOutput) DecisionTableParseException(org.drools.template.parser.DecisionTableParseException) Package(org.drools.template.model.Package) Test(org.junit.Test)

Example 10 with DRLOutput

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

the class RuleWorksheetParseTest method testDuplicatePackageAttribute.

/**
 * Duplicate package level attribute
 */
@Test
public void testDuplicatePackageAttribute() {
    try {
        makeRuleSet();
        // B3, C3
        makeAttribute("agenda-group", "agroup");
        // B3. B4
        makeAttribute("agenda-group", "bgroup");
        makeRuleTable();
        makeRow(11, "C", "A", "P");
        makeRow(12, "Foo", "Foo");
        makeRow(13, "attr == $param", "x");
        makeRow(15, "1", "show()", "10");
        listener.finishSheet();
        Package p = listener.getRuleSet();
        DRLOutput dout = new DRLOutput();
        p.renderDRL(dout);
        String drl = dout.getDRL();
        // System.out.println( drl );
        fail("should have failed");
    } catch (DecisionTableParseException e) {
        System.err.println(e.getMessage());
        assertTrue(e.getMessage().contains("C3, C4"));
    }
}
Also used : DRLOutput(org.drools.template.model.DRLOutput) DecisionTableParseException(org.drools.template.parser.DecisionTableParseException) Package(org.drools.template.model.Package) Test(org.junit.Test)

Aggregations

DRLOutput (org.drools.template.model.DRLOutput)12 Package (org.drools.template.model.Package)10 Test (org.junit.Test)9 InputStream (java.io.InputStream)4 Rule (org.drools.template.model.Rule)4 Condition (org.drools.template.model.Condition)3 DecisionTableParseException (org.drools.template.parser.DecisionTableParseException)2 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)1