Search in sources :

Example 46 with BRLActionVariableColumn

use of org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn in project drools-wb by kiegroup.

the class BRLConditionColumnSynchronizerTest method checkBRLFragmentConditionCannotBeDeletedWhenFieldBindingIsUsedInAction.

@Test
public void checkBRLFragmentConditionCannotBeDeletedWhenFieldBindingIsUsedInAction() throws VetoException {
    final BRLConditionColumn column = new BRLConditionColumn();
    column.setDefinition(Collections.singletonList(new FactPattern("Applicant") {

        {
            setBoundName("$a");
            addConstraint(new SingleFieldConstraint("age") {

                {
                    setBoundName("$age");
                }
            });
        }
    }));
    final BRLConditionVariableColumn columnV0 = new BRLConditionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Applicant", "age");
    column.getChildColumns().add(columnV0);
    column.setHeader("col1");
    columnV0.setHeader("col1v0");
    modelSynchronizer.appendColumn(column);
    final BRLActionColumn action = new BRLActionColumn();
    action.setDefinition(Collections.singletonList(new ActionCallMethod() {

        {
            setVariable("$age");
            setMethodName("toString()");
        }
    }));
    final BRLActionVariableColumn columnV1 = new BRLActionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Applicant", "age");
    action.getChildColumns().add(columnV1);
    action.setHeader("col2");
    columnV1.setHeader("col2v0");
    modelSynchronizer.appendColumn(action);
    try {
        modelSynchronizer.deleteColumn(column);
        fail("Deletion of the column should have been vetoed.");
    } catch (VetoDeletePatternInUseException veto) {
    // This is expected
    } catch (VetoException veto) {
        fail("VetoDeletePatternInUseException was expected.");
    }
    assertEquals(5, model.getExpandedColumns().size());
    assertTrue(model.getExpandedColumns().get(0) instanceof RowNumberCol52);
    assertTrue(model.getExpandedColumns().get(1) instanceof RuleNameColumn);
    assertTrue(model.getExpandedColumns().get(2) instanceof DescriptionCol52);
    assertEquals(columnV0, model.getExpandedColumns().get(3));
    assertEquals(action.getChildColumns().get(0), model.getExpandedColumns().get(4));
}
Also used : BRLConditionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) VetoException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoException) BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) ActionCallMethod(org.drools.workbench.models.datamodel.rule.ActionCallMethod) FactPattern(org.drools.workbench.models.datamodel.rule.FactPattern) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) BRLConditionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn) RuleNameColumn(org.drools.workbench.models.guided.dtable.shared.model.RuleNameColumn) VetoDeletePatternInUseException(org.drools.workbench.screens.guided.dtable.client.widget.table.model.synchronizers.ModelSynchronizer.VetoDeletePatternInUseException) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 47 with BRLActionVariableColumn

use of org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn in project drools-wb by kiegroup.

the class BRLActionColumnSynchronizerTest method testUpdate3.

@Test
public void testUpdate3() throws VetoException {
    // Single Column, multiple variables
    final BRLActionColumn column = spy(new BRLActionColumn());
    final BRLActionVariableColumn columnV0 = new BRLActionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Applicant", "age");
    final BRLActionVariableColumn columnV1 = new BRLActionVariableColumn("$name", DataType.TYPE_STRING, "Applicant", "name");
    column.getChildColumns().add(columnV0);
    column.getChildColumns().add(columnV1);
    column.setHeader("col1");
    columnV0.setHeader("col1v0");
    columnV1.setHeader("col1v1");
    modelSynchronizer.appendColumn(column);
    assertEquals(5, model.getExpandedColumns().size());
    assertEquals(1, model.getActionCols().size());
    assertEquals(5, uiModel.getColumns().size());
    assertTrue(uiModel.getColumns().get(3) instanceof IntegerUiColumn);
    assertTrue(uiModel.getColumns().get(4) instanceof StringUiColumn);
    final BRLActionColumn edited = new BRLActionColumn();
    final BRLActionVariableColumn editedColumnV0 = new BRLActionVariableColumn("$s", DataType.TYPE_NUMERIC_LONG, "Applicant", "salary");
    edited.getChildColumns().add(editedColumnV0);
    edited.setHideColumn(true);
    edited.setHeader("updated");
    editedColumnV0.setHeader("updated");
    List<BaseColumnFieldDiff> diffs = modelSynchronizer.updateColumn(column, edited);
    assertEquals(6, // header, hide, field name, field type, binding, removed column
    diffs.size());
    verify(column).diff(edited);
    assertEquals(4, model.getExpandedColumns().size());
    assertEquals(1, model.getActionCols().size());
    assertEquals(4, uiModel.getColumns().size());
    assertTrue(uiModel.getColumns().get(3) instanceof LongUiColumn);
    assertEquals("updated", uiModel.getColumns().get(3).getHeaderMetaData().get(0).getTitle());
    assertEquals("$s", uiModel.getColumns().get(3).getHeaderMetaData().get(1).getTitle());
    assertEquals(false, uiModel.getColumns().get(3).isVisible());
}
Also used : BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) LongUiColumn(org.drools.workbench.screens.guided.dtable.client.widget.table.columns.LongUiColumn) StringUiColumn(org.drools.workbench.screens.guided.dtable.client.widget.table.columns.StringUiColumn) IntegerUiColumn(org.drools.workbench.screens.guided.dtable.client.widget.table.columns.IntegerUiColumn) BaseColumnFieldDiff(org.drools.workbench.models.guided.dtable.shared.model.BaseColumnFieldDiff) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) Test(org.junit.Test)

Example 48 with BRLActionVariableColumn

use of org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn in project drools-wb by kiegroup.

the class BRLActionColumnSynchronizerTest method testDelete.

@Test
public void testDelete() throws VetoException {
    final BRLActionColumn column = new BRLActionColumn();
    final BRLActionVariableColumn columnV0 = new BRLActionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Applicant", "age");
    final BRLActionVariableColumn columnV1 = new BRLActionVariableColumn("$name", DataType.TYPE_STRING, "Applicant", "name");
    column.getChildColumns().add(columnV0);
    column.getChildColumns().add(columnV1);
    column.setHeader("col1");
    columnV0.setHeader("col1v0");
    columnV1.setHeader("col1v1");
    modelSynchronizer.appendColumn(column);
    assertEquals(5, model.getExpandedColumns().size());
    assertEquals(1, model.getActionCols().size());
    assertEquals(5, uiModel.getColumns().size());
    modelSynchronizer.deleteColumn(column);
    assertEquals(3, model.getExpandedColumns().size());
    assertEquals(0, model.getActionCols().size());
    assertEquals(3, uiModel.getColumns().size());
}
Also used : BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) Test(org.junit.Test)

Example 49 with BRLActionVariableColumn

use of org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn in project drools-wb by kiegroup.

the class BRLActionColumnSynchronizerTest method testMoveBRLActionVariableColumnTo.

@Test
public void testMoveBRLActionVariableColumnTo() throws VetoException {
    final BRLActionColumn column1 = new BRLActionColumn();
    final BRLActionVariableColumn column1v0 = new BRLActionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Applicant", "age");
    column1v0.setHeader("age");
    final BRLActionVariableColumn column1v1 = new BRLActionVariableColumn("$name", DataType.TYPE_STRING, "Applicant", "name");
    column1v1.setHeader("name");
    final BRLActionColumn column2 = new BRLActionColumn();
    final BRLActionVariableColumn column2v0 = new BRLActionVariableColumn("$country", DataType.TYPE_STRING, "Address", "country");
    column2v0.setHeader("country");
    column1.getChildColumns().add(column1v0);
    column1.getChildColumns().add(column1v1);
    column2.getChildColumns().add(column2v0);
    modelSynchronizer.appendColumn(column1);
    modelSynchronizer.appendColumn(column2);
    modelSynchronizer.appendRow();
    uiModel.setCellValue(0, 3, new BaseGridCellValue<Integer>(55));
    uiModel.setCellValue(0, 4, new BaseGridCellValue<String>("Smurf"));
    uiModel.setCellValue(0, 5, new BaseGridCellValue<String>("Canada"));
    assertEquals(2, model.getActionCols().size());
    assertEquals(column1, model.getActionCols().get(0));
    assertEquals(column2, model.getActionCols().get(1));
    assertEquals(55, model.getData().get(0).get(3).getNumericValue());
    assertEquals("Smurf", model.getData().get(0).get(4).getStringValue());
    assertEquals("Canada", model.getData().get(0).get(5).getStringValue());
    assertEquals(6, uiModel.getColumns().size());
    final GridColumn<?> uiModelColumn1_1 = uiModel.getColumns().get(3);
    final GridColumn<?> uiModelColumn2_1 = uiModel.getColumns().get(4);
    final GridColumn<?> uiModelColumn3_1 = uiModel.getColumns().get(5);
    assertEquals("age", uiModelColumn1_1.getHeaderMetaData().get(0).getTitle());
    assertEquals("name", uiModelColumn2_1.getHeaderMetaData().get(0).getTitle());
    assertTrue(uiModelColumn1_1 instanceof IntegerUiColumn);
    assertTrue(uiModelColumn2_1 instanceof StringUiColumn);
    assertTrue(uiModelColumn3_1 instanceof StringUiColumn);
    assertEquals(3, uiModelColumn1_1.getIndex());
    assertEquals(4, uiModelColumn2_1.getIndex());
    assertEquals(5, uiModelColumn3_1.getIndex());
    assertEquals(55, uiModel.getRow(0).getCells().get(uiModelColumn1_1.getIndex()).getValue().getValue());
    assertEquals("Smurf", uiModel.getRow(0).getCells().get(uiModelColumn2_1.getIndex()).getValue().getValue());
    assertEquals("Canada", uiModel.getRow(0).getCells().get(uiModelColumn3_1.getIndex()).getValue().getValue());
    uiModel.moveColumnTo(3, uiModelColumn2_1);
    // The move should have been vetoed and nothing changed
    assertEquals(2, model.getActionCols().size());
    assertEquals(column1, model.getActionCols().get(0));
    assertEquals(column2, model.getActionCols().get(1));
    assertEquals(55, model.getData().get(0).get(3).getNumericValue());
    assertEquals("Smurf", model.getData().get(0).get(4).getStringValue());
    assertEquals("Canada", model.getData().get(0).get(5).getStringValue());
    assertEquals(6, uiModel.getColumns().size());
    final GridColumn<?> uiModelColumn1_2 = uiModel.getColumns().get(3);
    final GridColumn<?> uiModelColumn2_2 = uiModel.getColumns().get(4);
    final GridColumn<?> uiModelColumn3_2 = uiModel.getColumns().get(5);
    assertEquals("age", uiModelColumn1_2.getHeaderMetaData().get(0).getTitle());
    assertEquals("name", uiModelColumn2_2.getHeaderMetaData().get(0).getTitle());
    assertTrue(uiModelColumn1_2 instanceof IntegerUiColumn);
    assertTrue(uiModelColumn2_2 instanceof StringUiColumn);
    assertTrue(uiModelColumn3_2 instanceof StringUiColumn);
    assertEquals(3, uiModelColumn1_2.getIndex());
    assertEquals(4, uiModelColumn2_2.getIndex());
    assertEquals(5, uiModelColumn3_2.getIndex());
    assertEquals(55, uiModel.getRow(0).getCells().get(uiModelColumn1_2.getIndex()).getValue().getValue());
    assertEquals("Smurf", uiModel.getRow(0).getCells().get(uiModelColumn2_2.getIndex()).getValue().getValue());
    assertEquals("Canada", uiModel.getRow(0).getCells().get(uiModelColumn3_2.getIndex()).getValue().getValue());
}
Also used : BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) StringUiColumn(org.drools.workbench.screens.guided.dtable.client.widget.table.columns.StringUiColumn) IntegerUiColumn(org.drools.workbench.screens.guided.dtable.client.widget.table.columns.IntegerUiColumn) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) Test(org.junit.Test)

Example 50 with BRLActionVariableColumn

use of org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn in project drools-wb by kiegroup.

the class BRLActionColumnSynchronizerTest method testAppend1.

@Test
public void testAppend1() throws VetoException {
    // Single Column, single variable
    final BRLActionColumn column = new BRLActionColumn();
    final BRLActionVariableColumn columnV0 = new BRLActionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Applicant", "age");
    column.getChildColumns().add(columnV0);
    column.setHeader("col1");
    columnV0.setHeader("col1v0");
    modelSynchronizer.appendColumn(column);
    assertEquals(4, model.getExpandedColumns().size());
    assertEquals(1, model.getActionCols().size());
    assertEquals(4, uiModel.getColumns().size());
    assertTrue(uiModel.getColumns().get(3) instanceof IntegerUiColumn);
}
Also used : BRLActionColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn) IntegerUiColumn(org.drools.workbench.screens.guided.dtable.client.widget.table.columns.IntegerUiColumn) BRLActionVariableColumn(org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn) Test(org.junit.Test)

Aggregations

BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)72 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)56 Test (org.junit.Test)41 ArrayList (java.util.ArrayList)28 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)28 ActionFieldValue (org.drools.workbench.models.datamodel.rule.ActionFieldValue)23 IAction (org.drools.workbench.models.datamodel.rule.IAction)20 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)20 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)19 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)18 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)18 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)17 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)16 ActionInsertFact (org.drools.workbench.models.datamodel.rule.ActionInsertFact)13 RuleNameColumn (org.drools.workbench.models.guided.dtable.shared.model.RuleNameColumn)13 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)12 InputStream (java.io.InputStream)11 IPattern (org.drools.workbench.models.datamodel.rule.IPattern)11 ConversionResult (org.drools.workbench.models.guided.dtable.shared.conversion.ConversionResult)11 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)11