diff --git a/src/main/java/com/metaweb/gridworks/commands/edit/AddColumnCommand.java b/src/main/java/com/metaweb/gridworks/commands/edit/AddColumnCommand.java index 793f7f3a9..018871dc3 100644 --- a/src/main/java/com/metaweb/gridworks/commands/edit/AddColumnCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/edit/AddColumnCommand.java @@ -13,14 +13,14 @@ public class AddColumnCommand extends EngineDependentCommand { protected AbstractOperation createOperation(HttpServletRequest request, JSONObject engineConfig) throws Exception { - int baseCellIndex = Integer.parseInt(request.getParameter("baseCellIndex")); + String baseColumnName = request.getParameter("baseColumnName"); String expression = request.getParameter("expression"); String headerLabel = request.getParameter("headerLabel"); int columnInsertIndex = Integer.parseInt(request.getParameter("columnInsertIndex")); return new ColumnAdditionOperation( engineConfig, - baseCellIndex, + baseColumnName, expression, headerLabel, columnInsertIndex diff --git a/src/main/java/com/metaweb/gridworks/commands/edit/DoTextTransformCommand.java b/src/main/java/com/metaweb/gridworks/commands/edit/DoTextTransformCommand.java index 1b6e75bf2..e48aad9f3 100644 --- a/src/main/java/com/metaweb/gridworks/commands/edit/DoTextTransformCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/edit/DoTextTransformCommand.java @@ -14,9 +14,9 @@ public class DoTextTransformCommand extends EngineDependentCommand { protected AbstractOperation createOperation(HttpServletRequest request, JSONObject engineConfig) throws Exception { - int cellIndex = Integer.parseInt(request.getParameter("cell")); + String columnName = request.getParameter("columnName"); String expression = request.getParameter("expression"); - return new TextTransformOperation(engineConfig, cellIndex, expression); + return new TextTransformOperation(engineConfig, columnName, expression); } } diff --git a/src/main/java/com/metaweb/gridworks/commands/edit/JoinMultiValueCellsCommand.java b/src/main/java/com/metaweb/gridworks/commands/edit/JoinMultiValueCellsCommand.java index d9c1ade51..7489a8398 100644 --- a/src/main/java/com/metaweb/gridworks/commands/edit/JoinMultiValueCellsCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/edit/JoinMultiValueCellsCommand.java @@ -21,11 +21,11 @@ public class JoinMultiValueCellsCommand extends Command { try { Project project = getProject(request); - int cellIndex = Integer.parseInt(request.getParameter("cellIndex")); - int keyCellIndex = Integer.parseInt(request.getParameter("keyCellIndex")); + String columnName = request.getParameter("columnName"); + String keyColumnName = request.getParameter("keyColumnName"); String separator = request.getParameter("separator"); - AbstractOperation op = new MultiValueCellJoinOperation(cellIndex, keyCellIndex, separator); + AbstractOperation op = new MultiValueCellJoinOperation(columnName, keyColumnName, separator); Process process = op.createProcess(project, new Properties()); boolean done = project.processManager.queueProcess(process); diff --git a/src/main/java/com/metaweb/gridworks/commands/edit/RemoveColumnCommand.java b/src/main/java/com/metaweb/gridworks/commands/edit/RemoveColumnCommand.java index 1948e6fff..a87fef71c 100644 --- a/src/main/java/com/metaweb/gridworks/commands/edit/RemoveColumnCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/edit/RemoveColumnCommand.java @@ -21,9 +21,9 @@ public class RemoveColumnCommand extends Command { try { Project project = getProject(request); - int columnRemovalIndex = Integer.parseInt(request.getParameter("columnRemovalIndex")); + String columnName = request.getParameter("columnName"); - AbstractOperation op = new ColumnRemovalOperation(columnRemovalIndex); + AbstractOperation op = new ColumnRemovalOperation(columnName); Process process = op.createProcess(project, new Properties()); boolean done = project.processManager.queueProcess(process); diff --git a/src/main/java/com/metaweb/gridworks/commands/edit/SplitMultiValueCellsCommand.java b/src/main/java/com/metaweb/gridworks/commands/edit/SplitMultiValueCellsCommand.java index d6ece527d..0f14f33ee 100644 --- a/src/main/java/com/metaweb/gridworks/commands/edit/SplitMultiValueCellsCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/edit/SplitMultiValueCellsCommand.java @@ -21,12 +21,12 @@ public class SplitMultiValueCellsCommand extends Command { try { Project project = getProject(request); - int cellIndex = Integer.parseInt(request.getParameter("cellIndex")); - int keyCellIndex = Integer.parseInt(request.getParameter("keyCellIndex")); + String columnName = request.getParameter("columnName"); + String keyColumnName = request.getParameter("keyColumnName"); String separator = request.getParameter("separator"); String mode = request.getParameter("mode"); - AbstractOperation op = new MultiValueCellSplitOperation(cellIndex, keyCellIndex, separator, mode); + AbstractOperation op = new MultiValueCellSplitOperation(columnName, keyColumnName, separator, mode); Process process = op.createProcess(project, new Properties()); boolean done = project.processManager.queueProcess(process); diff --git a/src/main/java/com/metaweb/gridworks/commands/recon/ApproveNewReconcileCommand.java b/src/main/java/com/metaweb/gridworks/commands/recon/ApproveNewReconcileCommand.java index 7ed058c26..80dc0bee6 100644 --- a/src/main/java/com/metaweb/gridworks/commands/recon/ApproveNewReconcileCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/recon/ApproveNewReconcileCommand.java @@ -14,8 +14,8 @@ public class ApproveNewReconcileCommand extends EngineDependentCommand { protected AbstractOperation createOperation(HttpServletRequest request, JSONObject engineConfig) throws Exception { - int cellIndex = Integer.parseInt(request.getParameter("cell")); + String columnName = request.getParameter("columnName"); - return new ApproveNewReconOperation(engineConfig, cellIndex); + return new ApproveNewReconOperation(engineConfig, columnName); } } diff --git a/src/main/java/com/metaweb/gridworks/commands/recon/ApproveReconcileCommand.java b/src/main/java/com/metaweb/gridworks/commands/recon/ApproveReconcileCommand.java index 41145278e..9c0c6f62f 100644 --- a/src/main/java/com/metaweb/gridworks/commands/recon/ApproveReconcileCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/recon/ApproveReconcileCommand.java @@ -14,8 +14,8 @@ public class ApproveReconcileCommand extends EngineDependentCommand { protected AbstractOperation createOperation(HttpServletRequest request, JSONObject engineConfig) throws Exception { - int cellIndex = Integer.parseInt(request.getParameter("cell")); + String columnName = request.getParameter("columnName"); - return new ApproveReconOperation(engineConfig, cellIndex); + return new ApproveReconOperation(engineConfig, columnName); } } diff --git a/src/main/java/com/metaweb/gridworks/commands/recon/DiscardReconcileCommand.java b/src/main/java/com/metaweb/gridworks/commands/recon/DiscardReconcileCommand.java index c54741c0c..a4a0c7dbf 100644 --- a/src/main/java/com/metaweb/gridworks/commands/recon/DiscardReconcileCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/recon/DiscardReconcileCommand.java @@ -13,8 +13,8 @@ public class DiscardReconcileCommand extends EngineDependentCommand { protected AbstractOperation createOperation(HttpServletRequest request, JSONObject engineConfig) throws Exception { - int cellIndex = Integer.parseInt(request.getParameter("cell")); + String columnName = request.getParameter("columnName"); - return new DiscardReconOperation(engineConfig, cellIndex); + return new DiscardReconOperation(engineConfig, columnName); } } diff --git a/src/main/java/com/metaweb/gridworks/commands/recon/ReconcileCommand.java b/src/main/java/com/metaweb/gridworks/commands/recon/ReconcileCommand.java index c85586e88..c573d990c 100644 --- a/src/main/java/com/metaweb/gridworks/commands/recon/ReconcileCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/recon/ReconcileCommand.java @@ -14,9 +14,9 @@ public class ReconcileCommand extends EngineDependentCommand { protected AbstractOperation createOperation(HttpServletRequest request, JSONObject engineConfig) throws Exception { - int cellIndex = Integer.parseInt(request.getParameter("cell")); + String columnName = request.getParameter("columnName"); String typeID = request.getParameter("type"); - return new ReconOperation(engineConfig, cellIndex, typeID); + return new ReconOperation(engineConfig, columnName, typeID); } } diff --git a/src/main/java/com/metaweb/gridworks/model/ColumnModel.java b/src/main/java/com/metaweb/gridworks/model/ColumnModel.java index 4b6f95201..504be7c50 100644 --- a/src/main/java/com/metaweb/gridworks/model/ColumnModel.java +++ b/src/main/java/com/metaweb/gridworks/model/ColumnModel.java @@ -79,6 +79,7 @@ public class ColumnModel implements Serializable, Jsonizable { writer.endArray(); writer.key("keyCellIndex"); writer.value(getKeyColumnIndex()); + writer.key("keyColumnName"); writer.value(columns.get(_keyColumnIndex).getHeaderLabel()); writer.key("columnGroups"); writer.array(); for (ColumnGroup g : _rootColumnGroups) { diff --git a/src/main/java/com/metaweb/gridworks/model/operations/ApproveNewReconOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/ApproveNewReconOperation.java index 13364807e..c99699bae 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/ApproveNewReconOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/ApproveNewReconOperation.java @@ -19,14 +19,18 @@ import com.metaweb.gridworks.model.changes.CellChange; public class ApproveNewReconOperation extends EngineDependentMassCellOperation { private static final long serialVersionUID = -5205694623711144436L; - public ApproveNewReconOperation(JSONObject engineConfig, int cellIndex) { - super(engineConfig, cellIndex, false); + public ApproveNewReconOperation(JSONObject engineConfig, String columnName) { + super(engineConfig, columnName, false); } public void write(JSONWriter writer, Properties options) throws JSONException { - // TODO Auto-generated method stub + writer.object(); + writer.key("description"); writer.value("Approve new topics in column " + _columnName); + writer.key("engineConfig"); writer.value(_engineConfig); + writer.key("columnName"); writer.value(_columnName); + writer.endObject(); } protected String createDescription(Column column, @@ -37,7 +41,8 @@ public class ApproveNewReconOperation extends EngineDependentMassCellOperation { } protected RowVisitor createRowVisitor(Project project, List cellChanges) throws Exception { - // TODO Auto-generated method stub + Column column = project.columnModel.getColumnByName(_columnName); + return new RowVisitor() { int cellIndex; List cellChanges; @@ -64,6 +69,6 @@ public class ApproveNewReconOperation extends EngineDependentMassCellOperation { } return false; } - }.init(_cellIndex, cellChanges); + }.init(column.getCellIndex(), cellChanges); } } diff --git a/src/main/java/com/metaweb/gridworks/model/operations/ApproveReconOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/ApproveReconOperation.java index 84b207df2..e677860c2 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/ApproveReconOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/ApproveReconOperation.java @@ -18,8 +18,8 @@ import com.metaweb.gridworks.model.changes.CellChange; public class ApproveReconOperation extends EngineDependentMassCellOperation { private static final long serialVersionUID = 5393888241057341155L; - public ApproveReconOperation(JSONObject engineConfig, int cellIndex) { - super(engineConfig, cellIndex, false); + public ApproveReconOperation(JSONObject engineConfig, String columnName) { + super(engineConfig, columnName, false); } public void write(JSONWriter writer, Properties options) @@ -36,7 +36,8 @@ public class ApproveReconOperation extends EngineDependentMassCellOperation { } protected RowVisitor createRowVisitor(Project project, List cellChanges) throws Exception { - // TODO Auto-generated method stub + Column column = project.columnModel.getColumnByName(_columnName); + return new RowVisitor() { int cellIndex; List cellChanges; @@ -64,6 +65,6 @@ public class ApproveReconOperation extends EngineDependentMassCellOperation { } return false; } - }.init(_cellIndex, cellChanges); + }.init(column.getCellIndex(), cellChanges); } } diff --git a/src/main/java/com/metaweb/gridworks/model/operations/ColumnAdditionOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/ColumnAdditionOperation.java index be3772790..bc2659154 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/ColumnAdditionOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/ColumnAdditionOperation.java @@ -28,7 +28,7 @@ import com.metaweb.gridworks.process.QuickHistoryEntryProcess; public class ColumnAdditionOperation extends EngineDependentOperation { private static final long serialVersionUID = -5672677479629932356L; - final protected int _baseCellIndex; + final protected String _baseColumnName; final protected String _expression; final protected String _headerLabel; @@ -36,14 +36,14 @@ public class ColumnAdditionOperation extends EngineDependentOperation { public ColumnAdditionOperation( JSONObject engineConfig, - int baseCellIndex, + String baseColumnName, String expression, String headerLabel, int columnInsertIndex ) { super(engineConfig); - _baseCellIndex = baseCellIndex; + _baseColumnName = baseColumnName; _expression = expression; _headerLabel = headerLabel; @@ -55,9 +55,9 @@ public class ColumnAdditionOperation extends EngineDependentOperation { Engine engine = createEngine(project); - Column column = project.columnModel.getColumnByCellIndex(_baseCellIndex); + Column column = project.columnModel.getColumnByName(_baseColumnName); if (column == null) { - throw new Exception("No column corresponding to cell index " + _baseCellIndex); + throw new Exception("No column named " + _baseColumnName); } List cellsAtRows = new ArrayList(project.rows.size()); @@ -88,6 +88,8 @@ public class ColumnAdditionOperation extends EngineDependentOperation { } protected RowVisitor createRowVisitor(Project project, List cellsAtRows) throws Exception { + Column column = project.columnModel.getColumnByName(_baseColumnName); + Evaluable eval = new Parser(_expression).getExpression(); Properties bindings = ExpressionUtils.createBindings(project); @@ -119,6 +121,6 @@ public class ColumnAdditionOperation extends EngineDependentOperation { return false; } - }.init(_baseCellIndex, bindings, cellsAtRows, eval); + }.init(column.getCellIndex(), bindings, cellsAtRows, eval); } } diff --git a/src/main/java/com/metaweb/gridworks/model/operations/ColumnRemovalOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/ColumnRemovalOperation.java index abda136e6..7439699cd 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/ColumnRemovalOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/ColumnRemovalOperation.java @@ -17,25 +17,25 @@ import com.metaweb.gridworks.process.QuickHistoryEntryProcess; public class ColumnRemovalOperation implements AbstractOperation { private static final long serialVersionUID = 8422079695048733734L; - final protected int _columnRemovalIndex; + final protected String _columnName; public ColumnRemovalOperation( - int columnRemoveIndex + String columnName ) { - _columnRemovalIndex = columnRemoveIndex; + _columnName = columnName; } public Process createProcess(Project project, Properties options) throws Exception { - Column column = project.columnModel.columns.get(_columnRemovalIndex); + Column column = project.columnModel.getColumnByName(_columnName); if (column == null) { - throw new Exception("No column at index " + _columnRemovalIndex); + throw new Exception("No column named " + _columnName); } String description = "Remove column " + column.getHeaderLabel(); - Change change = new ColumnRemovalChange(_columnRemovalIndex); + Change change = new ColumnRemovalChange(project.columnModel.columns.indexOf(column)); HistoryEntry historyEntry = new HistoryEntry( project, description, this, change); diff --git a/src/main/java/com/metaweb/gridworks/model/operations/DiscardReconOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/DiscardReconOperation.java index e3347ecfd..4bb5fd030 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/DiscardReconOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/DiscardReconOperation.java @@ -17,8 +17,8 @@ import com.metaweb.gridworks.model.changes.CellChange; public class DiscardReconOperation extends EngineDependentMassCellOperation { private static final long serialVersionUID = 6799029731665369179L; - public DiscardReconOperation(JSONObject engineConfig, int cellIndex) { - super(engineConfig, cellIndex, false); + public DiscardReconOperation(JSONObject engineConfig, String columnName) { + super(engineConfig, columnName, false); } public void write(JSONWriter writer, Properties options) @@ -35,7 +35,8 @@ public class DiscardReconOperation extends EngineDependentMassCellOperation { } protected RowVisitor createRowVisitor(Project project, List cellChanges) throws Exception { - // TODO Auto-generated method stub + Column column = project.columnModel.getColumnByName(_columnName); + return new RowVisitor() { int cellIndex; List cellChanges; @@ -57,6 +58,6 @@ public class DiscardReconOperation extends EngineDependentMassCellOperation { } return false; } - }.init(_cellIndex, cellChanges); + }.init(column.getCellIndex(), cellChanges); } } diff --git a/src/main/java/com/metaweb/gridworks/model/operations/EngineDependentMassCellOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/EngineDependentMassCellOperation.java index 3a432174b..835472e15 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/EngineDependentMassCellOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/EngineDependentMassCellOperation.java @@ -20,22 +20,22 @@ import com.metaweb.gridworks.process.QuickHistoryEntryProcess; abstract public class EngineDependentMassCellOperation extends EngineDependentOperation { private static final long serialVersionUID = -8962461328087299452L; - final protected int _cellIndex; + final protected String _columnName; final protected boolean _updateRowContextDependencies; protected EngineDependentMassCellOperation( - JSONObject engineConfig, int cellIndex, boolean updateRowContextDependencies) { + JSONObject engineConfig, String columnName, boolean updateRowContextDependencies) { super(engineConfig); - _cellIndex = cellIndex; + _columnName = columnName; _updateRowContextDependencies = updateRowContextDependencies; } public Process createProcess(Project project, Properties options) throws Exception { Engine engine = createEngine(project); - Column column = project.columnModel.getColumnByCellIndex(_cellIndex); + Column column = project.columnModel.getColumnByName(_columnName); if (column == null) { - throw new Exception("No column corresponding to cell index " + _cellIndex); + throw new Exception("No column named " + _columnName); } List cellChanges = new ArrayList(project.rows.size()); @@ -45,7 +45,7 @@ abstract public class EngineDependentMassCellOperation extends EngineDependentOp String description = createDescription(column, cellChanges); - MassCellChange massCellChange = new MassCellChange(cellChanges, _cellIndex, _updateRowContextDependencies); + MassCellChange massCellChange = new MassCellChange(cellChanges, column.getCellIndex(), _updateRowContextDependencies); HistoryEntry historyEntry = new HistoryEntry( project, description, this, massCellChange); diff --git a/src/main/java/com/metaweb/gridworks/model/operations/MultiValueCellJoinOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/MultiValueCellJoinOperation.java index 94bf552e0..7bcb2cd38 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/MultiValueCellJoinOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/MultiValueCellJoinOperation.java @@ -22,27 +22,34 @@ import com.metaweb.gridworks.process.QuickHistoryEntryProcess; public class MultiValueCellJoinOperation implements AbstractOperation { private static final long serialVersionUID = 3134524625206033285L; - final protected int _cellIndex; - final protected int _keyCellIndex; + final protected String _columnName; + final protected String _keyColumnName; final protected String _separator; public MultiValueCellJoinOperation( - int cellIndex, - int keyCellIndex, + String columnName, + String keyColumnName, String separator ) { - _cellIndex = cellIndex; - _keyCellIndex = keyCellIndex; + _columnName = columnName; + _keyColumnName = keyColumnName; _separator = separator; } public Process createProcess(Project project, Properties options) throws Exception { - Column column = project.columnModel.getColumnByCellIndex(_cellIndex); + Column column = project.columnModel.getColumnByName(_columnName); if (column == null) { - throw new Exception("No column corresponding to cell index " + _cellIndex); + throw new Exception("No column named " + _columnName); } + int cellIndex = column.getCellIndex(); + + Column keyColumn = project.columnModel.getColumnByName(_keyColumnName); + if (column == null) { + throw new Exception("No key column named " + _keyColumnName); + } + int keyCellIndex = keyColumn.getCellIndex(); List newRows = new ArrayList(); @@ -50,13 +57,13 @@ public class MultiValueCellJoinOperation implements AbstractOperation { for (int r = 0; r < oldRowCount; r++) { Row oldRow = project.rows.get(r); - if (oldRow.isCellBlank(_keyCellIndex)) { + if (oldRow.isCellBlank(keyCellIndex)) { newRows.add(oldRow.dup()); continue; } int r2 = r + 1; - while (r2 < oldRowCount && project.rows.get(r2).isCellBlank(_keyCellIndex)) { + while (r2 < oldRowCount && project.rows.get(r2).isCellBlank(keyCellIndex)) { r2++; } @@ -67,7 +74,7 @@ public class MultiValueCellJoinOperation implements AbstractOperation { StringBuffer sb = new StringBuffer(); for (int r3 = r; r3 < r2; r3++) { - Object value = project.rows.get(r3).getCellValue(_cellIndex); + Object value = project.rows.get(r3).getCellValue(cellIndex); if (!ExpressionUtils.isBlank(value)) { if (sb.length() > 0) { sb.append(_separator); @@ -79,9 +86,9 @@ public class MultiValueCellJoinOperation implements AbstractOperation { for (int r3 = r; r3 < r2; r3++) { Row newRow = project.rows.get(r3).dup(); if (r3 == r) { - newRow.setCell(_cellIndex, new Cell(sb.toString(), null)); + newRow.setCell(cellIndex, new Cell(sb.toString(), null)); } else { - newRow.setCell(_cellIndex, null); + newRow.setCell(cellIndex, null); } if (!newRow.isEmpty()) { diff --git a/src/main/java/com/metaweb/gridworks/model/operations/MultiValueCellSplitOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/MultiValueCellSplitOperation.java index 1b56046b6..76803dbc8 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/MultiValueCellSplitOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/MultiValueCellSplitOperation.java @@ -22,19 +22,19 @@ import com.metaweb.gridworks.process.QuickHistoryEntryProcess; public class MultiValueCellSplitOperation implements AbstractOperation { private static final long serialVersionUID = 8217930220439070322L; - final protected int _cellIndex; - final protected int _keyCellIndex; + final protected String _columnName; + final protected String _keyColumnName; final protected String _separator; final protected String _mode; public MultiValueCellSplitOperation( - int cellIndex, - int keyCellIndex, + String columnName, + String keyColumnName, String separator, String mode ) { - _cellIndex = cellIndex; - _keyCellIndex = keyCellIndex; + _columnName = columnName; + _keyColumnName = keyColumnName; _separator = separator; _mode = mode; } @@ -42,22 +42,29 @@ public class MultiValueCellSplitOperation implements AbstractOperation { public Process createProcess(Project project, Properties options) throws Exception { - Column column = project.columnModel.getColumnByCellIndex(_cellIndex); + Column column = project.columnModel.getColumnByName(_columnName); if (column == null) { - throw new Exception("No column corresponding to cell index " + _cellIndex); + throw new Exception("No column named " + _columnName); } + int cellIndex = column.getCellIndex(); + + Column keyColumn = project.columnModel.getColumnByName(_keyColumnName); + if (column == null) { + throw new Exception("No key column named " + _keyColumnName); + } + int keyCellIndex = keyColumn.getCellIndex(); List newRows = new ArrayList(); int oldRowCount = project.rows.size(); for (int r = 0; r < oldRowCount; r++) { Row oldRow = project.rows.get(r); - if (oldRow.isCellBlank(_cellIndex)) { + if (oldRow.isCellBlank(cellIndex)) { newRows.add(oldRow.dup()); continue; } - Object value = oldRow.getCellValue(_cellIndex); + Object value = oldRow.getCellValue(cellIndex); String s = value instanceof String ? ((String) value) : value.toString(); String[] values = null; if (_mode.equals("regex")) { @@ -74,7 +81,7 @@ public class MultiValueCellSplitOperation implements AbstractOperation { // First value goes into the same row { Row firstNewRow = oldRow.dup(); - firstNewRow.setCell(_cellIndex, new Cell(values[0].trim(), null)); + firstNewRow.setCell(cellIndex, new Cell(values[0].trim(), null)); newRows.add(firstNewRow); } @@ -85,11 +92,11 @@ public class MultiValueCellSplitOperation implements AbstractOperation { if (r2 < project.rows.size()) { Row oldRow2 = project.rows.get(r2); - if (oldRow2.isCellBlank(_cellIndex) && - oldRow2.isCellBlank(_keyCellIndex)) { + if (oldRow2.isCellBlank(cellIndex) && + oldRow2.isCellBlank(keyCellIndex)) { Row newRow = oldRow2.dup(); - newRow.setCell(_cellIndex, newCell); + newRow.setCell(cellIndex, newCell); newRows.add(newRow); r2++; @@ -98,8 +105,8 @@ public class MultiValueCellSplitOperation implements AbstractOperation { } } - Row newRow = new Row(_cellIndex + 1); - newRow.setCell(_cellIndex, newCell); + Row newRow = new Row(cellIndex + 1); + newRow.setCell(cellIndex, newCell); newRows.add(newRow); } diff --git a/src/main/java/com/metaweb/gridworks/model/operations/ReconOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/ReconOperation.java index ed250f3c1..bc49147d0 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/ReconOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/ReconOperation.java @@ -43,21 +43,21 @@ import com.metaweb.gridworks.util.ParsingUtilities; public class ReconOperation extends EngineDependentOperation { private static final long serialVersionUID = 838795186905314865L; - final protected int _cellIndex; + final protected String _columnName; final protected String _typeID; - public ReconOperation(JSONObject engineConfig, int cellIndex, String typeID) { + public ReconOperation(JSONObject engineConfig, String columnName, String typeID) { super(engineConfig); - _cellIndex = cellIndex; + _columnName = columnName; _typeID = typeID; } public Process createProcess(Project project, Properties options) throws Exception { Engine engine = createEngine(project); - Column column = project.columnModel.getColumnByCellIndex(_cellIndex); + Column column = project.columnModel.getColumnByName(_columnName); if (column == null) { - throw new Exception("No column corresponding to cell index " + _cellIndex); + throw new Exception("No column named " + _columnName); } List entries = new ArrayList(project.rows.size()); @@ -82,14 +82,14 @@ public class ReconOperation extends EngineDependentOperation { } return false; } - }.init(_cellIndex, entries)); + }.init(column.getCellIndex(), entries)); String description = "Reconcile " + entries.size() + " cells in column " + column.getHeaderLabel() + " to type " + _typeID; - return new ReconProcess(project, description, entries); + return new ReconProcess(project, description, entries, column.getCellIndex()); } public void write(JSONWriter writer, Properties options) @@ -146,11 +146,13 @@ public class ReconOperation extends EngineDependentOperation { public class ReconProcess extends LongRunningProcess implements Runnable { final protected Project _project; final protected List _entries; + final protected int _cellIndex; - public ReconProcess(Project project, String description, List entries) { + public ReconProcess(Project project, String description, List entries, int cellIndex) { super(description); _project = project; _entries = entries; + _cellIndex = cellIndex; } protected Runnable getRunnable() { diff --git a/src/main/java/com/metaweb/gridworks/model/operations/TextTransformOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/TextTransformOperation.java index d4dee1121..06c2fa83a 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/TextTransformOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/TextTransformOperation.java @@ -22,8 +22,8 @@ public class TextTransformOperation extends EngineDependentMassCellOperation { final protected String _expression; - public TextTransformOperation(JSONObject engineConfig, int cellIndex, String expression) { - super(engineConfig, cellIndex, true); + public TextTransformOperation(JSONObject engineConfig, String columnName, String expression) { + super(engineConfig, columnName, true); _expression = expression; } @@ -40,6 +40,8 @@ public class TextTransformOperation extends EngineDependentMassCellOperation { } protected RowVisitor createRowVisitor(Project project, List cellChanges) throws Exception { + Column column = project.columnModel.getColumnByName(_columnName); + Evaluable eval = new Parser(_expression).getExpression(); Properties bindings = ExpressionUtils.createBindings(project); @@ -72,6 +74,6 @@ public class TextTransformOperation extends EngineDependentMassCellOperation { return false; } - }.init(_cellIndex, bindings, cellChanges, eval); + }.init(column.getCellIndex(), bindings, cellChanges, eval); } } diff --git a/src/main/webapp/scripts/project/data-table-column-header-ui.js b/src/main/webapp/scripts/project/data-table-column-header-ui.js index 37b62fd4d..90b198037 100644 --- a/src/main/webapp/scripts/project/data-table-column-header-ui.js +++ b/src/main/webapp/scripts/project/data-table-column-header-ui.js @@ -187,7 +187,7 @@ DataTableColumnHeaderUI.prototype._createMenuForColumnHeader = function(elmt) { label: "Start Reconciling ...", tooltip: "Reconcile text in this column with topics on Freebase", click: function() { - new ReconDialog(self._columnIndex); + new ReconDialog(self._column); } }, {}, @@ -367,7 +367,7 @@ DataTableColumnHeaderUI.prototype._doFilterByExpressionPrompt = function(express DataTableColumnHeaderUI.prototype._doTextTransform = function(expression) { this._dataTableView.doPostThenUpdate( "do-text-transform", - { cell: this._column.cellIndex, expression: expression } + { columnName: this._column.headerLabel, expression: expression } ); }; @@ -386,21 +386,21 @@ DataTableColumnHeaderUI.prototype._doTextTransformPrompt = function() { DataTableColumnHeaderUI.prototype._doDiscardReconResults = function() { this._dataTableView.doPostThenUpdate( "discard-reconcile", - { cell: this._column.cellIndex } + { columnName: this._column.headerLabel } ); }; DataTableColumnHeaderUI.prototype._doApproveBestCandidates = function() { this._dataTableView.doPostThenUpdate( "approve-reconcile", - { cell: this._column.cellIndex } + { columnName: this._column.headerLabel } ); }; DataTableColumnHeaderUI.prototype._doApproveNewTopics = function() { this._dataTableView.doPostThenUpdate( "approve-new-reconcile", - { cell: this._column.cellIndex } + { columnName: this._column.headerLabel } ); }; @@ -416,7 +416,7 @@ DataTableColumnHeaderUI.prototype._doAddColumn = function(initialExpression) { self._dataTableView.doPostThenUpdate( "add-column", { - baseCellIndex: self._column.cellIndex, + baseColumnName: self._column.headerLabel, expression: expression, headerLabel: headerLabel, columnInsertIndex: self._columnIndex + 1 @@ -431,7 +431,7 @@ DataTableColumnHeaderUI.prototype._doAddColumn = function(initialExpression) { DataTableColumnHeaderUI.prototype._doRemoveColumn = function() { this._dataTableView.doPostThenUpdate( "remove-column", - { columnRemovalIndex: this._columnIndex }, + { columnName: this._column.headerLabel }, true ); }; @@ -442,8 +442,8 @@ DataTableColumnHeaderUI.prototype._doJoinMultiValueCells = function() { this._dataTableView.doPostThenUpdate( "join-multi-value-cells", { - cellIndex: this._column.cellIndex, - keyCellIndex: theProject.columnModel.keyCellIndex, + columnName: this._column.headerLabel, + keyColumnName: theProject.columnModel.keyColumnName, separator: separator } ); @@ -456,8 +456,8 @@ DataTableColumnHeaderUI.prototype._doSplitMultiValueCells = function() { this._dataTableView.doPostThenUpdate( "split-multi-value-cells", { - cellIndex: this._column.cellIndex, - keyCellIndex: theProject.columnModel.keyCellIndex, + columnName: this._column.headerLabel, + keyColumnName: theProject.columnModel.keyColumnName, separator: separator, mode: "plain" } diff --git a/src/main/webapp/scripts/project/data-table-view.js b/src/main/webapp/scripts/project/data-table-view.js index 5c62b63b2..eb9717917 100644 --- a/src/main/webapp/scripts/project/data-table-view.js +++ b/src/main/webapp/scripts/project/data-table-view.js @@ -227,7 +227,7 @@ DataTableView.prototype.render = function() { td.innerHTML = " "; } else { var cell = (column.cellIndex < cells.length) ? cells[column.cellIndex] : null; - new DataTableCellUI(this, cell, r, column.cellIndex, td); + new DataTableCellUI(this, cell, row.i, column.cellIndex, td); } } } diff --git a/src/main/webapp/scripts/project/recon-dialog.js b/src/main/webapp/scripts/project/recon-dialog.js index 98ba7baf2..ce0b0b85c 100644 --- a/src/main/webapp/scripts/project/recon-dialog.js +++ b/src/main/webapp/scripts/project/recon-dialog.js @@ -1,7 +1,5 @@ -function ReconDialog(columnIndex) { - this._columnIndex = columnIndex; - this._column = theProject.columnModel.columns[columnIndex]; - +function ReconDialog(column) { + this._column = column; this._createDialog(); } @@ -25,7 +23,7 @@ ReconDialog.prototype._createDialog = function() { $('').text("Start Reconciling").click(function() { DialogSystem.dismissUntil(level - 1); $.post( - "/command/reconcile?" + $.param({ project: theProject.id, cell: self._column.cellIndex, type: type }), + "/command/reconcile?" + $.param({ project: theProject.id, columnName: self._column.headerLabel, type: type }), { engine: JSON.stringify(ui.browsingEngine.getJSON()) }, function(data) { if (data.code != "error") {