Search in sources :

Example 16 with CompositeColumn

use of org.drools.workbench.models.guided.dtable.shared.model.CompositeColumn in project drools by kiegroup.

the class GuidedDTDRLPersistenceTest method testLHSOtherwisePatternBoolean.

@Test
public void testLHSOtherwisePatternBoolean() {
    GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
    String[][] row = new String[2][];
    String[][] data = new String[2][];
    row[0] = new String[] { "1", "desc1", "true", "false" };
    List<DTCellValue52> rowDTModel0 = DataUtilities.makeDataRowList(row[0]);
    data[0] = row[0];
    row[1] = new String[] { "3", "desc3", null, null };
    List<DTCellValue52> rowDTModel1 = DataUtilities.makeDataRowList(row[1]);
    rowDTModel1.get(2).setOtherwise(true);
    rowDTModel1.get(3).setOtherwise(true);
    data[1] = row[1];
    final List<List<DTCellValue52>> allDTData = new ArrayList<List<DTCellValue52>>() {

        {
            add(rowDTModel0);
            add(rowDTModel1);
        }
    };
    List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
    List<CompositeColumn<? extends BaseColumn>> allPatterns = new ArrayList<CompositeColumn<? extends BaseColumn>>();
    allColumns.add(new RowNumberCol52());
    allColumns.add(new DescriptionCol52());
    Pattern52 p1 = new Pattern52();
    p1.setBoundName("p1");
    p1.setFactType("Person");
    allPatterns.add(p1);
    ConditionCol52 col = new ConditionCol52();
    col.setFactField("alive");
    col.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    col.setFieldType(DataType.TYPE_BOOLEAN);
    col.setOperator("==");
    p1.getChildColumns().add(col);
    allColumns.add(col);
    Pattern52 p2 = new Pattern52();
    p2.setBoundName("p2");
    p2.setFactType("Person");
    allPatterns.add(p2);
    ConditionCol52 col2 = new ConditionCol52();
    col2.setFactField("alive");
    col2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    col2.setFieldType(DataType.TYPE_BOOLEAN);
    col2.setOperator("!=");
    p2.getChildColumns().add(col2);
    allColumns.add(col2);
    RuleModel rm = new RuleModel();
    TemplateDataProvider rowDataProvider0 = new GuidedDTTemplateDataProvider(allColumns, rowDTModel0);
    p.doConditions(allColumns, allPatterns, rowDataProvider0, rowDTModel0, allDTData, rm);
    String drl0 = RuleModelDRLPersistenceImpl.getInstance().marshal(rm);
    assertEquals(2, rm.lhs.length);
    assertEquals("Person", ((FactPattern) rm.lhs[0]).getFactType());
    assertEquals("p1", ((FactPattern) rm.lhs[0]).getBoundName());
    assertEquals("Person", ((FactPattern) rm.lhs[1]).getFactType());
    assertEquals("p2", ((FactPattern) rm.lhs[1]).getBoundName());
    assertTrue(drl0.indexOf("p1 : Person( alive == true )") > 0);
    assertTrue(drl0.indexOf("p2 : Person( alive != false )") > 0);
    TemplateDataProvider rowDataProvider1 = new GuidedDTTemplateDataProvider(allColumns, rowDTModel1);
    p.doConditions(allColumns, allPatterns, rowDataProvider1, rowDTModel1, allDTData, rm);
    String drl1 = RuleModelDRLPersistenceImpl.getInstance().marshal(rm);
    assertEquals(2, rm.lhs.length);
    assertEquals("Person", ((FactPattern) rm.lhs[0]).getFactType());
    assertEquals("p1", ((FactPattern) rm.lhs[0]).getBoundName());
    assertEquals("Person", ((FactPattern) rm.lhs[1]).getFactType());
    assertEquals("p2", ((FactPattern) rm.lhs[1]).getBoundName());
    assertTrue(drl1.indexOf("p1 : Person( alive not in ( true )") > 0);
    assertTrue(drl1.indexOf("p2 : Person( alive in ( false )") > 0);
}
Also used : ArrayList(java.util.ArrayList) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) CompositeColumn(org.drools.workbench.models.guided.dtable.shared.model.CompositeColumn) LimitedEntryConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) List(java.util.List) ArrayList(java.util.ArrayList) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) TemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.TemplateDataProvider) Test(org.junit.Test)

Example 17 with CompositeColumn

use of org.drools.workbench.models.guided.dtable.shared.model.CompositeColumn in project drools by kiegroup.

the class GuidedDTDRLPersistenceTest method testLHSOtherwisePatternDate.

@Test
public void testLHSOtherwisePatternDate() {
    GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
    String[][] row = new String[3][];
    String[][] data = new String[3][];
    row[0] = new String[] { "1", "desc1", "01-Jan-1980", "20-Jun-1985" };
    List<DTCellValue52> rowDTModel0 = DataUtilities.makeDataRowList(row[0]);
    data[0] = row[0];
    row[1] = new String[] { "2", "desc2", "01-Feb-1981", "21-Jun-1986" };
    List<DTCellValue52> rowDTModel1 = DataUtilities.makeDataRowList(row[1]);
    data[1] = row[1];
    row[2] = new String[] { "3", "desc3", null, null };
    List<DTCellValue52> rowDTModel2 = DataUtilities.makeDataRowList(row[2]);
    rowDTModel2.get(2).setOtherwise(true);
    rowDTModel2.get(3).setOtherwise(true);
    data[2] = row[2];
    final List<List<DTCellValue52>> allDTData = new ArrayList<List<DTCellValue52>>() {

        {
            add(rowDTModel0);
            add(rowDTModel1);
            add(rowDTModel2);
        }
    };
    List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
    List<CompositeColumn<? extends BaseColumn>> allPatterns = new ArrayList<CompositeColumn<? extends BaseColumn>>();
    allColumns.add(new RowNumberCol52());
    allColumns.add(new DescriptionCol52());
    Pattern52 p1 = new Pattern52();
    p1.setBoundName("p1");
    p1.setFactType("Person");
    allPatterns.add(p1);
    ConditionCol52 col = new ConditionCol52();
    col.setFactField("dateOfBirth");
    col.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    col.setFieldType(DataType.TYPE_DATE);
    col.setOperator("==");
    p1.getChildColumns().add(col);
    allColumns.add(col);
    Pattern52 p2 = new Pattern52();
    p2.setBoundName("p2");
    p2.setFactType("Person");
    allPatterns.add(p2);
    ConditionCol52 col2 = new ConditionCol52();
    col2.setFactField("dateOfBirth");
    col2.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    col2.setFieldType(DataType.TYPE_DATE);
    col2.setOperator("!=");
    p2.getChildColumns().add(col2);
    allColumns.add(col2);
    RuleModel rm = new RuleModel();
    TemplateDataProvider rowDataProvider0 = new GuidedDTTemplateDataProvider(allColumns, rowDTModel0);
    p.doConditions(allColumns, allPatterns, rowDataProvider0, rowDTModel0, allDTData, rm);
    String drl0 = RuleModelDRLPersistenceImpl.getInstance().marshal(rm);
    assertEquals(2, rm.lhs.length);
    assertEquals("Person", ((FactPattern) rm.lhs[0]).getFactType());
    assertEquals("p1", ((FactPattern) rm.lhs[0]).getBoundName());
    assertEquals("Person", ((FactPattern) rm.lhs[1]).getFactType());
    assertEquals("p2", ((FactPattern) rm.lhs[1]).getBoundName());
    assertTrue(drl0.indexOf("p1 : Person( dateOfBirth == \"01-Jan-1980\" )") > 0);
    assertTrue(drl0.indexOf("p2 : Person( dateOfBirth != \"20-Jun-1985\" )") > 0);
    TemplateDataProvider rowDataProvider1 = new GuidedDTTemplateDataProvider(allColumns, rowDTModel1);
    p.doConditions(allColumns, allPatterns, rowDataProvider1, rowDTModel1, allDTData, rm);
    String drl1 = RuleModelDRLPersistenceImpl.getInstance().marshal(rm);
    assertEquals(2, rm.lhs.length);
    assertEquals("Person", ((FactPattern) rm.lhs[0]).getFactType());
    assertEquals("p1", ((FactPattern) rm.lhs[0]).getBoundName());
    assertEquals("Person", ((FactPattern) rm.lhs[1]).getFactType());
    assertEquals("p2", ((FactPattern) rm.lhs[1]).getBoundName());
    assertTrue(drl1.indexOf("p1 : Person( dateOfBirth == \"01-Feb-1981\" )") > 0);
    assertTrue(drl1.indexOf("p2 : Person( dateOfBirth != \"21-Jun-1986\" )") > 0);
    TemplateDataProvider rowDataProvider2 = new GuidedDTTemplateDataProvider(allColumns, rowDTModel2);
    p.doConditions(allColumns, allPatterns, rowDataProvider2, rowDTModel2, allDTData, rm);
    String drl2 = RuleModelDRLPersistenceImpl.getInstance().marshal(rm);
    assertEquals(2, rm.lhs.length);
    assertEquals("Person", ((FactPattern) rm.lhs[0]).getFactType());
    assertEquals("p1", ((FactPattern) rm.lhs[0]).getBoundName());
    assertEquals("Person", ((FactPattern) rm.lhs[1]).getFactType());
    assertEquals("p2", ((FactPattern) rm.lhs[1]).getBoundName());
    assertTrue(drl2.indexOf("p1 : Person( dateOfBirth not in ( \"01-Jan-1980\", \"01-Feb-1981\" )") > 0);
    assertTrue(drl2.indexOf("p2 : Person( dateOfBirth in ( \"20-Jun-1985\", \"21-Jun-1986\" )") > 0);
}
Also used : ArrayList(java.util.ArrayList) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) CompositeColumn(org.drools.workbench.models.guided.dtable.shared.model.CompositeColumn) LimitedEntryConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52) ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) Pattern52(org.drools.workbench.models.guided.dtable.shared.model.Pattern52) List(java.util.List) ArrayList(java.util.ArrayList) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) GuidedDTTemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider) TemplateDataProvider(org.drools.workbench.models.guided.dtable.backend.util.TemplateDataProvider) Test(org.junit.Test)

Example 18 with CompositeColumn

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

the class ColumnsPagePresenterTest method testRefreshConditionsWidgetWhenConditionColumnsIsNotEmpty.

@Test
public void testRefreshConditionsWidgetWhenConditionColumnsIsNotEmpty() {
    final ColumnManagementView columnManagementView = mock(ColumnManagementView.class);
    final GuidedDecisionTableAccordionItem item = mock(GuidedDecisionTableAccordionItem.class);
    final Label blankSlate = mock(Label.class);
    final List<CompositeColumn<? extends BaseColumn>> conditions1 = new ArrayList<CompositeColumn<? extends BaseColumn>>() {

        {
            add(compositeColumn1);
        }
    };
    final Map<String, List<BaseColumn>> conditions2 = new HashMap<String, List<BaseColumn>>() {

        {
            put("title", new ArrayList<>());
        }
    };
    doReturn(verticalPanel).when(presenter).getConditionsWidget();
    doReturn(columnManagementView).when(presenter).getConditionsPanel();
    doReturn(blankSlate).when(presenter).blankSlate();
    doReturn(item).when(accordion).getItem(CONDITION);
    doReturn(conditions2).when(presenter).groupByTitle(conditions1);
    presenter.refreshConditionsWidget(conditions1);
    verify(item, never()).setOpen(false);
    verify(verticalPanel, never()).add(blankSlate);
    verify(verticalPanel).add(columnManagementView);
    verify(columnManagementView).renderColumns(conditions2);
}
Also used : HashMap(com.google.gwt.dev.util.collect.HashMap) ColumnManagementView(org.drools.workbench.screens.guided.dtable.client.widget.table.columns.control.ColumnManagementView) Label(com.google.gwt.user.client.ui.Label) ArrayList(java.util.ArrayList) GuidedDecisionTableAccordionItem(org.drools.workbench.screens.guided.dtable.client.editor.page.accordion.GuidedDecisionTableAccordionItem) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) List(java.util.List) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) CompositeColumn(org.drools.workbench.models.guided.dtable.shared.model.CompositeColumn) Test(org.junit.Test)

Example 19 with CompositeColumn

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

the class ColumnsPagePresenterTest method testRefreshConditionsWidgetWhenConditionColumnsIsEmpty.

@Test
public void testRefreshConditionsWidgetWhenConditionColumnsIsEmpty() {
    final List<CompositeColumn<? extends BaseColumn>> conditions = new ArrayList<>();
    final ColumnManagementView columnManagementView = mock(ColumnManagementView.class);
    final GuidedDecisionTableAccordionItem item = mock(GuidedDecisionTableAccordionItem.class);
    final Label blankSlate = mock(Label.class);
    doReturn(verticalPanel).when(presenter).getConditionsWidget();
    doReturn(columnManagementView).when(presenter).getConditionsPanel();
    doReturn(blankSlate).when(presenter).blankSlate();
    doReturn(item).when(accordion).getItem(CONDITION);
    presenter.refreshConditionsWidget(conditions);
    verify(item).setOpen(false);
    verify(verticalPanel).add(blankSlate);
    verify(verticalPanel, never()).add(columnManagementView);
    verify(columnManagementView, never()).renderColumns(any());
}
Also used : ArrayList(java.util.ArrayList) ColumnManagementView(org.drools.workbench.screens.guided.dtable.client.widget.table.columns.control.ColumnManagementView) Label(com.google.gwt.user.client.ui.Label) GuidedDecisionTableAccordionItem(org.drools.workbench.screens.guided.dtable.client.editor.page.accordion.GuidedDecisionTableAccordionItem) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) CompositeColumn(org.drools.workbench.models.guided.dtable.shared.model.CompositeColumn) Test(org.junit.Test)

Example 20 with CompositeColumn

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

the class ValidatorTest method fakeCompositeColumn.

private List<CompositeColumn<? extends BaseColumn>> fakeCompositeColumn(final ConditionCol52... columns) {
    final List<CompositeColumn<? extends BaseColumn>> compositeColumns = new ArrayList<>();
    compositeColumns.add(fakeCompositeColumn(new ArrayList<ConditionCol52>() {

        {
            for (ConditionCol52 column : columns) {
                add(column);
            }
        }
    }));
    return compositeColumns;
}
Also used : ConditionCol52(org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52) ArrayList(java.util.ArrayList) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) CompositeColumn(org.drools.workbench.models.guided.dtable.shared.model.CompositeColumn)

Aggregations

CompositeColumn (org.drools.workbench.models.guided.dtable.shared.model.CompositeColumn)22 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)20 ArrayList (java.util.ArrayList)17 Test (org.junit.Test)17 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)12 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)12 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)11 GuidedDTTemplateDataProvider (org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider)11 TemplateDataProvider (org.drools.workbench.models.guided.dtable.backend.util.TemplateDataProvider)11 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)11 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)11 LimitedEntryConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.LimitedEntryConditionCol52)11 RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)11 List (java.util.List)7 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)5 BaseSingleFieldConstraint (org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint)4 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)4 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)4 MetadataCol52 (org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52)4 ActionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ActionCol52)3