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;
}
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);
}
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);
}
}
}
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);
}
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);
}
Aggregations