Search in sources :

Example 26 with FreeFormLine

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();
        }
    });
}
Also used : FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) Command(com.google.gwt.user.client.Command)

Example 27 with FreeFormLine

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;
}
Also used : FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) PatternDescr(org.drools.compiler.lang.descr.PatternDescr) AndDescr(org.drools.compiler.lang.descr.AndDescr) EvalDescr(org.drools.compiler.lang.descr.EvalDescr) ConditionalElementDescr(org.drools.compiler.lang.descr.ConditionalElementDescr)

Example 28 with FreeFormLine

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;
}
Also used : FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) Pattern(java.util.regex.Pattern) IFactPattern(org.drools.workbench.models.datamodel.rule.IFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) IPattern(org.drools.workbench.models.datamodel.rule.IPattern) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) Matcher(java.util.regex.Matcher) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel)

Example 29 with FreeFormLine

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);
}
Also used : FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) Test(org.junit.Test)

Example 30 with FreeFormLine

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);
}
Also used : FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) TemplateModel(org.drools.workbench.models.guided.template.shared.TemplateModel) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) Test(org.junit.Test)

Aggregations

FreeFormLine (org.drools.workbench.models.datamodel.rule.FreeFormLine)64 Test (org.junit.Test)49 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)29 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)24 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)22 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)22 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)18 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)18 IAction (org.drools.workbench.models.datamodel.rule.IAction)17 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)14 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)14 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)12 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)11 TemplateModel (org.drools.workbench.models.guided.template.shared.TemplateModel)11 ArrayList (java.util.ArrayList)10 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)10 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)10 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)10 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)9 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)9