Search in sources :

Example 56 with FreeFormLine

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

the class RuleModellerActionSelectorPopup method addFreeFormDRL.

// Add free-form DRL
void addFreeFormDRL() {
    choices.addItem(SECTION_SEPARATOR);
    choices.addItem(GuidedRuleEditorResources.CONSTANTS.AddFreeFormDrl(), "FF");
    cmds.put("FF", new Command() {

        public void execute() {
            model.addRhsItem(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 57 with FreeFormLine

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

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

Example 59 with FreeFormLine

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

the class GuidedDecisionTableGeneratorListenerTest method checkConversionWithBigMaths.

private void checkConversionWithBigMaths(final ConversionResult result, final GuidedDecisionTableGeneratorListener listener, final Supplier<String> expectedDataType, final Supplier<Object> expectedDataValueRow0, final Supplier<Object> expectedDataValueRow1) {
    // Check conversion results
    assertEquals(0, result.getMessages().size());
    // Check basics
    final List<GuidedDecisionTable52> dtables = listener.getGuidedDecisionTables();
    assertNotNull(dtables);
    assertEquals(1, dtables.size());
    GuidedDecisionTable52 dtable = dtables.get(0);
    assertEquals("HelloWorld1", dtable.getTableName());
    assertEquals(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY, dtable.getTableFormat());
    // Check expanded columns
    List<BaseColumn> columns = dtable.getExpandedColumns();
    assertNotNull(columns);
    assertEquals(8, columns.size());
    assertTrue(columns.get(0) instanceof RowNumberCol52);
    assertTrue(columns.get(1) instanceof DescriptionCol52);
    assertTrue(columns.get(2) instanceof BRLConditionVariableColumn);
    assertTrue(columns.get(3) instanceof BRLActionVariableColumn);
    assertTrue(columns.get(4) instanceof BRLActionVariableColumn);
    assertTrue(columns.get(5) instanceof BRLActionVariableColumn);
    assertTrue(columns.get(6) instanceof BRLActionVariableColumn);
    assertTrue(columns.get(7) instanceof BRLActionVariableColumn);
    // Check individual condition columns
    assertEquals(1, dtable.getConditions().size());
    assertTrue(dtable.getConditions().get(0) instanceof BRLConditionColumn);
    BRLConditionColumn conditionCol0 = ((BRLConditionColumn) dtable.getConditions().get(0));
    assertEquals("Converted from ['Status']", conditionCol0.getHeader());
    assertEquals(1, conditionCol0.getChildColumns().size());
    List<IPattern> conditionCol0definition = conditionCol0.getDefinition();
    assertEquals(1, conditionCol0definition.size());
    assertTrue(conditionCol0definition.get(0) instanceof FactPattern);
    FactPattern conditionCol0fp = (FactPattern) conditionCol0definition.get(0);
    assertEquals("Message", conditionCol0fp.getFactType());
    assertEquals(1, conditionCol0fp.getNumberOfConstraints());
    // Field Constraint 1
    assertTrue(conditionCol0fp.getConstraint(0) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol0fpsfc0 = (SingleFieldConstraint) conditionCol0fp.getConstraint(0);
    assertEquals("status", conditionCol0fpsfc0.getFieldName());
    assertEquals("==", conditionCol0fpsfc0.getOperator());
    assertEquals("param1", conditionCol0fpsfc0.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0fpsfc0.getConstraintValueType());
    assertEquals(DataType.TYPE_STRING, conditionCol0fpsfc0.getFieldType());
    // Field Constraint 1 - Variable 1
    BRLConditionVariableColumn conditionCol0param0 = conditionCol0.getChildColumns().get(0);
    assertEquals("param1", conditionCol0param0.getVarName());
    assertEquals("Status", conditionCol0param0.getHeader());
    assertEquals(DataType.TYPE_STRING, conditionCol0param0.getFieldType());
    assertEquals("Message", conditionCol0param0.getFactType());
    assertEquals("status", conditionCol0param0.getFactField());
    // Check individual action columns
    assertEquals(3, dtable.getActionCols().size());
    // Action 1
    assertTrue(dtable.getActionCols().get(0) instanceof BRLActionColumn);
    BRLActionColumn actionCol0 = ((BRLActionColumn) dtable.getActionCols().get(0));
    assertEquals("Converted from ['Print out message?']", actionCol0.getHeader());
    assertEquals(1, actionCol0.getChildColumns().size());
    List<IAction> actionCol0definition = actionCol0.getDefinition();
    assertEquals(1, actionCol0definition.size());
    assertTrue(actionCol0definition.get(0) instanceof FreeFormLine);
    FreeFormLine actionCol0ffl0 = (FreeFormLine) actionCol0definition.get(0);
    assertEquals("System.out.println(m.getMessage());", actionCol0ffl0.getText());
    // Action 2
    BRLActionColumn actionCol1 = ((BRLActionColumn) dtable.getActionCols().get(1));
    assertEquals("Converted from ['Set message', 'Set status', 'Set rate']", actionCol1.getHeader());
    assertEquals(3, actionCol1.getChildColumns().size());
    List<IAction> actionCol1definition = actionCol1.getDefinition();
    assertEquals(1, actionCol1definition.size());
    assertTrue(actionCol1definition.get(0) instanceof ActionSetField);
    ActionSetField actionCol1asf0 = (ActionSetField) actionCol1definition.get(0);
    assertEquals("m", actionCol1asf0.getVariable());
    ActionFieldValue[] actionCol1asf0afvs = actionCol1asf0.getFieldValues();
    assertEquals(3, actionCol1asf0afvs.length);
    ActionFieldValue actionCol1asf0afv0 = actionCol1asf0afvs[0];
    assertEquals("message", actionCol1asf0afv0.getField());
    assertEquals("param2", actionCol1asf0afv0.getValue());
    assertEquals(FieldNatureType.TYPE_TEMPLATE, actionCol1asf0afv0.getNature());
    assertEquals(DataType.TYPE_STRING, actionCol1asf0afv0.getType());
    ActionFieldValue actionCol1asf0afv1 = actionCol1asf0afvs[1];
    assertEquals("status", actionCol1asf0afv1.getField());
    assertEquals("param3", actionCol1asf0afv1.getValue());
    assertEquals(FieldNatureType.TYPE_TEMPLATE, actionCol1asf0afv1.getNature());
    assertEquals(DataType.TYPE_STRING, actionCol1asf0afv1.getType());
    // Action 1 - Variable 1
    BRLActionVariableColumn actionCol0param0 = actionCol0.getChildColumns().get(0);
    assertEquals("", actionCol0param0.getVarName());
    assertEquals("Print out message?", actionCol0param0.getHeader());
    assertEquals(DataType.TYPE_BOOLEAN, actionCol0param0.getFieldType());
    assertNull(actionCol0param0.getFactType());
    assertNull(actionCol0param0.getFactField());
    assertTrue(dtable.getActionCols().get(0) instanceof BRLActionColumn);
    // Action 2 - Variable 1
    BRLActionVariableColumn actionCol1param0 = actionCol1.getChildColumns().get(0);
    assertEquals("param2", actionCol1param0.getVarName());
    assertEquals("Set message", actionCol1param0.getHeader());
    assertEquals(DataType.TYPE_STRING, actionCol1param0.getFieldType());
    assertEquals("Message", actionCol1param0.getFactType());
    assertEquals("message", actionCol1param0.getFactField());
    // Action 2 - Variable 2
    BRLActionVariableColumn actionCol1param1 = actionCol1.getChildColumns().get(1);
    assertEquals("param3", actionCol1param1.getVarName());
    assertEquals("Set status", actionCol1param1.getHeader());
    assertEquals(DataType.TYPE_STRING, actionCol1param1.getFieldType());
    assertEquals("Message", actionCol1param1.getFactType());
    assertEquals("status", actionCol1param1.getFactField());
    // Action 2 - Variable 3
    BRLActionVariableColumn actionCol1param2 = actionCol1.getChildColumns().get(2);
    assertEquals("param4", actionCol1param2.getVarName());
    assertEquals("Set rate", actionCol1param2.getHeader());
    assertEquals(expectedDataType.get(), actionCol1param2.getFieldType());
    assertEquals("Message", actionCol1param2.getFactType());
    assertEquals("rate", actionCol1param2.getFactField());
    // Check data
    assertEquals(2, dtable.getData().size());
    assertTrue(isRowEquivalent(new Object[] { 1, "Hello World", "Message.HELLO", false, "Goodbye cruel world", "Message.GOODBYE", expectedDataValueRow0.get(), "m" }, dtable.getData().get(0)));
    assertTrue(isRowEquivalent(new Object[] { 2, "Goodbye", "Message.GOODBYE", false, "", "", expectedDataValueRow1.get(), "m" }, dtable.getData().get(1)));
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) IPattern(org.drools.workbench.models.datamodel.rule.IPattern) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) IAction(org.drools.workbench.models.datamodel.rule.IAction) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) ActionSetField(org.drools.workbench.models.datamodel.rule.ActionSetField) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ActionFieldValue(org.drools.workbench.models.datamodel.rule.ActionFieldValue) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)

Example 60 with FreeFormLine

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

the class GuidedDecisionTableGeneratorListenerTest method conversionWithRetract.

@Test
public // https://issues.jboss.org/browse/GUVNOR-2888
void conversionWithRetract() {
    final ConversionResult result = new ConversionResult();
    final List<DataListener> listeners = new ArrayList<>();
    addModelField("org.test.Employee", "this", "org.test.Employee", DataType.TYPE_THIS);
    addModelField("org.test.Employee", "yearsOfService", Integer.class.getName(), DataType.TYPE_NUMERIC_INTEGER);
    addModelField("org.test.Employee", "name", String.class.getName(), DataType.TYPE_STRING);
    addModelField("org.test.Employee", "bigAbsence", Boolean.class.getName(), DataType.TYPE_BOOLEAN);
    addModelField("org.test.Bonus", "this", "org.test.Bonus", DataType.TYPE_THIS);
    addModelField("org.test.Bonus", "amount", Double.class.getName(), DataType.TYPE_NUMERIC_DOUBLE);
    addModelField("org.test.Bonus", "employee", "org.test.Employee", DataType.TYPE_OBJECT);
    final GuidedDecisionTableGeneratorListener listener = new GuidedDecisionTableGeneratorListener(result, dmo);
    listeners.add(listener);
    // Convert
    final ExcelParser parser = new ExcelParser(listeners);
    final InputStream is = this.getClass().getResourceAsStream("GUVNOR-2888.xlsx");
    try {
        parser.parseFile(is);
    } finally {
        try {
            is.close();
        } catch (IOException ioe) {
            fail(ioe.getMessage());
        }
    }
    // Check conversion results
    assertEquals(1, result.getMessages().size());
    assertTrue(result.getMessages().get(0).getMessage().contains("I13"));
    // Check basics
    final List<GuidedDecisionTable52> dtables = listener.getGuidedDecisionTables();
    assertNotNull(dtables);
    assertEquals(1, dtables.size());
    GuidedDecisionTable52 dtable = dtables.get(0);
    assertEquals("bonus_program", dtable.getTableName());
    assertEquals(GuidedDecisionTable52.TableFormat.EXTENDED_ENTRY, dtable.getTableFormat());
    // Check expanded columns
    List<BaseColumn> columns = dtable.getExpandedColumns();
    assertNotNull(columns);
    assertEquals(11, columns.size());
    assertTrue(columns.get(0) instanceof RowNumberCol52);
    assertTrue(columns.get(1) instanceof DescriptionCol52);
    assertTrue(columns.get(2) instanceof BRLConditionVariableColumn);
    assertTrue(columns.get(3) instanceof BRLConditionVariableColumn);
    assertTrue(columns.get(4) instanceof BRLConditionVariableColumn);
    assertTrue(columns.get(5) instanceof BRLConditionVariableColumn);
    assertTrue(columns.get(6) instanceof BRLConditionVariableColumn);
    assertTrue(columns.get(7) instanceof BRLConditionVariableColumn);
    assertTrue(columns.get(8) instanceof BRLActionVariableColumn);
    assertTrue(columns.get(9) instanceof BRLActionVariableColumn);
    assertTrue(columns.get(10) instanceof BRLActionVariableColumn);
    // Check individual condition columns
    assertEquals(3, dtable.getConditions().size());
    // Pattern 0
    assertTrue(dtable.getConditions().get(0) instanceof BRLConditionColumn);
    BRLConditionColumn conditionCol0 = ((BRLConditionColumn) dtable.getConditions().get(0));
    assertEquals("Converted from ['Served between', 'Served between', 'Served more', 'absence']", conditionCol0.getHeader());
    assertEquals(4, conditionCol0.getChildColumns().size());
    List<IPattern> conditionCol0definition = conditionCol0.getDefinition();
    assertEquals(1, conditionCol0definition.size());
    assertTrue(conditionCol0definition.get(0) instanceof FactPattern);
    FactPattern conditionCol0fp = (FactPattern) conditionCol0definition.get(0);
    assertEquals("Employee", conditionCol0fp.getFactType());
    assertEquals(4, conditionCol0fp.getNumberOfConstraints());
    // Pattern 0 - Field Constraint 0
    assertTrue(conditionCol0fp.getConstraint(0) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol0fpsfc0 = (SingleFieldConstraint) conditionCol0fp.getConstraint(0);
    assertEquals("yearsOfService", conditionCol0fpsfc0.getFieldName());
    assertEquals(">=", conditionCol0fpsfc0.getOperator());
    assertEquals("param1", conditionCol0fpsfc0.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0fpsfc0.getConstraintValueType());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, conditionCol0fpsfc0.getFieldType());
    // Pattern 0 - Field Constraint 0 - Variable 0
    BRLConditionVariableColumn conditionCol0param0 = conditionCol0.getChildColumns().get(0);
    assertEquals("param1", conditionCol0param0.getVarName());
    assertEquals("Served between", conditionCol0param0.getHeader());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, conditionCol0param0.getFieldType());
    assertEquals("Employee", conditionCol0param0.getFactType());
    assertEquals("yearsOfService", conditionCol0param0.getFactField());
    // Pattern 0 - Field Constraint 1
    assertTrue(conditionCol0fp.getConstraint(1) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol0fpsfc1 = (SingleFieldConstraint) conditionCol0fp.getConstraint(1);
    assertEquals("yearsOfService", conditionCol0fpsfc1.getFieldName());
    assertEquals("<", conditionCol0fpsfc1.getOperator());
    assertEquals("param2", conditionCol0fpsfc1.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0fpsfc1.getConstraintValueType());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, conditionCol0fpsfc1.getFieldType());
    // Pattern 0 - Field Constraint 1 - Variable 0
    BRLConditionVariableColumn conditionCol0param1 = conditionCol0.getChildColumns().get(1);
    assertEquals("param2", conditionCol0param1.getVarName());
    assertEquals("Served between", conditionCol0param1.getHeader());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, conditionCol0param1.getFieldType());
    assertEquals("Employee", conditionCol0param1.getFactType());
    assertEquals("yearsOfService", conditionCol0param1.getFactField());
    // Pattern 0 - Field Constraint 2
    assertTrue(conditionCol0fp.getConstraint(2) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol0fpsfc2 = (SingleFieldConstraint) conditionCol0fp.getConstraint(2);
    assertEquals("yearsOfService", conditionCol0fpsfc2.getFieldName());
    assertEquals(">", conditionCol0fpsfc2.getOperator());
    assertEquals("param3", conditionCol0fpsfc2.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0fpsfc2.getConstraintValueType());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, conditionCol0fpsfc2.getFieldType());
    // Pattern 0 - Field Constraint 2 - Variable 0
    BRLConditionVariableColumn conditionCol0param2 = conditionCol0.getChildColumns().get(2);
    assertEquals("param3", conditionCol0param2.getVarName());
    assertEquals("Served more", conditionCol0param2.getHeader());
    assertEquals(DataType.TYPE_NUMERIC_INTEGER, conditionCol0param2.getFieldType());
    assertEquals("Employee", conditionCol0param2.getFactType());
    assertEquals("yearsOfService", conditionCol0param2.getFactField());
    // Pattern 0 - Field Constraint 3
    assertTrue(conditionCol0fp.getConstraint(3) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol0fpsfc3 = (SingleFieldConstraint) conditionCol0fp.getConstraint(3);
    assertEquals("bigAbsence", conditionCol0fpsfc3.getFieldName());
    assertEquals("==", conditionCol0fpsfc3.getOperator());
    assertEquals("param4", conditionCol0fpsfc3.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0fpsfc3.getConstraintValueType());
    assertEquals(DataType.TYPE_BOOLEAN, conditionCol0fpsfc3.getFieldType());
    // Pattern 0 - Field Constraint 3 - Variable 0
    BRLConditionVariableColumn conditionCol0param3 = conditionCol0.getChildColumns().get(3);
    assertEquals("param4", conditionCol0param3.getVarName());
    assertEquals("absence", conditionCol0param3.getHeader());
    assertEquals(DataType.TYPE_BOOLEAN, conditionCol0param3.getFieldType());
    assertEquals("Employee", conditionCol0param3.getFactType());
    assertEquals("bigAbsence", conditionCol0param3.getFactField());
    // Pattern 1
    assertTrue(dtable.getConditions().get(1) instanceof BRLConditionColumn);
    BRLConditionColumn conditionCol1 = ((BRLConditionColumn) dtable.getConditions().get(1));
    assertEquals("Converted from ['bonus for employee']", conditionCol1.getHeader());
    assertEquals(1, conditionCol1.getChildColumns().size());
    List<IPattern> conditionCol1definition = conditionCol1.getDefinition();
    assertEquals(1, conditionCol1definition.size());
    assertTrue(conditionCol1definition.get(0) instanceof FactPattern);
    FactPattern conditionCol1fp = (FactPattern) conditionCol1definition.get(0);
    assertEquals("Bonus", conditionCol1fp.getFactType());
    assertEquals(1, conditionCol1fp.getNumberOfConstraints());
    // Pattern 1 - Field Constraint 0
    assertTrue(conditionCol1fp.getConstraint(0) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol1fpsfc0 = (SingleFieldConstraint) conditionCol1fp.getConstraint(0);
    assertEquals("employee", conditionCol1fpsfc0.getFieldName());
    assertEquals("==", conditionCol1fpsfc0.getOperator());
    assertEquals("param5", conditionCol1fpsfc0.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol1fpsfc0.getConstraintValueType());
    assertEquals(DataType.TYPE_OBJECT, conditionCol1fpsfc0.getFieldType());
    // Pattern 1 - Field Constraint 0 - Variable 0
    BRLConditionVariableColumn conditionCol1param0 = conditionCol1.getChildColumns().get(0);
    assertEquals("param5", conditionCol1param0.getVarName());
    assertEquals("bonus for employee", conditionCol1param0.getHeader());
    assertEquals(DataType.TYPE_OBJECT, conditionCol1param0.getFieldType());
    assertEquals("Bonus", conditionCol1param0.getFactType());
    assertEquals("employee", conditionCol1param0.getFactField());
    // Pattern 2
    assertTrue(dtable.getConditions().get(2) instanceof BRLConditionColumn);
    BRLConditionColumn conditionCol2 = ((BRLConditionColumn) dtable.getConditions().get(2));
    assertEquals("Converted from ['no bonus for employee']", conditionCol2.getHeader());
    assertEquals(1, conditionCol2.getChildColumns().size());
    List<IPattern> conditionCol2definition = conditionCol2.getDefinition();
    assertEquals(1, conditionCol2definition.size());
    assertTrue(conditionCol2definition.get(0) instanceof CompositeFactPattern);
    CompositeFactPattern conditionCol2cfp = (CompositeFactPattern) conditionCol2definition.get(0);
    assertEquals(CompositeFactPattern.COMPOSITE_TYPE_NOT, conditionCol2cfp.getType());
    assertEquals(1, conditionCol2cfp.getPatterns().length);
    assertTrue(conditionCol2cfp.getPatterns()[0] instanceof FactPattern);
    FactPattern conditionCol2fp = (FactPattern) conditionCol2cfp.getPatterns()[0];
    assertEquals("Bonus", conditionCol2fp.getFactType());
    assertEquals(1, conditionCol2fp.getNumberOfConstraints());
    // Pattern 2 - Field Constraint 0
    assertTrue(conditionCol2fp.getConstraint(0) instanceof SingleFieldConstraint);
    final SingleFieldConstraint conditionCol2fpsfc0 = (SingleFieldConstraint) conditionCol2fp.getConstraint(0);
    assertEquals("employee", conditionCol2fpsfc0.getFieldName());
    assertEquals("==", conditionCol2fpsfc0.getOperator());
    assertEquals("param6", conditionCol2fpsfc0.getValue());
    assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol2fpsfc0.getConstraintValueType());
    assertEquals(DataType.TYPE_OBJECT, conditionCol2fpsfc0.getFieldType());
    // Pattern 2 - Field Constraint 0 - Variable 0
    BRLConditionVariableColumn conditionCol2param0 = conditionCol2.getChildColumns().get(0);
    assertEquals("param6", conditionCol2param0.getVarName());
    assertEquals("no bonus for employee", conditionCol2param0.getHeader());
    assertEquals(DataType.TYPE_OBJECT, conditionCol2param0.getFieldType());
    assertEquals("Bonus", conditionCol2param0.getFactType());
    assertEquals("employee", conditionCol2param0.getFactField());
    // Check individual action columns
    assertEquals(3, dtable.getActionCols().size());
    // Action 0
    assertTrue(dtable.getActionCols().get(0) instanceof BRLActionColumn);
    BRLActionColumn actionCol0 = ((BRLActionColumn) dtable.getActionCols().get(0));
    assertEquals("Converted from ['Inser bonus of amount']", actionCol0.getHeader());
    assertEquals(1, actionCol0.getChildColumns().size());
    List<IAction> actionCol0definition = actionCol0.getDefinition();
    assertEquals(1, actionCol0definition.size());
    assertTrue(actionCol0definition.get(0) instanceof FreeFormLine);
    FreeFormLine actionCol0ffl0 = (FreeFormLine) actionCol0definition.get(0);
    assertEquals("Bonus $b = new Bonus(); $b.setAmount((double)@{param7}); $b.setEmployee($e); insert($b);", actionCol0ffl0.getText());
    // Action 0 - Variable 0
    BRLActionVariableColumn actionCol0param0 = actionCol0.getChildColumns().get(0);
    assertEquals("param7", actionCol0param0.getVarName());
    assertEquals("Inser bonus of amount", actionCol0param0.getHeader());
    assertEquals(DataType.TYPE_OBJECT, actionCol0param0.getFieldType());
    // Action 1
    BRLActionColumn actionCol1 = ((BRLActionColumn) dtable.getActionCols().get(1));
    assertEquals("Converted from ['retract']", actionCol1.getHeader());
    assertEquals(1, actionCol1.getChildColumns().size());
    List<IAction> actionCol1definition = actionCol1.getDefinition();
    assertEquals(1, actionCol1definition.size());
    assertTrue(actionCol1definition.get(0) instanceof ActionRetractFact);
    ActionRetractFact actionCol1arf = (ActionRetractFact) actionCol1definition.get(0);
    assertEquals("$bonus", actionCol1arf.getVariableName());
    assertTrue(dtable.getActionCols().get(1) instanceof BRLActionColumn);
    // Action 1 - Variable 0
    BRLActionVariableColumn actionCol1param0 = actionCol1.getChildColumns().get(0);
    assertEquals("param8", actionCol1param0.getVarName());
    assertEquals("retract", actionCol1param0.getHeader());
    assertEquals(DataType.TYPE_BOOLEAN, actionCol1param0.getFieldType());
    // Action 2
    BRLActionColumn actionCol2 = ((BRLActionColumn) dtable.getActionCols().get(2));
    assertEquals("Converted from ['retract2']", actionCol2.getHeader());
    assertEquals(1, actionCol2.getChildColumns().size());
    List<IAction> actionCol2definition = actionCol2.getDefinition();
    assertEquals(1, actionCol2definition.size());
    assertTrue(actionCol2definition.get(0) instanceof ActionRetractFact);
    ActionRetractFact actionCol2arf = (ActionRetractFact) actionCol2definition.get(0);
    assertEquals("$b", actionCol2arf.getVariableName());
    assertTrue(dtable.getActionCols().get(2) instanceof BRLActionColumn);
    // Action 2 - Variable 1
    BRLActionVariableColumn actionCol2param0 = actionCol2.getChildColumns().get(0);
    assertEquals("", actionCol2param0.getVarName());
    assertEquals("retract2", actionCol2param0.getHeader());
    assertEquals(DataType.TYPE_BOOLEAN, actionCol2param0.getFieldType());
    // Check data
    assertEquals(4, dtable.getData().size());
    assertTrue(isRowEquivalent(new Object[] { 1, "Lowest bonus", 0, 2, null, false, "", "$e", "400", false, false }, dtable.getData().get(0)));
    assertTrue(isRowEquivalent(new Object[] { 2, "Middle bonus", 2, 6, null, false, "", "$e", "800", false, false }, dtable.getData().get(1)));
    assertTrue(isRowEquivalent(new Object[] { 3, "High bonus", null, null, 6, false, "", "", "1000", false, false }, dtable.getData().get(2)));
    assertTrue(isRowEquivalent(new Object[] { 4, "Big absence", null, null, null, true, "$e", "", "", true, true }, dtable.getData().get(3)));
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) IPattern(org.drools.workbench.models.datamodel.rule.IPattern) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) ArrayList(java.util.ArrayList) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) CompositeFactPattern(org.drools.workbench.models.datamodel.rule.CompositeFactPattern) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) ActionRetractFact(org.drools.workbench.models.datamodel.rule.ActionRetractFact) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ExcelParser(org.drools.decisiontable.parser.xls.ExcelParser) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) IAction(org.drools.workbench.models.datamodel.rule.IAction) InputStream(java.io.InputStream) IOException(java.io.IOException) BigInteger(java.math.BigInteger) ConversionResult(org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult) FreeFormLine(org.drools.workbench.models.datamodel.rule.FreeFormLine) DataListener(org.drools.template.parser.DataListener) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) 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