Search in sources :

Example 56 with RowNumberCol52

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

the class GuidedDTDRLPersistenceTest method testMetaData.

@Test
public void testMetaData() {
    GuidedDTDRLPersistence p = new GuidedDTDRLPersistence();
    String[] row = new String[] { "1", "desc", "bar", "" };
    List<BaseColumn> allColumns = new ArrayList<BaseColumn>();
    allColumns.add(new RowNumberCol52());
    allColumns.add(new DescriptionCol52());
    List<MetadataCol52> metadataCols = new ArrayList<MetadataCol52>();
    RuleModel rm = new RuleModel();
    RuleMetadata[] orig = rm.metadataList;
    // RuleAttribute[] orig = rm.attributes;
    p.doMetadata(allColumns, metadataCols, DataUtilities.makeDataRowList(row), rm);
    assertSame(orig, rm.metadataList);
    MetadataCol52 col1 = new MetadataCol52();
    col1.setMetadata("foo");
    MetadataCol52 col2 = new MetadataCol52();
    col2.setMetadata("foo2");
    metadataCols.add(col1);
    metadataCols.add(col2);
    allColumns.addAll(metadataCols);
    p.doMetadata(allColumns, metadataCols, DataUtilities.makeDataRowList(row), rm);
    assertEquals(1, rm.metadataList.length);
    assertEquals("foo", rm.metadataList[0].getAttributeName());
    assertEquals("bar", rm.metadataList[0].getValue());
    row = new String[] { "1", "desc", "bar1", "bar2" };
    p.doMetadata(allColumns, metadataCols, DataUtilities.makeDataRowList(row), rm);
    assertEquals(2, rm.metadataList.length);
    assertEquals("foo", rm.metadataList[0].getAttributeName());
    assertEquals("bar1", rm.metadataList[0].getValue());
    assertEquals("foo2", rm.metadataList[1].getAttributeName());
    assertEquals("bar2", rm.metadataList[1].getValue());
}
Also used : ArrayList(java.util.ArrayList) RuleModel(org.drools.workbench.models.datamodel.rule.RuleModel) MetadataCol52(org.drools.workbench.models.guided.dtable.shared.model.MetadataCol52) DescriptionCol52(org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52) BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) RuleMetadata(org.drools.workbench.models.datamodel.rule.RuleMetadata) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 57 with RowNumberCol52

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

the class GuidedDTDRLPersistenceTest method testLHSWithBRLColumn_ParseToDRL.

@Test
public // This test checks a Decision Table involving BRL columns is correctly converted into DRL
void testLHSWithBRLColumn_ParseToDRL() {
    GuidedDecisionTable52 dtable = new GuidedDecisionTable52();
    // All 3 rows should render, as the code is now lower down for skipping columns with empty cells
    String[][] data = new String[][] { new String[] { "1", "desc", "Gargamel", "Pupa", "50" }, new String[] { "2", "desc", "Gargamel", "", "50" }, new String[] { "3", "desc", "Gargamel", "Pupa", "" } };
    // Simple (mandatory) columns
    dtable.setRowNumberCol(new RowNumberCol52());
    dtable.setDescriptionCol(new DescriptionCol52());
    // Simple Condition
    Pattern52 p1 = new Pattern52();
    p1.setFactType("Baddie");
    ConditionCol52 con = new ConditionCol52();
    con.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    con.setFactField("name");
    con.setOperator("==");
    p1.getChildColumns().add(con);
    dtable.getConditions().add(p1);
    // BRL Column
    BRLConditionColumn brl1 = new BRLConditionColumn();
    // BRL Column definition
    List<IPattern> brl1Definition = new ArrayList<IPattern>();
    FactPattern brl1DefinitionFactPattern1 = new FactPattern("Smurf");
    SingleFieldConstraint brl1DefinitionFactPattern1Constraint1 = new SingleFieldConstraint();
    brl1DefinitionFactPattern1Constraint1.setFieldType(DataType.TYPE_STRING);
    brl1DefinitionFactPattern1Constraint1.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    brl1DefinitionFactPattern1Constraint1.setFieldName("name");
    brl1DefinitionFactPattern1Constraint1.setOperator("==");
    brl1DefinitionFactPattern1Constraint1.setValue("$name");
    brl1DefinitionFactPattern1.addConstraint(brl1DefinitionFactPattern1Constraint1);
    SingleFieldConstraint brl1DefinitionFactPattern1Constraint2 = new SingleFieldConstraint();
    brl1DefinitionFactPattern1Constraint2.setFieldType(DataType.TYPE_NUMERIC_INTEGER);
    brl1DefinitionFactPattern1Constraint2.setConstraintValueType(SingleFieldConstraint.TYPE_TEMPLATE);
    brl1DefinitionFactPattern1Constraint2.setFieldName("age");
    brl1DefinitionFactPattern1Constraint2.setOperator("==");
    brl1DefinitionFactPattern1Constraint2.setValue("$age");
    brl1DefinitionFactPattern1.addConstraint(brl1DefinitionFactPattern1Constraint2);
    brl1Definition.add(brl1DefinitionFactPattern1);
    brl1.setDefinition(brl1Definition);
    // Setup BRL column bindings
    BRLConditionVariableColumn brl1Variable1 = new BRLConditionVariableColumn("$name", DataType.TYPE_STRING, "Person", "name");
    brl1.getChildColumns().add(brl1Variable1);
    BRLConditionVariableColumn brl1Variable2 = new BRLConditionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Person", "age");
    brl1.getChildColumns().add(brl1Variable2);
    dtable.getConditions().add(brl1);
    dtable.setData(DataUtilities.makeDataLists(data));
    // Now to test conversion
    int ruleStartIndex;
    int pattern1StartIndex;
    int pattern2StartIndex;
    GuidedDTDRLPersistence p = GuidedDTDRLPersistence.getInstance();
    String drl = p.marshal(dtable);
    System.out.println(drl);
    // Row 0
    ruleStartIndex = drl.indexOf("//from row number: 1");
    assertFalse(ruleStartIndex == -1);
    pattern1StartIndex = drl.indexOf("Baddie( name == \"Gargamel\" )", ruleStartIndex);
    assertFalse(pattern1StartIndex == -1);
    pattern2StartIndex = drl.indexOf("Smurf( name == \"Pupa\" , age == 50 )", ruleStartIndex);
    assertFalse(pattern2StartIndex == -1);
    // Row 1
    ruleStartIndex = drl.indexOf("//from row number: 2");
    assertFalse(ruleStartIndex == -1);
    pattern1StartIndex = drl.indexOf("Baddie( name == \"Gargamel\" )", ruleStartIndex);
    assertFalse(pattern1StartIndex == -1);
    pattern2StartIndex = drl.indexOf("Smurf( age == 50 )", ruleStartIndex);
    assertFalse(pattern2StartIndex == -1);
    // Row 2
    ruleStartIndex = drl.indexOf("//from row number: 3");
    assertFalse(ruleStartIndex == -1);
    pattern1StartIndex = drl.indexOf("Baddie( name == \"Gargamel\" )", ruleStartIndex);
    assertFalse(pattern1StartIndex == -1);
    pattern2StartIndex = drl.indexOf("Smurf( name == \"Pupa\" )", ruleStartIndex);
    assertFalse(pattern2StartIndex == -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) ArrayList(java.util.ArrayList) 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) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) SingleFieldConstraint(org.drools.workbench.models.datamodel.rule.SingleFieldConstraint) BaseSingleFieldConstraint(org.drools.workbench.models.datamodel.rule.BaseSingleFieldConstraint) 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) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Example 58 with RowNumberCol52

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

the class GuidedDecisionTableSourceServiceTest method setUp.

@Before
public void setUp() throws Exception {
    service = new GuidedDecisionTableSourceService(resourceTypeDefinition, guidedDecisionTableEditorService, ioService, fileDiscoveryService, moduleService);
    // Simulates that no DSL files are present
    when(moduleService.resolvePackage(any())).thenReturn(packageMock);
    when(discoveryService.discoverFiles(any(), any())).thenReturn(new ArrayList<Path>());
    when(fileSystem.supportedFileAttributeViews()).thenReturn(new HashSet<String>());
    when(path.getFileSystem()).thenReturn(fileSystem);
    when(path.toString()).thenReturn("/");
    when(path.getFileName()).thenReturn(path);
    when(path.toUri()).thenReturn(new URI("/"));
    model = new GuidedDecisionTable52();
    model.setPackageName("com.sample");
    model.setImports(new Imports(Arrays.asList(new Import("com.sample.Person"))));
    model.setRowNumberCol(new RowNumberCol52());
    model.setDescriptionCol(new DescriptionCol52());
    pattern = new Pattern52();
    pattern.setBoundName("$p");
    pattern.setFactType("Person");
    nameEqualToLiteralCondition = new ConditionCol52();
    nameEqualToLiteralCondition.setConstraintValueType(BaseSingleFieldConstraint.TYPE_LITERAL);
    nameEqualToLiteralCondition.setHeader("name equals to");
    nameEqualToLiteralCondition.setFactField("name");
    nameEqualToLiteralCondition.setOperator("==");
    pattern.setChildColumns(Arrays.asList(nameEqualToLiteralCondition));
    model.setConditionPatterns(Arrays.asList(pattern));
    data = new ArrayList<>();
}
Also used : Path(org.uberfire.java.nio.file.Path) GuidedDecisionTable52(org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52) Import(org.kie.soup.project.datamodel.imports.Import) Imports(org.kie.soup.project.datamodel.imports.Imports) URI(java.net.URI) 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) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Before(org.junit.Before)

Example 59 with RowNumberCol52

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

the class RowSynchronizer method initialiseRowData.

private void initialiseRowData(final int rowIndex) {
    final List<BaseColumn> modelColumns = model.getExpandedColumns();
    final List<DTCellValue52> modelRow = model.getData().get(rowIndex);
    for (int columnIndex = 0; columnIndex < modelColumns.size(); columnIndex++) {
        final BaseColumn modelColumn = modelColumns.get(columnIndex);
        final DTCellValue52 modelCell = makeModelCellValue(modelColumn);
        modelRow.add(modelCell);
        // BaseGridData is sparsely populated; only add values if needed.
        if (modelCell.hasValue()) {
            uiModel.setCellValueInternal(rowIndex, columnIndex, gridWidgetCellFactory.convertCell(modelCell, modelColumn, cellUtilities, columnUtilities));
        }
        uiModel.indexColumn(columnIndex);
        // Set-up SelectionManager for Row Number column, to select entire row.
        if (modelColumn instanceof RowNumberCol52) {
            uiModel.getCell(rowIndex, columnIndex).setSelectionStrategy(RowSelectionStrategy.INSTANCE);
        }
    }
}
Also used : BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) DTCellValue52(org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)

Example 60 with RowNumberCol52

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

the class GridWidgetColumnFactoryImplTest method columnResizingListenerSetup_RowNumberColumn.

@Test
public void columnResizingListenerSetup_RowNumberColumn() {
    final BaseColumn column = new RowNumberCol52();
    final GridColumn<?> uiColumn = factory.convertColumn(column, access, gridWidget);
    assertFalse(uiColumn instanceof BaseUiColumn);
    assertEquals((int) uiColumn.getWidth(), column.getWidth());
    assertEquals(50.0, column.getWidth(), 0.0);
}
Also used : BaseColumn(org.drools.workbench.models.guided.dtable.shared.model.BaseColumn) BaseUiColumn(org.drools.workbench.screens.guided.dtable.client.widget.table.columns.BaseUiColumn) RowNumberCol52(org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52) Test(org.junit.Test)

Aggregations

RowNumberCol52 (org.drools.workbench.models.guided.dtable.shared.model.RowNumberCol52)82 Test (org.junit.Test)70 DescriptionCol52 (org.drools.workbench.models.guided.dtable.shared.model.DescriptionCol52)66 BaseColumn (org.drools.workbench.models.guided.dtable.shared.model.BaseColumn)57 ArrayList (java.util.ArrayList)47 GuidedDecisionTable52 (org.drools.workbench.models.guided.dtable.shared.model.GuidedDecisionTable52)33 SingleFieldConstraint (org.drools.workbench.models.datamodel.rule.SingleFieldConstraint)24 BRLConditionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn)23 ConditionCol52 (org.drools.workbench.models.guided.dtable.shared.model.ConditionCol52)23 DTCellValue52 (org.drools.workbench.models.guided.dtable.shared.model.DTCellValue52)23 FactPattern (org.drools.workbench.models.datamodel.rule.FactPattern)22 BRLConditionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn)22 RuleModel (org.drools.workbench.models.datamodel.rule.RuleModel)21 Pattern52 (org.drools.workbench.models.guided.dtable.shared.model.Pattern52)21 GuidedDTTemplateDataProvider (org.drools.workbench.models.guided.dtable.backend.util.GuidedDTTemplateDataProvider)19 TemplateDataProvider (org.drools.workbench.models.guided.dtable.backend.util.TemplateDataProvider)19 BRLActionColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionColumn)19 BRLActionVariableColumn (org.drools.workbench.models.guided.dtable.shared.model.BRLActionVariableColumn)18 IOException (java.io.IOException)17 InputStream (java.io.InputStream)17