Search in sources :

Example 26 with DSLSentence

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

the class RuleModelDRLPersistenceUnmarshallingTest method testDSL.

@Test
public void testDSL() {
    String drl = "package org.mortgages;\n" + "rule \"testdsl\"\n" + "  dialect \"mvel\"\n" + "  when\n" + "    There is a test rated applicant older than 111 years\n" + "  then\n" + "end";
    String dslDefinition = "There is a {rating} rated applicant older than {age} years";
    String dslFile = "[when]" + dslDefinition + "= Applicant( creditRating == \"{rating}\", age > {age} )";
    when(dmo.getPackageName()).thenReturn("org.mortgages");
    final RuleModel model = RuleModelDRLPersistenceImpl.getInstance().unmarshalUsingDSL(drl, Collections.emptyList(), dmo, dslFile);
    assertEquals(1, model.lhs.length);
    DSLSentence dslSentence = (DSLSentence) model.lhs[0];
    assertEquals("Applicant( creditRating == \"{rating}\", age > {age} )", dslSentence.getDrl());
    assertEquals("test", dslSentence.getValues().get(0).getValue());
    assertEquals("111", dslSentence.getValues().get(1).getValue());
}
Also used : RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) DSLSentence(org.drools.workbench.models.datamodel.rule.DSLSentence) Test(org.junit.Test)

Example 27 with DSLSentence

use of org.drools.workbench.models.datamodel.rule.DSLSentence in project drools-wb by kiegroup.

the class RuleModellerConditionSelectorPopup method addDSLSentences.

// The list of DSL sentences
private void addDSLSentences() {
    // DSL might be prohibited (e.g. editing a DRL file. Only DSLR files can contain DSL)
    if (!ruleModeller.isDSLEnabled()) {
        return;
    }
    for (final DSLSentence sen : oracle.getDSLConditions()) {
        final String sentence = sen.toString();
        final String key = "DSL" + sentence;
        choices.addItem(sentence, key);
        cmds.put(key, new Command() {

            public void execute() {
                addNewDSLLhs(sen, Integer.parseInt(positionCbo.getValue(positionCbo.getSelectedIndex())));
                hide();
            }
        });
    }
}
Also used : Command(com.google.gwt.user.client.Command) DSLSentence(org.drools.workbench.models.datamodel.rule.DSLSentence)

Example 28 with DSLSentence

use of org.drools.workbench.models.datamodel.rule.DSLSentence in project drools-wb by kiegroup.

the class RuleModellerWidgetFactory method getWidget.

public RuleModellerWidget getWidget(RuleModeller ruleModeller, EventBus eventBus, IAction action, Boolean readOnly) {
    if (action instanceof ActionCallMethod) {
        return new ActionCallMethodWidget(ruleModeller, eventBus, (ActionCallMethod) action, readOnly);
    }
    if (action instanceof ActionSetField) {
        return new ActionSetFieldWidget(ruleModeller, eventBus, (ActionSetField) action, readOnly);
    }
    if (action instanceof ActionInsertFact) {
        return new ActionInsertFactWidget(ruleModeller, eventBus, (ActionInsertFact) action, readOnly);
    }
    if (action instanceof ActionRetractFact) {
        return new ActionRetractFactWidget(ruleModeller, eventBus, (ActionRetractFact) action, readOnly);
    }
    if (action instanceof DSLSentence) {
        RuleModellerWidget w = new DSLSentenceWidget(ruleModeller, eventBus, (DSLSentence) action, readOnly);
        return w;
    }
    if (action instanceof FreeFormLine) {
        return new FreeFormLineWidget(ruleModeller, eventBus, (FreeFormLine) action, readOnly);
    }
    if (action instanceof ActionGlobalCollectionAdd) {
        return new GlobalCollectionAddWidget(ruleModeller, eventBus, (ActionGlobalCollectionAdd) action, readOnly);
    }
    // All hardcoded action widgets have been checked, perform a plugin lookup
    List<RuleModellerActionPlugin> matchingActionPlugins = actionPlugins.stream().filter(p -> p.accept(action)).collect(Collectors.toList());
    if (matchingActionPlugins.size() > 1) {
        throw new IllegalStateException("Ambigious " + RuleModellerActionPlugin.class.getName() + " implementations for action " + action);
    }
    if (matchingActionPlugins.size() == 1) {
        RuleModellerActionPlugin actionPlugin = matchingActionPlugins.get(0);
        RuleModellerWidget ruleModellerWidget = actionPlugin.createWidget(ruleModeller, eventBus, action, readOnly);
        return ruleModellerWidget;
    }
    // NON-NLS
    throw new RuntimeException("I don't know what type of action is: " + action);
}
Also used : ExpressionBuilder(org.drools.workbench.screens.guided.rule.client.widget.ExpressionBuilder) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) CompositeFactPatternWidget(org.drools.workbench.screens.guided.rule.client.widget.CompositeFactPatternWidget) RuleModellerActionPlugin(org.drools.workbench.screens.guided.rule.client.editor.plugin.RuleModellerActionPlugin) FromCompositeFactPatternWidget(org.drools.workbench.screens.guided.rule.client.widget.FromCompositeFactPatternWidget) ActionCallMethodWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionCallMethodWidget) ActionInsertFactWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionInsertFactWidget) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromEntryPointFactPatternWidget(org.drools.workbench.screens.guided.rule.client.widget.FromEntryPointFactPatternWidget) PortablePreconditions(org.kie.soup.commons.validation.PortablePreconditions) ExpressionFormLine(org.drools.workbench.models.datamodel.rule.ExpressionFormLine) IPattern(org.drools.workbench.models.datamodel.rule.IPattern) ActionSetFieldWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionSetFieldWidget) GlobalCollectionAddWidget(org.drools.workbench.screens.guided.rule.client.widget.GlobalCollectionAddWidget) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) DSLSentence(org.drools.workbench.models.datamodel.rule.DSLSentence) IAction(org.drools.workbench.models.datamodel.rule.IAction) EventBus(com.google.gwt.event.shared.EventBus) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) FactPatternWidget(org.drools.workbench.screens.guided.rule.client.widget.FactPatternWidget) Collection(java.util.Collection) RuleModellerWidget(org.drools.workbench.screens.guided.rule.client.widget.RuleModellerWidget) FreeFormLineWidget(org.drools.workbench.screens.guided.rule.client.widget.FreeFormLineWidget) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) Collectors(java.util.stream.Collectors) FromCollectCompositeFactPatternWidget(org.drools.workbench.screens.guided.rule.client.widget.FromCollectCompositeFactPatternWidget) ActionRetractFactWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionRetractFactWidget) List(java.util.List) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) ActionRetractFact(org.drools.workbench.models.datamodel.rule.ActionRetractFact) FromAccumulateCompositeFactPatternWidget(org.drools.workbench.screens.guided.rule.client.widget.FromAccumulateCompositeFactPatternWidget) ActionGlobalCollectionAdd(org.drools.workbench.models.datamodel.rule.ActionGlobalCollectionAdd) ActionCallMethod(org.drools.workbench.models.datamodel.rule.ActionCallMethod) DSLSentenceWidget(org.drools.workbench.screens.guided.rule.client.widget.DSLSentenceWidget) Collections(java.util.Collections) GlobalCollectionAddWidget(org.drools.workbench.screens.guided.rule.client.widget.GlobalCollectionAddWidget) RuleModellerActionPlugin(org.drools.workbench.screens.guided.rule.client.editor.plugin.RuleModellerActionPlugin) ActionCallMethod(org.drools.workbench.models.datamodel.rule.ActionCallMethod) ActionInsertFactWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionInsertFactWidget) ActionCallMethodWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionCallMethodWidget) RuleModellerWidget(org.drools.workbench.screens.guided.rule.client.widget.RuleModellerWidget) DSLSentenceWidget(org.drools.workbench.screens.guided.rule.client.widget.DSLSentenceWidget) FreeFormLineWidget(org.drools.workbench.screens.guided.rule.client.widget.FreeFormLineWidget) ActionSetFieldWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionSetFieldWidget) ActionRetractFact(org.drools.workbench.models.datamodel.rule.ActionRetractFact) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) ActionInsertFact(org.drools.workbench.models.datamodel.rule.ActionInsertFact) ActionGlobalCollectionAdd(org.drools.workbench.models.datamodel.rule.ActionGlobalCollectionAdd) DSLSentence(org.drools.workbench.models.datamodel.rule.DSLSentence) ActionRetractFactWidget(org.drools.workbench.screens.guided.rule.client.widget.ActionRetractFactWidget)

Example 29 with DSLSentence

use of org.drools.workbench.models.datamodel.rule.DSLSentence in project drools-wb by kiegroup.

the class RuleModellerActionSelectorPopup method addDSLSentences.

// Add DSL sentences
void addDSLSentences() {
    // DSL might be prohibited (e.g. editing a DRL file. Only DSLR files can contain DSL)
    if (!ruleModeller.isDSLEnabled()) {
        return;
    }
    for (final DSLSentence sen : oracle.getDSLActions()) {
        final String sentence = sen.toString();
        final String key = "DSL" + sentence;
        choices.addItem(sentence, key);
        cmds.put(key, new Command() {

            public void execute() {
                addNewDSLRhs(sen, Integer.parseInt(positionCbo.getValue(positionCbo.getSelectedIndex())));
                hide();
            }
        });
    }
}
Also used : Command(com.google.gwt.user.client.Command) DSLSentence(org.drools.workbench.models.datamodel.rule.DSLSentence)

Aggregations

DSLSentence (org.drools.workbench.models.datamodel.rule.DSLSentence)29 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)19 Test (org.junit.Test)19 DSLVariableValue (org.drools.workbench.models.datamodel.rule.DSLVariableValue)7 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)6 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)6 DSLComplexVariableValue (org.drools.workbench.models.datamodel.rule.DSLComplexVariableValue)5 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)5 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)4 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)4 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)4 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)3 ActionRetractFact (org.drools.workbench.models.datamodel.rule.ActionRetractFact)3 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)3 FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)3 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)3 Command (com.google.gwt.user.client.Command)2 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 ArrayList (java.util.ArrayList)2