use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn in project drools-wb by kiegroup.
the class BRLConditionColumnSynchronizer method update.
@Override
public List<BaseColumnFieldDiff> update(final ColumnMetaData originalMetaData, final ColumnMetaData editedMetaData) throws VetoException {
// Check operation is supported
if (!(handlesUpdate(originalMetaData) && handlesUpdate(editedMetaData))) {
return Collections.emptyList();
}
// Check whether any discarded bindings were used. If so veto the update.
final BRLConditionColumn originalColumn = (BRLConditionColumn) originalMetaData.getColumn();
final BRLConditionColumn editedColumn = (BRLConditionColumn) editedMetaData.getColumn();
final Set<String> originalBindings = getPatternBindings(originalColumn);
final Set<String> editedBindings = getPatternBindings(editedColumn);
originalBindings.removeAll(editedBindings);
for (String binding : originalBindings) {
if (rm.isBoundFactUsed(binding)) {
throw new VetoUpdatePatternInUseException();
}
}
final List<BaseColumnFieldDiff> diffs = originalColumn.diff(editedColumn);
// Copy existing data for re-use if applicable
final Map<String, List<DTCellValue52>> originalColumnsData = new HashMap<>();
for (BRLConditionVariableColumn variable : originalColumn.getChildColumns()) {
int iColumnIndex = model.getExpandedColumns().indexOf(variable);
final List<DTCellValue52> originalColumnData = new ArrayList<>();
final String key = makeUpdateBRLConditionColumnKey(variable);
for (List<DTCellValue52> row : model.getData()) {
originalColumnData.add(row.get(iColumnIndex));
}
originalColumnsData.put(key, originalColumnData);
}
// Insert new columns setting data from that above, if applicable. Column visibility is handled here too.
model.getConditions().add(model.getConditions().indexOf(originalColumn), editedColumn);
for (BRLConditionVariableColumn childModelColumn : editedColumn.getChildColumns()) {
final String key = makeUpdateBRLConditionColumnKey(childModelColumn);
if (originalColumnsData.containsKey(key)) {
final List<DTCellValue52> originalColumnData = originalColumnsData.get(key);
synchroniseAppendColumn(childModelColumn, originalColumnData);
} else {
synchroniseAppendColumn(childModelColumn);
}
}
// Delete columns for the original definition
doDelete(originalColumn);
// Signal patterns changed event to Decision Table Widget
final BoundFactsChangedEvent pce = new BoundFactsChangedEvent(rm.getLHSBoundFacts());
eventBus.fireEvent(pce);
return diffs;
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn in project drools-wb by kiegroup.
the class BRLConditionColumnSynchronizer method append.
@Override
public void append(final ColumnMetaData metaData) throws VetoException {
// Check operation is supported
if (!handlesAppend(metaData)) {
return;
}
final BRLConditionColumn column = (BRLConditionColumn) metaData.getColumn();
model.getConditions().add(column);
for (BRLConditionVariableColumn childModelColumn : column.getChildColumns()) {
synchroniseAppendColumn(childModelColumn);
}
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn in project drools-wb by kiegroup.
the class BRLConditionColumnSynchronizer method isBRLFragment.
private boolean isBRLFragment(final List<? extends MetaData> metaData) {
if (!metaData.stream().allMatch((c) -> (c instanceof MoveColumnToMetaData))) {
return false;
}
if (!metaData.stream().allMatch((c) -> ((MoveColumnToMetaData) c).getColumn() instanceof BRLConditionVariableColumn)) {
return false;
}
final MoveColumnToMetaData md = (MoveColumnToMetaData) metaData.get(0);
final BRLConditionVariableColumn srcModelColumn = (BRLConditionVariableColumn) md.getColumn();
final BRLConditionColumn srcModelPattern = model.getBRLColumn(srcModelColumn);
return srcModelPattern.getChildColumns().size() == metaData.size();
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn in project drools-wb by kiegroup.
the class BRLConditionColumnSynchronizer method delete.
@Override
public void delete(final ColumnMetaData metaData) throws VetoException {
// Check operation is supported
if (!handlesDelete(metaData)) {
return;
}
final BRLConditionColumn column = (BRLConditionColumn) metaData.getColumn();
// If Pattern has been updated and there was only one child column then original Pattern will be deleted
final Set<String> bindings = getPatternBindings(column);
for (String binding : bindings) {
if (rm.isBoundFactUsed(binding)) {
throw new VetoDeletePatternInUseException();
}
}
doDelete(column);
}
use of org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn in project drools-wb by kiegroup.
the class BRLConditionColumnSynchronizerTest method testAppend2.
@Test
public void testAppend2() throws VetoException {
// Single Column, multiple variables
final BRLConditionColumn column = new BRLConditionColumn();
final BRLConditionVariableColumn columnV0 = new BRLConditionVariableColumn("$age", DataType.TYPE_NUMERIC_INTEGER, "Applicant", "age");
final BRLConditionVariableColumn columnV1 = new BRLConditionVariableColumn("$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(4, model.getExpandedColumns().size());
assertEquals(1, model.getConditions().size());
assertEquals(4, uiModel.getColumns().size());
assertTrue(uiModel.getColumns().get(2) instanceof IntegerUiColumn);
assertTrue(uiModel.getColumns().get(3) instanceof StringUiColumn);
assertEquals(2, uiModel.getColumns().get(2).getHeaderMetaData().size());
assertEquals("$age", uiModel.getColumns().get(2).getHeaderMetaData().get(1).getTitle());
assertEquals(2, uiModel.getColumns().get(3).getHeaderMetaData().size());
assertEquals("$name", uiModel.getColumns().get(3).getHeaderMetaData().get(1).getTitle());
}
Aggregations