Search in sources :

Example 31 with IAction

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

the class GuidedRuleModelVisitor method getConsumedModelClasses.

public Set<String> getConsumedModelClasses() {
    final Set<String> factTypes = new HashSet<String>();
    // Extract Fact Types from model
    if (model.lhs != null) {
        for (int i = 0; i < model.lhs.length; i++) {
            IPattern pattern = model.lhs[i];
            factTypes.addAll(visit(pattern));
        }
    }
    if (model.rhs != null) {
        for (int i = 0; i < model.rhs.length; i++) {
            IAction action = model.rhs[i];
            factTypes.addAll(visit(action));
        }
    }
    // Convert Fact Types into Fully Qualified Class Names
    final Set<String> fullyQualifiedClassNames = new HashSet<String>();
    for (String factType : factTypes) {
        fullyQualifiedClassNames.add(convertToFullyQualifiedClassName(factType));
    }
    return fullyQualifiedClassNames;
}
Also used : IPattern(org.drools.workbench.models.datamodel.rule.IPattern) IAction(org.drools.workbench.models.datamodel.rule.IAction) ConnectiveConstraint(org.drools.workbench.models.datamodel.rule.ConnectiveConstraint) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) HashSet(java.util.HashSet)

Example 32 with IAction

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

the class RuleModeller method renderRhs.

/**
 * Do all the widgets for the RHS.
 */
private void renderRhs(final RuleModel model) {
    for (int i = 0; i < model.rhs.length; i++) {
        DirtyableVerticalPane widget = new DirtyableVerticalPane();
        widget.setWidth("100%");
        IAction action = model.rhs[i];
        // if lockRHS() set the widget RO, otherwise let them decide.
        Boolean readOnly = this.lockRHS() ? true : null;
        RuleModellerWidget w = getWidgetFactory().getWidget(this, eventBus, action, readOnly);
        w.addOnModifiedCommand(this.onWidgetModifiedCommand);
        widget.add(wrapRHSWidget(model, i, w));
        widget.add(spacerWidget());
        layout.setWidget(currentLayoutRow, 0, new DirtyableHorizontalPane());
        layout.setWidget(currentLayoutRow, 1, new DirtyableHorizontalPane());
        layout.setWidget(currentLayoutRow, 2, this.wrapLineNumber(i + 1, false));
        layout.getFlexCellFormatter().setHorizontalAlignment(currentLayoutRow, 2, HasHorizontalAlignment.ALIGN_CENTER);
        layout.getFlexCellFormatter().setVerticalAlignment(currentLayoutRow, 2, HasVerticalAlignment.ALIGN_MIDDLE);
        layout.setWidget(currentLayoutRow, 3, widget);
        layout.getFlexCellFormatter().setHorizontalAlignment(currentLayoutRow, 3, HasHorizontalAlignment.ALIGN_LEFT);
        layout.getFlexCellFormatter().setVerticalAlignment(currentLayoutRow, 3, HasVerticalAlignment.ALIGN_TOP);
        layout.getFlexCellFormatter().setWidth(currentLayoutRow, 3, "100%");
        layout.getRowFormatter().addStyleName(currentLayoutRow, (i % 2 == 0 ? GuidedRuleEditorResources.INSTANCE.css().evenRow() : GuidedRuleEditorResources.INSTANCE.css().oddRow()));
        if (!w.isFactTypeKnown()) {
            addInvalidPatternIcon();
            addFactTypeKnownValueChangeHandler(w, currentLayoutRow);
        }
        final int index = i;
        if (!(this.lockRHS() || w.isReadOnly())) {
            this.addActionsButtonsToLayout(GuidedRuleEditorResources.CONSTANTS.AddAnActionBelow(), new ClickHandler() {

                public void onClick(ClickEvent event) {
                    showActionSelector(index + 1);
                }
            }, new ClickHandler() {

                public void onClick(ClickEvent event) {
                    model.moveRhsItemDown(index);
                    refreshWidget();
                }
            }, new ClickHandler() {

                public void onClick(ClickEvent event) {
                    model.moveRhsItemUp(index);
                    refreshWidget();
                }
            });
        }
        this.rhsWidgets.add(w);
        currentLayoutRow++;
    }
}
Also used : ClickHandler(com.google.gwt.event.dom.client.ClickHandler) IAction(org.drools.workbench.models.datamodel.rule.IAction) DirtyableVerticalPane(org.uberfire.ext.widgets.common.client.common.DirtyableVerticalPane) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) DirtyableHorizontalPane(org.uberfire.ext.widgets.common.client.common.DirtyableHorizontalPane) RuleModellerWidget(org.drools.workbench.screens.guided.rule.client.widget.RuleModellerWidget)

Example 33 with IAction

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

the class RuleModellerActionSelectorPopup method addCustomActionPlugins.

private void addCustomActionPlugins() {
    if (actionPlugins != null) {
        for (RuleModellerActionPlugin actionPlugin : actionPlugins) {
            final IAction iAction = actionPlugin.createIAction(ruleModeller);
            actionPlugin.addPluginToActionList(ruleModeller, () -> {
                choices.addItem(actionPlugin.getActionAddDescription(), actionPlugin.getId());
                cmds.put(actionPlugin.getId(), () -> {
                    model.addRhsItem(iAction, Integer.parseInt(positionCbo.getValue(positionCbo.getSelectedIndex())));
                    hide();
                });
            });
        }
    }
}
Also used : IAction(org.drools.workbench.models.datamodel.rule.IAction) RuleModellerActionPlugin(org.drools.workbench.screens.guided.rule.client.editor.plugin.RuleModellerActionPlugin)

Example 34 with IAction

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

the class GuidedDecisionTreeModelUnmarshallingVisitor method visit.

private GuidedDecisionTree visit(final String drl, final String baseFileName, final List<String> globals, final PackageDataModelOracle dmo) {
    PortablePreconditions.checkNotNull("drl", drl);
    PortablePreconditions.checkNotNull("baseFileName", baseFileName);
    PortablePreconditions.checkNotNull("globals", globals);
    PortablePreconditions.checkNotNull("dmo", dmo);
    final GuidedDecisionTree model = new GuidedDecisionTree();
    model.setTreeName(baseFileName);
    // De-serialize Package name
    final String packageName = PackageNameParser.parsePackageName(drl);
    model.setPackageName(packageName);
    // De-serialize imports
    final Imports imports = ImportsParser.parseImports(drl);
    for (Import item : imports.getImports()) {
        model.getImports().addImport(item);
    }
    // Split DRL into separate rules
    final List<String> rules = new ArrayList<String>();
    final Pattern pattern = Pattern.compile("\\s?rule\\s(.+?)\\send\\s?", Pattern.DOTALL);
    final Matcher matcher = pattern.matcher(drl);
    while (matcher.find()) {
        rules.add(matcher.group());
    }
    // Build a linear Path of Nodes for each rule
    final List<GuidedDecisionTreeParserExtendedError> rulesParserContent = new ArrayList<GuidedDecisionTreeParserExtendedError>();
    for (String rule : rules) {
        final GuidedDecisionTreeParserExtendedError ruleParserContent = new GuidedDecisionTreeParserExtendedError();
        rulesParserContent.add(ruleParserContent);
        try {
            final RuleModel rm = RuleModelDRLPersistenceImpl.getInstance().unmarshal(rule, globals, dmo);
            ruleParserContent.setOriginalRuleName(rm.name);
            ruleParserContent.setOriginalDrl(rule);
            for (IPattern p : rm.lhs) {
                ruleParserContent.getNodes().addAll(visit(p, model, dmo, ruleParserContent.getMessages()));
            }
            for (IAction a : rm.rhs) {
                ruleParserContent.getNodes().addAll(visit(a, getTypesOnPath(ruleParserContent.getNodes()), model, dmo, ruleParserContent.getMessages()));
            }
        } catch (Exception e) {
            ruleParserContent.getMessages().add(new DefaultParserMessage(e.getMessage()));
        }
    }
    // Combine Paths into a single tree.
    for (GuidedDecisionTreeParserExtendedError ruleParserContent : rulesParserContent) {
        Node activeModelNode = null;
        boolean error = !ruleParserContent.getMessages().isEmpty();
        for (int index = 0; !error && index < ruleParserContent.getNodes().size(); index++) {
            final Node node = ruleParserContent.getNodes().get(index);
            switch(index) {
                case 0:
                    if (!(node instanceof TypeNode)) {
                        ruleParserContent.getMessages().add(new InvalidRootParserMessage());
                        error = true;
                        break;
                    }
                    final TypeNode root = (TypeNode) node;
                    if (model.getRoot() == null) {
                        model.setRoot(root);
                    } else if (!root.equals(model.getRoot())) {
                        ruleParserContent.getMessages().add(new AmbiguousRootParserMessage(root.getClassName()));
                        error = true;
                        break;
                    }
                    activeModelNode = model.getRoot();
                    break;
                default:
                    if (!activeModelNode.getChildren().contains(node)) {
                        // If the active node in the Model doesn't contain the child add it as a new child
                        activeModelNode.addChild(node);
                        activeModelNode = node;
                    } else {
                        // Otherwise swap out the Node in the Path for the existing one in the Model
                        activeModelNode = activeModelNode.getChildren().get(activeModelNode.getChildren().indexOf(node));
                    }
            }
        }
        if (!ruleParserContent.getMessages().isEmpty()) {
            model.getParserErrors().add(new GuidedDecisionTreeParserError(ruleParserContent.getOriginalRuleName(), ruleParserContent.getOriginalDrl(), ruleParserContent.getMessages()));
        }
    }
    return model;
}
Also used : IPattern(org.drools.workbench.models.datamodel.rule.IPattern) Pattern(java.util.regex.Pattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) IPattern(org.drools.workbench.models.datamodel.rule.IPattern) Import(org.kie.soup.project.datamodel.imports.Import) IAction(org.drools.workbench.models.datamodel.rule.IAction) Matcher(java.util.regex.Matcher) InvalidRootParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.InvalidRootParserMessage) GuidedDecisionTreeParserError(org.drools.workbench.models.guided.dtree.shared.model.parser.GuidedDecisionTreeParserError) ActionRetractNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionRetractNode) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) Node(org.drools.workbench.models.guided.dtree.shared.model.nodes.Node) ActionUpdateNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionUpdateNode) ActionInsertNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ActionInsertNode) ConstraintNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.ConstraintNode) ArrayList(java.util.ArrayList) GuidedDecisionTree(org.drools.workbench.models.guided.dtree.shared.model.GuidedDecisionTree) DefaultParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.DefaultParserMessage) Imports(org.kie.soup.project.datamodel.imports.Imports) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) CompositeFieldConstraint(org.drools.workbench.models.datamodel.rule.CompositeFieldConstraint) FieldConstraint(org.drools.workbench.models.datamodel.rule.FieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) TypeNode(org.drools.workbench.models.guided.dtree.shared.model.nodes.TypeNode) AmbiguousRootParserMessage(org.drools.workbench.models.guided.dtree.shared.model.parser.messages.AmbiguousRootParserMessage)

Example 35 with IAction

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

the class BRLActionColumnTest method testDiffAll.

@Test
public void testDiffAll() {
    List<IAction> definition1 = Arrays.asList(new ActionRetractFact("var1"));
    column1.setDefinition(definition1);
    List<BRLActionVariableColumn> childColumns1 = Arrays.asList(new BRLActionVariableColumn("var1", "FieldType1"));
    column1.setChildColumns(childColumns1);
    column1.setHeader("header1");
    column1.setHideColumn(false);
    List<IAction> definition2 = Arrays.asList(new ActionRetractFact("var2"));
    column2.setDefinition(definition2);
    List<BRLActionVariableColumn> childColumns2 = Arrays.asList(new BRLActionVariableColumn("var2", "FieldType2"));
    column2.setChildColumns(childColumns2);
    column2.setHeader("header2");
    column2.setHideColumn(true);
    List<BaseColumnFieldDiff> diff = column1.diff(column2);
    assertNotNull(diff);
    assertEquals(5, diff.size());
    assertEquals(FIELD_HIDE_COLUMN, diff.get(0).getFieldName());
    assertEquals(false, diff.get(0).getOldValue());
    assertEquals(true, diff.get(0).getValue());
    assertEquals(FIELD_HEADER, diff.get(1).getFieldName());
    assertEquals("header1", diff.get(1).getOldValue());
    assertEquals("header2", diff.get(1).getValue());
    assertEquals(FIELD_DEFINITION, diff.get(2).getFieldName());
    assertEquals(definition1, diff.get(2).getOldValue());
    assertEquals(definition2, diff.get(2).getValue());
    assertEquals(FIELD_VAR_NAME, diff.get(3).getFieldName());
    assertEquals("var1", diff.get(3).getOldValue());
    assertEquals("var2", diff.get(3).getValue());
    assertEquals(FIELD_FIELD_TYPE, diff.get(4).getFieldName());
    assertEquals("FieldType1", diff.get(4).getOldValue());
    assertEquals("FieldType2", diff.get(4).getValue());
}
Also used : ActionRetractFact(org.drools.workbench.models.datamodel.rule.ActionRetractFact) IAction(org.drools.workbench.models.datamodel.rule.IAction) Test(org.junit.Test)

Aggregations

IAction (org.drools.workbench.models.datamodel.rule.IAction)63 Test (org.junit.Test)44 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)35 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)32 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)31 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)30 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)29 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)25 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)21 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)20 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)20 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)20 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)20 ArrayList (java.util.ArrayList)19 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)19 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)17 FreeFormLine (org.drools.workbench.models.datamodel.rule.FreeFormLine)17 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)17 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)15 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)15