From 965ef20790310f8e5f34f5d29151ab4b3219c1a9 Mon Sep 17 00:00:00 2001 From: David Huynh Date: Sun, 1 Aug 2010 04:44:21 +0000 Subject: [PATCH] Made sure commands that create new columns check for duplicate column names. git-svn-id: http://google-refine.googlecode.com/svn/trunk@1126 7d457c2a-affb-35e4-300a-418c747d4874 --- .../commands/history/UndoRedoCommand.java | 14 +++++++++----- .../TransposeColumnsIntoRowsOperation.java | 6 ++++++ .../column/ColumnAdditionOperation.java | 3 +++ .../gridworks/process/ProcessManager.java | 18 ++++-------------- main/webapp/modules/core/scripts/project.js | 2 ++ 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/main/src/com/metaweb/gridworks/commands/history/UndoRedoCommand.java b/main/src/com/metaweb/gridworks/commands/history/UndoRedoCommand.java index fbdc1ba40..1c04ffe68 100644 --- a/main/src/com/metaweb/gridworks/commands/history/UndoRedoCommand.java +++ b/main/src/com/metaweb/gridworks/commands/history/UndoRedoCommand.java @@ -31,10 +31,14 @@ public class UndoRedoCommand extends Command { } } - boolean done = lastDoneID == -1 || - project.processManager.queueProcess( - new HistoryProcess(project, lastDoneID)); - - respond(response, "{ \"code\" : " + (done ? "\"ok\"" : "\"pending\"") + " }"); + try { + boolean done = lastDoneID == -1 || + project.processManager.queueProcess( + new HistoryProcess(project, lastDoneID)); + + respond(response, "{ \"code\" : " + (done ? "\"ok\"" : "\"pending\"") + " }"); + } catch (Exception e) { + respondException(response, e); + } } } diff --git a/main/src/com/metaweb/gridworks/operations/cell/TransposeColumnsIntoRowsOperation.java b/main/src/com/metaweb/gridworks/operations/cell/TransposeColumnsIntoRowsOperation.java index 518240774..6c8c139e5 100644 --- a/main/src/com/metaweb/gridworks/operations/cell/TransposeColumnsIntoRowsOperation.java +++ b/main/src/com/metaweb/gridworks/operations/cell/TransposeColumnsIntoRowsOperation.java @@ -73,6 +73,12 @@ public class TransposeColumnsIntoRowsOperation extends AbstractOperation { @Override protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception { + if (_combinedColumnName != null && + !_combinedColumnName.isEmpty() && + project.columnModel.getColumnByName(_combinedColumnName) != null) { + throw new Exception("Another column already named " + _combinedColumnName); + } + List newColumns = new ArrayList(); List oldColumns = project.columnModel.columns; diff --git a/main/src/com/metaweb/gridworks/operations/column/ColumnAdditionOperation.java b/main/src/com/metaweb/gridworks/operations/column/ColumnAdditionOperation.java index d818ea935..197ad28ab 100644 --- a/main/src/com/metaweb/gridworks/operations/column/ColumnAdditionOperation.java +++ b/main/src/com/metaweb/gridworks/operations/column/ColumnAdditionOperation.java @@ -105,6 +105,9 @@ public class ColumnAdditionOperation extends EngineDependentOperation { 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 cellsAtRows = new ArrayList(project.rows.size()); diff --git a/main/src/com/metaweb/gridworks/process/ProcessManager.java b/main/src/com/metaweb/gridworks/process/ProcessManager.java index 37298d034..87ee31c42 100644 --- a/main/src/com/metaweb/gridworks/process/ProcessManager.java +++ b/main/src/com/metaweb/gridworks/process/ProcessManager.java @@ -31,14 +31,9 @@ public class ProcessManager implements Jsonizable { writer.endObject(); } - public HistoryEntry queueProcess(Process process) { + public HistoryEntry queueProcess(Process process) throws Exception { if (process.isImmediate() && _processes.size() == 0) { - try { - return process.performImmediate(); - } catch (Exception e) { - // TODO: Not sure what to do yet - e.printStackTrace(); - } + return process.performImmediate(); } else { _processes.add(process); @@ -47,14 +42,9 @@ public class ProcessManager implements Jsonizable { return null; } - public boolean queueProcess(HistoryProcess process) { + public boolean queueProcess(HistoryProcess process) throws Exception { if (process.isImmediate() && _processes.size() == 0) { - try { - return process.performImmediate() != null; - } catch (Exception e) { - // TODO: Not sure what to do yet - e.printStackTrace(); - } + return process.performImmediate() != null; } else { _processes.add(process); diff --git a/main/webapp/modules/core/scripts/project.js b/main/webapp/modules/core/scripts/project.js index d2aee456d..634e743aa 100644 --- a/main/webapp/modules/core/scripts/project.js +++ b/main/webapp/modules/core/scripts/project.js @@ -243,6 +243,8 @@ Gridworks.postProcess = function(command, params, body, updateOptions, callbacks } catch (e) { Gridworks.reportException(e); } + } else { + alert(o.message); } } else { if ("onDone" in callbacks) {