use of com.google.refine.model.changes.ColumnAdditionChange in project OpenRefine by OpenRefine.
the class ColumnAdditionOperation method createHistoryEntry.
@Override
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
Engine engine = createEngine(project);
Column column = project.columnModel.getColumnByName(_baseColumnName);
if (column == null) {
throw new Exception("No column named " + _baseColumnName);
}
if (project.columnModel.getColumnByName(_newColumnName) != null) {
throw new Exception("Another column already named " + _newColumnName);
}
List<CellAtRow> cellsAtRows = new ArrayList<CellAtRow>(project.rows.size());
FilteredRows filteredRows = engine.getAllFilteredRows();
filteredRows.accept(project, createRowVisitor(project, cellsAtRows));
String description = createDescription(column, cellsAtRows);
Change change = new ColumnAdditionChange(_newColumnName, _columnInsertIndex, cellsAtRows);
return new HistoryEntry(historyEntryID, project, description, this, change);
}
use of com.google.refine.model.changes.ColumnAdditionChange in project OpenRefine by OpenRefine.
the class MassChangeTests method testWrongReverseOrder.
/**
* Test case for #914 - Demonstrates MassChange revert doesn't work by
* adding two columns to a project with a MassChange and then reverting.
* Without the fix, column "a" will be removed before column "b", causing
* column "b" removal to fail because it won't be found at index 1 as
* expected.
*/
@Test
public void testWrongReverseOrder() throws Exception {
List<Change> changes = new ArrayList<Change>();
changes.add(new ColumnAdditionChange("a", 0, new ArrayList<CellAtRow>()));
changes.add(new ColumnAdditionChange("b", 1, new ArrayList<CellAtRow>()));
MassChange massChange = new MassChange(changes, false);
massChange.apply(project);
massChange.revert(project);
assertTrue(project.columnModel.columns.isEmpty());
}
Aggregations