use of org.drools.workbench.models.datamodel.rule.FreeFormLine in project drools-wb by kiegroup.
the class RuleModellerConditionSelectorPopup method addFreeFormDrl.
// Free form DRL
private void addFreeFormDrl() {
choices.addItem(SECTION_SEPARATOR);
choices.addItem(GuidedRuleEditorResources.CONSTANTS.FreeFormDrl(), "FF");
cmds.put("FF", new Command() {
public void execute() {
model.addLhsItem(new FreeFormLine(), Integer.parseInt(positionCbo.getValue(positionCbo.getSelectedIndex())));
hide();
}
});
}
use of org.drools.workbench.models.datamodel.rule.FreeFormLine in project drools by kiegroup.
the class RuleModelDRLPersistenceImpl method parseBaseDescr.
private IPattern parseBaseDescr(final RuleModel m, final BaseDescr descr, final boolean isJavaDialect, final Map<String, String> boundParams, final PackageDataModelOracle dmo) {
if (descr instanceof PatternDescr) {
return parsePatternDescr(m, (PatternDescr) descr, isJavaDialect, boundParams, dmo);
} else if (descr instanceof AndDescr) {
AndDescr andDescr = (AndDescr) descr;
return parseBaseDescr(m, andDescr.getDescrs().get(0), isJavaDialect, boundParams, dmo);
} else if (descr instanceof EvalDescr) {
FreeFormLine freeFormLine = new FreeFormLine();
freeFormLine.setText("eval( " + ((EvalDescr) descr).getContent() + " )");
return freeFormLine;
} else if (descr instanceof ConditionalElementDescr) {
return parseExistentialElementDescr(m, (ConditionalElementDescr) descr, isJavaDialect, boundParams, dmo);
}
return null;
}
use of org.drools.workbench.models.datamodel.rule.FreeFormLine in project drools by kiegroup.
the class RuleModelDRLPersistenceImpl method getSimpleRuleModel.
// Simple fall-back parser of DRL
public RuleModel getSimpleRuleModel(final String drl) {
final RuleModel rm = new RuleModel();
rm.setPackageName(PackageNameParser.parsePackageName(drl));
rm.setImports(ImportsParser.parseImports(drl));
final Pattern rulePattern = Pattern.compile(".*\\s?rule\\s+(.+?)\\s+.*", Pattern.DOTALL);
final Pattern lhsPattern = Pattern.compile(".*\\s+when\\s+(.+?)\\s+then.*", Pattern.DOTALL);
final Pattern rhsPattern = Pattern.compile(".*\\s+then\\s+(.+?)\\s+end.*", Pattern.DOTALL);
final Matcher ruleMatcher = rulePattern.matcher(drl);
if (ruleMatcher.matches()) {
String name = ruleMatcher.group(1);
if (name.startsWith("\"")) {
name = name.substring(1);
}
if (name.endsWith("\"")) {
name = name.substring(0, name.length() - 1);
}
rm.name = name;
}
final Matcher lhsMatcher = lhsPattern.matcher(drl);
if (lhsMatcher.matches()) {
final FreeFormLine lhs = new FreeFormLine();
lhs.setText(lhsMatcher.group(1) == null ? "" : lhsMatcher.group(1).trim());
rm.addLhsItem(lhs);
}
final Matcher rhsMatcher = rhsPattern.matcher(drl);
if (rhsMatcher.matches()) {
final FreeFormLine rhs = new FreeFormLine();
rhs.setText(rhsMatcher.group(1) == null ? "" : rhsMatcher.group(1).trim());
rm.addRhsItem(rhs);
}
return rm;
}
use of org.drools.workbench.models.datamodel.rule.FreeFormLine in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testActionFreeFormLineSecondValue.
@Test
public void testActionFreeFormLineSecondValue() {
TemplateModel m = new TemplateModel();
m.name = "r1";
FreeFormLine ffl = new FreeFormLine();
ffl.setText("System.println( \"@{f1}\" + \"@{f2}\" );");
m.addRhsItem(ffl);
String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "then\n" + "end";
m.addRow(new String[] { null, "bar" });
checkMarshall(expected, m);
}
use of org.drools.workbench.models.datamodel.rule.FreeFormLine in project drools by kiegroup.
the class RuleTemplateModelDRLPersistenceTest method testFromCollectFreeFormLineSecondValue.
@Test
public void testFromCollectFreeFormLineSecondValue() {
TemplateModel m = new TemplateModel();
m.name = "r1";
FreeFormLine ffl = new FreeFormLine();
ffl.setText("Person( field1 == \"@{f1}\", field2 == \"@{f2}\" )");
FactPattern fp = new FactPattern("java.util.List");
FromCollectCompositeFactPattern fac = new FromCollectCompositeFactPattern();
fac.setRightPattern(ffl);
fac.setFactPattern(fp);
m.addLhsItem(fac);
String expected = "rule \"r1_0\"\n" + "dialect \"mvel\"\n" + "when\n" + "then\n" + "end";
m.addRow(new String[] { null, "foo" });
checkMarshall(expected, m);
}
Aggregations