Search in sources :

Example 6 with FromEntryPointFactPattern

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

the class GuidedDTDRLPersistence method doCondition.

private void doCondition(List<BaseColumn> allColumns, Pattern52 pattern, List<IPattern> patterns, List<DTCellValue52> row, List<List<DTCellValue52>> data, RuleModel rm) {
    List<ConditionCol52> cols = pattern.getChildColumns();
    for (ConditionCol52 c : cols) {
        int index = allColumns.indexOf(c);
        DTCellValue52 dcv = row.get(index);
        String cell = "";
        if (c instanceof LimitedEntryCol) {
            if (Boolean.TRUE.equals(dcv.getBooleanValue())) {
                LimitedEntryCol lec = (LimitedEntryCol) c;
                DTCellValue52 value = lec.getValue();
                if (value != null) {
                    cell = GuidedDTDRLUtilities.convertDTCellValueToString(value);
                }
            }
        } else {
            cell = GuidedDTDRLUtilities.convertDTCellValueToString(dcv);
        }
        boolean isOtherwise = dcv.isOtherwise();
        boolean isValid = isOtherwise;
        // Otherwise values are automatically valid as they're constructed from the other rules
        if (!isOtherwise) {
            isValid = validCell(cell, dcv.getDataType());
        }
        // If operator is "== null" or "!= null" add constraint if table value is true
        if (c.getOperator() != null && (c.getOperator().equals("== null") || c.getOperator().equals("!= null"))) {
            isValid = Boolean.TRUE.equals(dcv.getBooleanValue());
        }
        if (isValid) {
            // get or create the pattern it belongs too
            IPattern ifp = findByFactPattern(patterns, pattern);
            // If the pattern does not exist create one suitable
            if (ifp == null) {
                FactPattern fp = new FactPattern(pattern.getFactType());
                fp.setBoundName(pattern.getBoundName());
                fp.setNegated(pattern.isNegated());
                fp.setWindow(pattern.getWindow());
                if (pattern.getEntryPointName() != null && pattern.getEntryPointName().length() > 0) {
                    FromEntryPointFactPattern fep = new FromEntryPointFactPattern();
                    fep.setEntryPointName(pattern.getEntryPointName());
                    fep.setFactPattern(fp);
                    patterns.add(fep);
                    ifp = fep;
                } else {
                    patterns.add(fp);
                    ifp = fp;
                }
            }
            // Extract the FactPattern from the IFactPattern
            FactPattern fp;
            if (ifp instanceof FactPattern) {
                fp = (FactPattern) ifp;
            } else if (ifp instanceof FromEntryPointFactPattern) {
                FromEntryPointFactPattern fep = (FromEntryPointFactPattern) ifp;
                fp = fep.getFactPattern();
            } else {
                throw new IllegalArgumentException("Inexpected IFactPattern implementation found.");
            }
            // Add the constraint from this cell
            switch(c.getConstraintValueType()) {
                case BaseSingleFieldConstraint.TYPE_LITERAL:
                case BaseSingleFieldConstraint.TYPE_RET_VALUE:
                    if (!isOtherwise) {
                        FieldConstraint fc = makeSingleFieldConstraint(c, cell);
                        fp.addConstraint(fc);
                    } else {
                        FieldConstraint fc = makeSingleFieldConstraint(c, allColumns, data);
                        fp.addConstraint(fc);
                    }
                    break;
                case BaseSingleFieldConstraint.TYPE_PREDICATE:
                    SingleFieldConstraint pred = new SingleFieldConstraint();
                    pred.setConstraintValueType(c.getConstraintValueType());
                    if (c.getFactField() != null && c.getFactField().indexOf("$param") > -1) {
                        // handle interpolation
                        pred.setValue(c.getFactField().replace("$param", cell));
                    } else {
                        pred.setValue(cell);
                    }
                    fp.addConstraint(pred);
                    break;
                default:
                    throw new IllegalArgumentException("Unknown constraintValueType: " + c.getConstraintValueType());
            }
        }
    }
}
Also used : IPattern(org.drools.workbench.models.datamodel.rule.IPattern) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) 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) LimitedEntryCol(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryCol) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) 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 7 with FromEntryPointFactPattern

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

the class GuidedDTDRLPersistence method doFindByNegatedFactPattern.

private IPattern doFindByNegatedFactPattern(final List<IPattern> patterns, final Pattern52 find) {
    final String factType = find.getFactType();
    for (IPattern ifp : patterns) {
        if (ifp instanceof FactPattern) {
            final FactPattern fp = (FactPattern) ifp;
            final Optional<IPattern> match = checkNegatedFactPattern(fp, factType);
            if (match.isPresent()) {
                return match.get();
            }
        } else if (ifp instanceof FromEntryPointFactPattern) {
            final FromEntryPointFactPattern fefp = (FromEntryPointFactPattern) ifp;
            final FactPattern fp = fefp.getFactPattern();
            final Optional<IPattern> match = checkNegatedFactPattern(fp, factType);
            if (match.isPresent()) {
                return match.get();
            }
        }
    }
    return null;
}
Also used : IPattern(org.drools.workbench.models.datamodel.rule.IPattern) Optional(java.util.Optional) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern)

Example 8 with FromEntryPointFactPattern

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

the class RuleModellerConditionSelectorPopup method addNewFCE.

private void addNewFCE(String type, int position) {
    FromCompositeFactPattern p = null;
    if (type.equals("from")) {
        p = new FromCompositeFactPattern();
    } else if (type.equals("from accumulate")) {
        p = new FromAccumulateCompositeFactPattern();
    } else if (type.equals("from collect")) {
        p = new FromCollectCompositeFactPattern();
    } else if (type.equals("from entry-point")) {
        p = new FromEntryPointFactPattern();
    }
    this.model.addLhsItem(p, position);
}
Also used : FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)

Example 9 with FromEntryPointFactPattern

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

the class FromCollectCompositeFactPatternWidget method showRightPatternSelector.

/**
 * Pops up the fact selector.
 */
protected void showRightPatternSelector(final Widget w) {
    final ListBox box = new ListBox();
    AsyncPackageDataModelOracle oracle = this.getModeller().getDataModelOracle();
    String[] facts = oracle.getFactTypes();
    box.addItem(GuidedRuleEditorResources.CONSTANTS.Choose());
    for (int i = 0; i < facts.length; i++) {
        box.addItem(facts[i]);
    }
    box.setSelectedIndex(0);
    final FormStylePopup popup = new FormStylePopup(GuidedRuleEditorResources.CONSTANTS.NewFactPattern());
    popup.addAttribute(GuidedRuleEditorResources.CONSTANTS.chooseFactType(), box);
    box.addChangeHandler(new ChangeHandler() {

        public void onChange(ChangeEvent event) {
            getFromCollectPattern().setRightPattern(new FactPattern(box.getItemText(box.getSelectedIndex())));
            setModified(true);
            getModeller().refreshWidget();
            popup.hide();
        }
    });
    final Button freeFormDRLBtn = new Button(GuidedRuleEditorResources.CONSTANTS.FreeFormDrl());
    final Button fromBtn = new Button(HumanReadableConstants.INSTANCE.From());
    final Button fromAccumulateBtn = new Button(HumanReadableConstants.INSTANCE.FromAccumulate());
    final Button fromCollectBtn = new Button(HumanReadableConstants.INSTANCE.FromCollect());
    final Button fromEntryPointBtn = new Button(HumanReadableConstants.INSTANCE.FromEntryPoint());
    ClickHandler btnsClickHandler = new ClickHandler() {

        public void onClick(ClickEvent event) {
            Widget sender = (Widget) event.getSource();
            if (sender == fromBtn) {
                getFromCollectPattern().setRightPattern(new FromCompositeFactPattern());
            } else if (sender == fromAccumulateBtn) {
                getFromCollectPattern().setRightPattern(new FromAccumulateCompositeFactPattern());
            } else if (sender == fromCollectBtn) {
                getFromCollectPattern().setRightPattern(new FromCollectCompositeFactPattern());
            } else if (sender == freeFormDRLBtn) {
                getFromCollectPattern().setRightPattern(new FreeFormLine());
            } else if (sender == fromEntryPointBtn) {
                getFromCollectPattern().setRightPattern(new FromEntryPointFactPattern());
            } else {
                throw new IllegalArgumentException("Unknown sender: " + sender);
            }
            setModified(true);
            getModeller().refreshWidget();
            popup.hide();
        }
    };
    freeFormDRLBtn.addClickHandler(btnsClickHandler);
    fromBtn.addClickHandler(btnsClickHandler);
    fromAccumulateBtn.addClickHandler(btnsClickHandler);
    fromCollectBtn.addClickHandler(btnsClickHandler);
    fromEntryPointBtn.addClickHandler(btnsClickHandler);
    popup.addAttribute("", freeFormDRLBtn);
    popup.addAttribute("", fromBtn);
    popup.addAttribute("", fromAccumulateBtn);
    popup.addAttribute("", fromCollectBtn);
    popup.addAttribute("", fromEntryPointBtn);
    popup.show();
}
Also used : AsyncPackageDataModelOracle(org.kie.workbench.common.widgets.client.datamodel.AsyncPackageDataModelOracle) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) Widget(com.google.gwt.user.client.ui.Widget) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) Button(org.gwtbootstrap3.client.ui.Button) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FormStylePopup(org.uberfire.ext.widgets.common.client.common.popups.FormStylePopup) ListBox(org.gwtbootstrap3.client.ui.ListBox)

Example 10 with FromEntryPointFactPattern

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

the class FromCollectCompositeFactPatternWidget method getCompositeLabel.

@Override
protected Widget getCompositeLabel() {
    ClickHandler leftPatternclick = new ClickHandler() {

        public void onClick(ClickEvent event) {
            showFactTypeSelector();
        }
    };
    ClickHandler rightPatternclick = new ClickHandler() {

        public void onClick(ClickEvent event) {
            Widget w = (Widget) event.getSource();
            showRightPatternSelector(w);
        }
    };
    String lbl = "<div class='form-field'>" + HumanReadable.getCEDisplayName("from collect") + "</div>";
    FlexTable panel = new FlexTable();
    int r = 0;
    if (pattern.getFactPattern() == null) {
        panel.setWidget(r++, 0, new ClickableLabel("<br> <font color='red'>" + GuidedRuleEditorResources.CONSTANTS.clickToAddPatterns() + "</font>", leftPatternclick, !this.readOnly));
    }
    panel.setWidget(r++, 0, new HTML(lbl));
    if (this.getFromCollectPattern().getRightPattern() == null) {
        panel.setWidget(r++, 0, new ClickableLabel("<br> <font color='red'>" + GuidedRuleEditorResources.CONSTANTS.clickToAddPatterns() + "</font>", rightPatternclick, !this.readOnly));
    } else {
        IPattern rPattern = this.getFromCollectPattern().getRightPattern();
        RuleModellerWidget patternWidget = null;
        if (rPattern instanceof FactPattern) {
            patternWidget = new FactPatternWidget(this.getModeller(), this.getEventBus(), rPattern, true, true, this.readOnly);
        } else if (rPattern instanceof FromAccumulateCompositeFactPattern) {
            patternWidget = new FromAccumulateCompositeFactPatternWidget(this.getModeller(), this.getEventBus(), (FromAccumulateCompositeFactPattern) rPattern, this.readOnly);
        } else if (rPattern instanceof FromCollectCompositeFactPattern) {
            patternWidget = new FromCollectCompositeFactPatternWidget(this.getModeller(), this.getEventBus(), (FromCollectCompositeFactPattern) rPattern, this.readOnly);
        } else if (rPattern instanceof FromEntryPointFactPattern) {
            patternWidget = new FromEntryPointFactPatternWidget(this.getModeller(), this.getEventBus(), (FromEntryPointFactPattern) rPattern, this.readOnly);
        } else if (rPattern instanceof FromCompositeFactPattern) {
            patternWidget = new FromCompositeFactPatternWidget(this.getModeller(), this.getEventBus(), (FromCompositeFactPattern) rPattern, this.readOnly);
        } else if (rPattern instanceof FreeFormLine) {
            patternWidget = new FreeFormLineWidget(this.getModeller(), this.getEventBus(), (FreeFormLine) rPattern, this.readOnly);
        } else {
            throw new IllegalArgumentException("Unsupported pattern " + rPattern + " for right side of FROM COLLECT");
        }
        patternWidget.addOnModifiedCommand(new Command() {

            public void execute() {
                setModified(true);
            }
        });
        panel.setWidget(r++, 0, addRemoveButton(patternWidget, new ClickHandler() {

            public void onClick(ClickEvent event) {
                if (Window.confirm(GuidedRuleEditorResources.CONSTANTS.RemoveThisBlockOfData())) {
                    setModified(true);
                    getFromCollectPattern().setRightPattern(null);
                    getModeller().refreshWidget();
                }
            }
        }));
    }
    return panel;
}
Also used : IPattern(org.drools.workbench.models.datamodel.rule.IPattern) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) Widget(com.google.gwt.user.client.ui.Widget) FlexTable(com.google.gwt.user.client.ui.FlexTable) FromEntryPointFactPattern(org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) HTML(com.google.gwt.user.client.ui.HTML) FromCollectCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) FromCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern) Command(com.google.gwt.user.client.Command) FromAccumulateCompositeFactPattern(org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern) ClickableLabel(org.uberfire.ext.widgets.common.client.common.ClickableLabel)

Aggregations

FromEntryPointFactPattern (org.drools.workbench.models.datamodel.rule.FromEntryPointFactPattern)12 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)10 FromAccumulateCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromAccumulateCompositeFactPattern)9 FromCollectCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCollectCompositeFactPattern)9 FromCompositeFactPattern (org.drools.workbench.models.datamodel.rule.FromCompositeFactPattern)9 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)4 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)4 Widget (com.google.gwt.user.client.ui.Widget)4 CompositeFactPattern (org.drools.workbench.models.datamodel.rule.CompositeFactPattern)4 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)4 Test (org.junit.Test)4 ChangeEvent (com.google.gwt.event.dom.client.ChangeEvent)3 ChangeHandler (com.google.gwt.event.dom.client.ChangeHandler)3 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)3 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)3 Command (com.google.gwt.user.client.Command)2 FlexTable (com.google.gwt.user.client.ui.FlexTable)2 HTML (com.google.gwt.user.client.ui.HTML)2 FreeFormLine (org.drools.workbench.models.datamodel.rule.FreeFormLine)2 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)2