use of org.drools.workbench.models.guided.dtable.shared.model.BaseColumn in project drools-wb by kiegroup.
the class DependentEnumsUtilities method getCurrentValueMap.
/**
* Create a map of Field Values keyed on Field Names used by
* SuggestionCompletionEngine.getEnums(String, String, Map<String, String>)
* to drive dependent enumerations.
*
* @param context The Context of the cell being edited containing physical
* coordinate in the data-space.
*/
@Override
public Map<String, String> getCurrentValueMap(final Context context) {
Map<String, String> currentValueMap = new HashMap<String, String>();
final int iBaseRowIndex = context.getRowIndex();
final int iBaseColIndex = context.getColumnIndex();
final List<DTCellValue52> rowData = this.model.getData().get(iBaseRowIndex);
// Get the column for the cell being edited
final List<BaseColumn> allColumns = this.model.getExpandedColumns();
final BaseColumn baseColumn = allColumns.get(iBaseColIndex);
// Get values for all Constraints or Actions on the same pattern as the baseColumn
if (baseColumn instanceof BRLConditionVariableColumn) {
final BRLConditionVariableColumn baseBRLConditionColumn = (BRLConditionVariableColumn) baseColumn;
final BRLConditionColumn brl = model.getBRLColumn(baseBRLConditionColumn);
final RuleModel rm = new RuleModel();
IPattern[] lhs = new IPattern[brl.getDefinition().size()];
brl.getDefinition().toArray(lhs);
rm.lhs = lhs;
final RuleModelPeerVariableVisitor peerVariableVisitor = new RuleModelPeerVariableVisitor(rm, baseBRLConditionColumn.getVarName());
List<ValueHolder> peerVariables = peerVariableVisitor.getPeerVariables();
// Add other variables values
for (ValueHolder valueHolder : peerVariables) {
switch(valueHolder.getType()) {
case TEMPLATE_KEY:
final BRLConditionVariableColumn vc = getConditionVariableColumnIndex(brl.getChildColumns(), valueHolder.getValue());
final int iCol = allColumns.indexOf(vc);
final DTCellValue52 dcv = rowData.get(iCol);
final String field = vc.getFactField();
currentValueMap.put(field, cellUtilities.asString(dcv));
break;
case VALUE:
currentValueMap.put(valueHolder.getFieldName(), valueHolder.getValue());
}
}
} else if (baseColumn instanceof BRLActionVariableColumn) {
final BRLActionVariableColumn baseBRLActionColumn = (BRLActionVariableColumn) baseColumn;
final BRLActionColumn brl = model.getBRLColumn(baseBRLActionColumn);
final RuleModel rm = new RuleModel();
IAction[] rhs = new IAction[brl.getDefinition().size()];
brl.getDefinition().toArray(rhs);
rm.rhs = rhs;
final RuleModelPeerVariableVisitor peerVariableVisitor = new RuleModelPeerVariableVisitor(rm, baseBRLActionColumn.getVarName());
List<ValueHolder> peerVariables = peerVariableVisitor.getPeerVariables();
// Add other variables values
for (ValueHolder valueHolder : peerVariables) {
switch(valueHolder.getType()) {
case TEMPLATE_KEY:
final BRLActionVariableColumn vc = getActionVariableColumnIndex(brl.getChildColumns(), valueHolder.getValue());
final int iCol = allColumns.indexOf(vc);
final DTCellValue52 dcv = rowData.get(iCol);
final String field = vc.getFactField();
currentValueMap.put(field, cellUtilities.asString(dcv));
break;
case VALUE:
currentValueMap.put(valueHolder.getFieldName(), valueHolder.getValue());
}
}
} else if (baseColumn instanceof ConditionCol52) {
final ConditionCol52 baseConditionColumn = (ConditionCol52) baseColumn;
final Pattern52 basePattern = this.model.getPattern(baseConditionColumn);
for (ConditionCol52 cc : basePattern.getChildColumns()) {
final int iCol = allColumns.indexOf(cc);
final DTCellValue52 dcv = rowData.get(iCol);
currentValueMap.put(cc.getFactField(), cellUtilities.asString(dcv));
}
} else if (baseColumn instanceof ActionSetFieldCol52) {
ActionSetFieldCol52 baseActionColumn = (ActionSetFieldCol52) baseColumn;
final String binding = baseActionColumn.getBoundName();
for (ActionCol52 ac : this.model.getActionCols()) {
if (ac instanceof ActionSetFieldCol52) {
final ActionSetFieldCol52 asf = (ActionSetFieldCol52) ac;
if (asf.getBoundName().equals(binding)) {
final int iCol = allColumns.indexOf(asf);
final DTCellValue52 dcv = rowData.get(iCol);
currentValueMap.put(asf.getFactField(), cellUtilities.asString(dcv));
}
}
}
} else if (baseColumn instanceof ActionInsertFactCol52) {
ActionInsertFactCol52 baseActionColumn = (ActionInsertFactCol52) baseColumn;
final String binding = baseActionColumn.getBoundName();
for (ActionCol52 ac : this.model.getActionCols()) {
if (ac instanceof ActionInsertFactCol52) {
final ActionInsertFactCol52 aif = (ActionInsertFactCol52) ac;
if (aif.getBoundName().equals(binding)) {
final int iCol = allColumns.indexOf(aif);
final DTCellValue52 dcv = rowData.get(iCol);
currentValueMap.put(aif.getFactField(), cellUtilities.asString(dcv));
}
}
}
}
return currentValueMap;
}
use of org.drools.workbench.models.guided.dtable.shared.model.BaseColumn in project drools-wb by kiegroup.
the class ColumnsPagePresenterTest method testRefreshActionsWidgetWhenActionColumnsIsNotEmpty.
@Test
public void testRefreshActionsWidgetWhenActionColumnsIsNotEmpty() {
final ColumnManagementView columnManagementView = mock(ColumnManagementView.class);
final GuidedDecisionTableAccordionItem item = mock(GuidedDecisionTableAccordionItem.class);
final Label blankSlate = mock(Label.class);
final ActionCol52 actionCol52 = mock(ActionCol52.class);
final List<ActionCol52> actionColumns1 = new ArrayList<ActionCol52>() {
{
add(actionCol52);
}
};
final Map<String, List<BaseColumn>> actionColumns2 = new HashMap<String, List<BaseColumn>>() {
{
put("title", new ArrayList<>());
}
};
doReturn(verticalPanel).when(presenter).getActionsWidget();
doReturn(columnManagementView).when(presenter).getActionsPanel();
doReturn(blankSlate).when(presenter).blankSlate();
doReturn(item).when(accordion).getItem(ACTION);
doReturn(actionColumns2).when(presenter).groupByTitle(actionColumns1);
presenter.refreshActionsWidget(actionColumns1);
verify(item, never()).setOpen(false);
verify(verticalPanel, never()).add(blankSlate);
verify(verticalPanel).add(columnManagementView);
verify(columnManagementView).renderColumns(actionColumns2);
}
use of org.drools.workbench.models.guided.dtable.shared.model.BaseColumn 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);
}
use of org.drools.workbench.models.guided.dtable.shared.model.BaseColumn 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());
}
use of org.drools.workbench.models.guided.dtable.shared.model.BaseColumn in project drools-wb by kiegroup.
the class GuidedDecisionTableGeneratorListenerTest method conditionsTest.
private void conditionsTest(final String xlsFileName, final List<Object[]> expectedRows) {
final ConversionResult result = new ConversionResult();
final List<DataListener> listeners = new ArrayList<DataListener>();
addModelField("org.test.Driver", "this", "org.test.Driver", DataType.TYPE_THIS);
addModelField("org.test.Driver", "age", Integer.class.getName(), DataType.TYPE_NUMERIC_INTEGER);
addModelField("org.test.Driver", "firstName", String.class.getName(), DataType.TYPE_STRING);
addModelField("org.test.Driver", "surname", String.class.getName(), DataType.TYPE_STRING);
addModelField("org.test.Vehicle", "this", "org.test.Vehicle", DataType.TYPE_THIS);
addModelField("org.test.Vehicle", "make", String.class.getName(), DataType.TYPE_STRING);
addModelField("org.test.Vehicle", "model", String.class.getName(), DataType.TYPE_STRING);
final GuidedDecisionTableGeneratorListener listener = new GuidedDecisionTableGeneratorListener(result, dmo);
listeners.add(listener);
// Convert
final ExcelParser parser = new ExcelParser(listeners);
final InputStream is = this.getClass().getResourceAsStream(xlsFileName);
try {
parser.parseFile(is);
} finally {
try {
is.close();
} catch (IOException ioe) {
fail(ioe.getMessage());
}
}
// Check conversion results
assertEquals(0, result.getMessages().size());
// Check basics
List<GuidedDecisionTable52> dtables = listener.getGuidedDecisionTables();
assertNotNull(dtables);
assertEquals(1, dtables.size());
GuidedDecisionTable52 dtable = dtables.get(0);
assertEquals("ConditionsTest", 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 RuleNameColumn);
assertTrue(columns.get(2) instanceof DescriptionCol52);
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);
// Check individual condition columns
assertEquals(2, dtable.getConditions().size());
assertTrue(dtable.getConditions().get(0) instanceof BRLConditionColumn);
assertTrue(dtable.getConditions().get(1) instanceof BRLConditionColumn);
// Column 1
BRLConditionColumn conditionCol0 = ((BRLConditionColumn) dtable.getConditions().get(0));
assertEquals("Converted from ['Age of driver', 'First name', 'Surname']", conditionCol0.getHeader());
assertEquals(3, 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("Driver", conditionCol0fp.getFactType());
assertEquals(3, conditionCol0fp.getNumberOfConstraints());
assertTrue(conditionCol0fp.getConstraint(0) instanceof SingleFieldConstraint);
final SingleFieldConstraint conditionCol0fpsfc0 = (SingleFieldConstraint) conditionCol0fp.getConstraint(0);
assertEquals("age", conditionCol0fpsfc0.getFieldName());
assertEquals(">", conditionCol0fpsfc0.getOperator());
assertEquals("param1", conditionCol0fpsfc0.getValue());
assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0fpsfc0.getConstraintValueType());
assertEquals(DataType.TYPE_NUMERIC_INTEGER, conditionCol0fpsfc0.getFieldType());
assertTrue(conditionCol0fp.getConstraint(1) instanceof SingleFieldConstraint);
final SingleFieldConstraint conditionCol0fpsfc1 = (SingleFieldConstraint) conditionCol0fp.getConstraint(1);
assertEquals("firstName", conditionCol0fpsfc1.getFieldName());
assertEquals("==", conditionCol0fpsfc1.getOperator());
assertEquals("param2", conditionCol0fpsfc1.getValue());
assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0fpsfc1.getConstraintValueType());
assertEquals(DataType.TYPE_STRING, conditionCol0fpsfc1.getFieldType());
assertTrue(conditionCol0fp.getConstraint(2) instanceof SingleFieldConstraint);
final SingleFieldConstraint conditionCol0fpsfc2 = (SingleFieldConstraint) conditionCol0fp.getConstraint(2);
assertEquals("surname", conditionCol0fpsfc2.getFieldName());
assertEquals("==", conditionCol0fpsfc2.getOperator());
assertEquals("param3", conditionCol0fpsfc2.getValue());
assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol0fpsfc2.getConstraintValueType());
assertEquals(DataType.TYPE_STRING, conditionCol0fpsfc2.getFieldType());
// Column 1 - Variable 1
BRLConditionVariableColumn conditionCol0param0 = conditionCol0.getChildColumns().get(0);
assertEquals("param1", conditionCol0param0.getVarName());
assertEquals("Age of driver", conditionCol0param0.getHeader());
assertEquals(DataType.TYPE_NUMERIC_INTEGER, conditionCol0param0.getFieldType());
assertEquals("Driver", conditionCol0param0.getFactType());
assertEquals("age", conditionCol0param0.getFactField());
// Column 1 - Variable 2
BRLConditionVariableColumn conditionCol0param1 = conditionCol0.getChildColumns().get(1);
assertEquals("param2", conditionCol0param1.getVarName());
assertEquals("First name", conditionCol0param1.getHeader());
assertEquals(DataType.TYPE_STRING, conditionCol0param1.getFieldType());
assertEquals("Driver", conditionCol0param1.getFactType());
assertEquals("firstName", conditionCol0param1.getFactField());
// Column 1 - Variable 3
BRLConditionVariableColumn conditionCol0param2 = conditionCol0.getChildColumns().get(2);
assertEquals("param3", conditionCol0param2.getVarName());
assertEquals("Surname", conditionCol0param2.getHeader());
assertEquals(DataType.TYPE_STRING, conditionCol0param2.getFieldType());
assertEquals("Driver", conditionCol0param2.getFactType());
assertEquals("surname", conditionCol0param2.getFactField());
// Column 2
BRLConditionColumn conditionCol1 = ((BRLConditionColumn) dtable.getConditions().get(1));
assertEquals("Converted from ['something', 'something']", conditionCol1.getHeader());
assertEquals(2, 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("Vehicle", conditionCol1fp.getFactType());
assertEquals(2, conditionCol1fp.getNumberOfConstraints());
assertTrue(conditionCol1fp.getConstraint(0) instanceof SingleFieldConstraint);
final SingleFieldConstraint conditionCol1fpsfc0 = (SingleFieldConstraint) conditionCol1fp.getConstraint(0);
assertEquals("make", conditionCol1fpsfc0.getFieldName());
assertEquals("==", conditionCol1fpsfc0.getOperator());
assertEquals("param4", conditionCol1fpsfc0.getValue());
assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol1fpsfc0.getConstraintValueType());
assertEquals(DataType.TYPE_STRING, conditionCol1fpsfc0.getFieldType());
assertTrue(conditionCol1fp.getConstraint(1) instanceof SingleFieldConstraint);
final SingleFieldConstraint conditionCol1fpsfc1 = (SingleFieldConstraint) conditionCol1fp.getConstraint(1);
assertEquals("model", conditionCol1fpsfc1.getFieldName());
assertEquals("==", conditionCol1fpsfc1.getOperator());
assertEquals("param5", conditionCol1fpsfc1.getValue());
assertEquals(SingleFieldConstraint.TYPE_TEMPLATE, conditionCol1fpsfc1.getConstraintValueType());
assertEquals(DataType.TYPE_STRING, conditionCol1fpsfc1.getFieldType());
// Column 2 - Variable 1
BRLConditionVariableColumn conditionCol1param0 = conditionCol1.getChildColumns().get(0);
assertEquals("param4", conditionCol1param0.getVarName());
assertEquals("something", conditionCol1param0.getHeader());
assertEquals(DataType.TYPE_STRING, conditionCol1param0.getFieldType());
assertEquals("Vehicle", conditionCol1param0.getFactType());
assertEquals("make", conditionCol1param0.getFactField());
// Column 2 - Variable 2
BRLConditionVariableColumn conditionCol1param1 = conditionCol1.getChildColumns().get(1);
assertEquals("param5", conditionCol1param1.getVarName());
assertEquals("something", conditionCol1param1.getHeader());
assertEquals(DataType.TYPE_STRING, conditionCol1param1.getFieldType());
assertEquals("Vehicle", conditionCol1param1.getFactType());
assertEquals("model", conditionCol1param1.getFactField());
// Check data
assertEquals(2, dtable.getData().size());
assertNotNull(expectedRows);
assertTrue(expectedRows.size() == 2);
for (int i = 0; i < 2; i++) {
assertTrue(isRowEquivalent(expectedRows.get(i), dtable.getData().get(i)));
}
}
Aggregations