Search in sources :

Example 51 with FreeFormLine

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

the class GuidedDTDRLPersistence method doAction.

private void doAction(List<BaseColumn> allColumns, BRLActionColumn column, List<LabelledAction> actions, TemplateDataProvider rowDataProvider, List<DTCellValue52> row, RuleModel rm) {
    // Check whether the parameter-less BRL fragment needs inclusion
    if (!hasVariables(column)) {
        final BRLActionVariableColumn variableColumn = column.getChildColumns().get(0);
        final int index = allColumns.indexOf(variableColumn);
        final DTCellValue52 dcv = row.get(index);
        if (dcv.getBooleanValue()) {
            for (IAction action : column.getDefinition()) {
                addAction(action, actions);
            }
        }
    } else {
        for (IAction action : column.getDefinition()) {
            boolean addAction = false;
            // Get interpolation variables used by the Action
            Map<InterpolationVariable, Integer> ivs = new HashMap<InterpolationVariable, Integer>();
            RuleModelVisitor rmv = new RuleModelVisitor(action, ivs);
            rmv.visit(action);
            if (ivs.size() == 0) {
                addAction = true;
            } else if (ivs.size() > 0) {
                // Ensure every key has a value and substitute keys for values
                int templateKeyCount = 0;
                for (InterpolationVariable variable : ivs.keySet()) {
                    String value = rowDataProvider.getTemplateKeyValue(variable.getVarName());
                    if (!"".equals(value)) {
                        templateKeyCount++;
                    }
                }
                // Ensure at least one key has a value (FreeFormLines need all values to be provided)
                if (action instanceof FreeFormLine) {
                    addAction = templateKeyCount == ivs.size();
                } else if (templateKeyCount > 0) {
                    addAction = true;
                }
            }
            if (addAction) {
                addAction(action, actions);
            }
        }
    }
}
Also used : FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) IAction(org.drools.workbench.models.datamodel.rule.IAction) RuleModelVisitor(org.drools.workbench.models.datamodel.rule.visitors.RuleModelVisitor) InterpolationVariable(org.drools.workbench.models.datamodel.rule.InterpolationVariable) HashMap(java.util.HashMap) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)

Example 52 with FreeFormLine

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

the class RuleModelDRLPersistenceUnmarshallingTest method testMultipleFromKeywords.

@Test
public // https://bugzilla.redhat.com/show_bug.cgi?id=1191737
void testMultipleFromKeywords() throws Exception {
    String drl = "package org.test;\n" + "rule \"ToyWithoutName \"\n" + "dialect \"java\"\n" + "when\n" + "  $father: Father()\n" + "  ($kid: Kid() from $father.kids)\n" + "  ($toy: Toy(name == null) from $kid.toys)\n" + "then\n" + "  System.out.println(\"blabla\");\n" + "end";
    addModelField("org.test.Father", "this", "org.test.Father", DataType.TYPE_THIS);
    addModelField("org.test.Father", "kids", "org.test.Kid", DataType.TYPE_COLLECTION);
    addModelField("org.test.Kid", "this", "org.test.Kid", DataType.TYPE_THIS);
    addModelField("org.test.Kid", "toys", "org.test.Toy", DataType.TYPE_COLLECTION);
    addModelField("org.test.Toy", "this", "org.test.Toy", DataType.TYPE_THIS);
    addModelField("org.test.Toy", "name", "java.lang.String", DataType.TYPE_STRING);
    when(dmo.getPackageName()).thenReturn("org.test");
    final RuleModel m = RuleModelDRLPersistenceImpl.getInstance().unmarshal(drl, Collections.emptyList(), dmo);
    assertNotNull(m);
    assertEquals(3, m.lhs.length);
    final IPattern p0 = m.lhs[0];
    assertTrue(p0 instanceof FactPattern);
    final FactPattern fp0 = (FactPattern) p0;
    assertEquals("$father", fp0.getBoundName());
    assertEquals("Father", fp0.getFactType());
    final IPattern p1 = m.lhs[1];
    assertTrue(p1 instanceof FromCompositeFactPattern);
    final FromCompositeFactPattern fp1 = (FromCompositeFactPattern) p1;
    assertEquals("$kid", fp1.getFactPattern().getBoundName());
    assertEquals("Kid", fp1.getFactType());
    final IPattern p2 = m.lhs[2];
    assertTrue(p2 instanceof FromCompositeFactPattern);
    final FromCompositeFactPattern fp2 = (FromCompositeFactPattern) p2;
    assertEquals("$toy", fp2.getFactPattern().getBoundName());
    assertEquals("Toy", fp2.getFactType());
    assertEquals(1, m.rhs.length);
    final IAction a = m.rhs[0];
    assertTrue(a instanceof FreeFormLine);
    final FreeFormLine affl = (FreeFormLine) a;
    assertEquals("System.out.println(\"blabla\");", affl.getText());
    // Check round-trip
    assertEqualsIgnoreWhitespace(drl, RuleModelDRLPersistenceImpl.getInstance().marshal(m));
}
Also used : IPattern(org.drools.workbench.models.datamodel.rule.IPattern) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) IAction(org.drools.workbench.models.datamodel.rule.IAction) 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) Test(org.junit.Test)

Example 53 with FreeFormLine

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

the class RuleModelCloneVisitor method visitFreeFormLine.

private FreeFormLine visitFreeFormLine(FreeFormLine ffl) {
    FreeFormLine clone = new FreeFormLine();
    clone.setText(ffl.getText());
    return clone;
}
Also used : FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine)

Example 54 with FreeFormLine

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

the class RuleModelCloneVisitorTest method buildFreeFormLine.

private static FreeFormLine buildFreeFormLine() {
    FreeFormLine ffl = new FreeFormLine();
    ffl.setText("text");
    return ffl;
}
Also used : FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine)

Example 55 with FreeFormLine

use of org.drools.workbench.models.datamodel.rule.FreeFormLine 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)

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