Search in sources :

Example 1 with ColumnAdditionChange

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);
}
Also used : CellAtRow(com.google.refine.model.changes.CellAtRow) ColumnAdditionChange(com.google.refine.model.changes.ColumnAdditionChange) Column(com.google.refine.model.Column) ArrayList(java.util.ArrayList) HistoryEntry(com.google.refine.history.HistoryEntry) Change(com.google.refine.history.Change) ColumnAdditionChange(com.google.refine.model.changes.ColumnAdditionChange) FilteredRows(com.google.refine.browsing.FilteredRows) Engine(com.google.refine.browsing.Engine) JSONException(org.json.JSONException)

Example 2 with ColumnAdditionChange

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());
}
Also used : MassChange(com.google.refine.model.changes.MassChange) ColumnAdditionChange(com.google.refine.model.changes.ColumnAdditionChange) ArrayList(java.util.ArrayList) Change(com.google.refine.history.Change) ColumnAdditionChange(com.google.refine.model.changes.ColumnAdditionChange) MassChange(com.google.refine.model.changes.MassChange) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) RefineTest(com.google.refine.tests.RefineTest)

Aggregations

Change (com.google.refine.history.Change)2 ColumnAdditionChange (com.google.refine.model.changes.ColumnAdditionChange)2 ArrayList (java.util.ArrayList)2 Engine (com.google.refine.browsing.Engine)1 FilteredRows (com.google.refine.browsing.FilteredRows)1 HistoryEntry (com.google.refine.history.HistoryEntry)1 Column (com.google.refine.model.Column)1 CellAtRow (com.google.refine.model.changes.CellAtRow)1 MassChange (com.google.refine.model.changes.MassChange)1 RefineTest (com.google.refine.tests.RefineTest)1 JSONException (org.json.JSONException)1 BeforeTest (org.testng.annotations.BeforeTest)1 Test (org.testng.annotations.Test)1