Search in sources :

Example 1 with RuleAttribute

use of org.drools.workbench.models.datamodel.rule.RuleAttribute in project drools by kiegroup.

the class RuleModelDRLPersistenceImpl method parseAttributes.

private boolean parseAttributes(final RuleModel m, final Map<String, AttributeDescr> attributes) {
    boolean isJavaDialect = false;
    for (Map.Entry<String, AttributeDescr> entry : attributes.entrySet()) {
        String name = entry.getKey();
        String value = normalizeAttributeValue(entry.getValue().getValue().trim());
        RuleAttribute ruleAttribute = new RuleAttribute(name, value);
        m.addAttribute(ruleAttribute);
        isJavaDialect |= name.equals("dialect") && value.equals("java");
    }
    return isJavaDialect;
}
Also used : RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) Map(java.util.Map) HashMap(java.util.HashMap) AttributeDescr(org.drools.compiler.lang.descr.AttributeDescr)

Example 2 with RuleAttribute

use of org.drools.workbench.models.datamodel.rule.RuleAttribute in project drools by kiegroup.

the class RuleModelDRLPersistenceTest method testInsertLogical.

@Test
public void testInsertLogical() {
    String expected = "rule \"my rule\"\n\tno-loop true\n\tdialect \"mvel\"\n\twhen\n\t\tPerson( )\n" + "\t\tAccident( )\n\tthen\n\t\tinsertLogical( new Report() );\nend\n";
    final RuleModel m = new RuleModel();
    m.addLhsItem(new FactPattern("Person"));
    m.addLhsItem(new FactPattern("Accident"));
    m.addAttribute(new RuleAttribute("no-loop", "true"));
    m.addRhsItem(new ActionInsertLogicalFact("Report"));
    m.name = "my rule";
    checkMarshalling(expected, m);
}
Also used : RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) ActionInsertLogicalFact(org.drools.workbench.models.datamodel.rule.ActionInsertLogicalFact) Test(org.junit.Test)

Example 3 with RuleAttribute

use of org.drools.workbench.models.datamodel.rule.RuleAttribute in project drools by kiegroup.

the class RuleModelDRLPersistenceTest method testRHSSetMethodCallsMethodMVEL.

@Test
public void testRHSSetMethodCallsMethodMVEL() {
    String oldValue = System.getProperty("drools.dateformat");
    try {
        System.setProperty("drools.dateformat", "dd-MMM-yyyy");
        RuleModel m = new RuleModel();
        m.name = "RHS SetMethodCallsMethod";
        m.addAttribute(new RuleAttribute("dialect", "mvel"));
        FactPattern p = new FactPattern("Person");
        p.setBoundName("$p");
        m.addLhsItem(p);
        ActionCallMethod acm = new ActionCallMethod();
        acm.setMethodName("method");
        acm.setVariable("$p");
        acm.addFieldValue(new ActionFieldFunction("f1", "String", DataType.TYPE_STRING));
        acm.addFieldValue(new ActionFieldFunction("f2", "true", DataType.TYPE_BOOLEAN));
        acm.addFieldValue(new ActionFieldFunction("f3", "31-Jan-2012", DataType.TYPE_DATE));
        acm.addFieldValue(new ActionFieldFunction("f4", "100", DataType.TYPE_NUMERIC_INTEGER));
        acm.addFieldValue(new ActionFieldFunction("f5", "100", DataType.TYPE_NUMERIC_BIGDECIMAL));
        m.addRhsItem(acm);
        String result = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
        assertTrue(result.indexOf("java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(\"dd-MMM-yyyy\");") != -1);
        assertTrue(result.indexOf("$p.method( \"String\", true, sdf.parse(\"31-Jan-2012\"), 100, 100B );") != -1);
        checkMarshalling(null, m);
    } finally {
        if (oldValue == null) {
            System.clearProperty("drools.dateformat");
        } else {
            System.setProperty("drools.dateformat", oldValue);
        }
    }
}
Also used : RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) ActionCallMethod(org.drools.workbench.models.datamodel.rule.ActionCallMethod) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) ActionFieldFunction(org.drools.workbench.models.datamodel.rule.ActionFieldFunction) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 4 with RuleAttribute

use of org.drools.workbench.models.datamodel.rule.RuleAttribute in project drools by kiegroup.

the class RuleModelDRLPersistenceTest method testCalendarsWithQuotes.

@Test
public void testCalendarsWithQuotes() {
    // BZ1059232 - Guided rule editor: calendars attribute is broken when a list of calendars is used
    RuleModel m = new RuleModel();
    m.attributes = new RuleAttribute[1];
    m.attributes[0] = new RuleAttribute("calendars", "\"a\", \"b\"");
    final String drl = ruleModelPersistence.marshal(m);
    assertTrue(drl.indexOf("calendars \"a\", \"b\"") > 0);
}
Also used : RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Example 5 with RuleAttribute

use of org.drools.workbench.models.datamodel.rule.RuleAttribute in project drools by kiegroup.

the class RuleModelDRLPersistenceTest method testDefaultMVEL.

@Test
public void testDefaultMVEL() {
    RuleModel m = new RuleModel();
    String s = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
    assertTrue(s.indexOf("mvel") > -1);
    m.addAttribute(new RuleAttribute("dialect", "goober"));
    s = RuleModelDRLPersistenceImpl.getInstance().marshal(m);
    assertFalse(s.indexOf("mvel") > -1);
    assertTrue(s.indexOf("goober") > -1);
}
Also used : RuleAttribute(org.drools.workbench.models.datamodel.rule.RuleAttribute) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) Test(org.junit.Test)

Aggregations

RuleAttribute (org.drools.workbench.models.datamodel.rule.RuleAttribute)33 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)25 Test (org.junit.Test)24 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)14 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)14 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)12 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)12 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)12 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)11 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)11 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)10 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)9 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)7 ActionGlobalCollectionAdd (org.drools.workbench.models.datamodel.rule.ActionGlobalCollectionAdd)4 CompositeFieldConstraint (org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint)4 FieldConstraint (org.drools.workbench.models.datamodel.rule.FieldConstraint)4 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)4 ActionCallMethod (org.drools.workbench.models.datamodel.rule.ActionCallMethod)3 ActionFieldFunction (org.drools.workbench.models.datamodel.rule.ActionFieldFunction)3 ActionRetractFact (org.drools.workbench.models.datamodel.rule.ActionRetractFact)3