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());
}
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);
}
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<>();
}
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);
}
}
}
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);
}
Aggregations