From 3bda9d035dd82babd71d8c4b9ac65e3999ec2b90 Mon Sep 17 00:00:00 2001 From: David Huynh Date: Fri, 6 Aug 2010 06:15:05 +0000 Subject: [PATCH] Added support for creating a project by pointing to a data file URL. git-svn-id: http://google-refine.googlecode.com/svn/trunk@1139 7d457c2a-affb-35e4-300a-418c747d4874 --- CHANGES.txt | 3 ++ .../project/CreateProjectCommand.java | 29 ++++++++++--------- .../importers/ImporterUtilities.java | 2 +- .../gridworks/importers/TsvCsvImporter.java | 2 +- .../gridworks/util/ParsingUtilities.java | 1 - main/webapp/modules/core/index.html | 5 +++- main/webapp/modules/core/scripts/index.js | 20 +++++++------ 7 files changed, 36 insertions(+), 26 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 6a345b516..382468e90 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -15,6 +15,9 @@ Features: - In CSV and TSV importers, added support for ignoring quotation marks - Regexp groups capturing GEL function - Text facet's choice count limit is now configurable through preference page +- Select All and Unselect All buttons in History Extract dialog +- Schema skeleton: support for multiple cells per cell-as nodes, and for conditional links +- Added support for creating a project by pointing to a data file URL. Fixes: - TSV/CSV exporter bug: Gridworks crashed when there were empty cells. diff --git a/main/src/com/google/gridworks/commands/project/CreateProjectCommand.java b/main/src/com/google/gridworks/commands/project/CreateProjectCommand.java index a8a6f571a..80375549e 100644 --- a/main/src/com/google/gridworks/commands/project/CreateProjectCommand.java +++ b/main/src/com/google/gridworks/commands/project/CreateProjectCommand.java @@ -173,7 +173,8 @@ public class CreateProjectCommand extends Command { ) throws Exception { ServletFileUpload upload = new ServletFileUpload(); - String url = null; + String url = options.getProperty("url"); + boolean imported = false; FileItemIterator iter = upload.getItemIterator(request); while (iter.hasNext()) { @@ -185,25 +186,29 @@ public class CreateProjectCommand extends Command { Reader reader = new InputStreamReader(stream,"UTF-8"); try { internalInvokeImporter(project, new TsvCsvImporter(), options, reader); + imported = true; } finally { reader.close(); } - } else if (name.equals("url")) { + } else if (name.equals("project-url")) { url = Streams.asString(stream); } else { options.put(name, Streams.asString(stream)); } } else { String fileName = item.getName().toLowerCase(); - try { - internalImportFile(project, options, fileName, stream); - } finally { - stream.close(); + if (fileName.length() > 0) { + try { + internalImportFile(project, options, fileName, stream); + imported = true; + } finally { + stream.close(); + } } } } - if (url != null && url.length() > 0) { + if (!imported && url != null && url.length() > 0) { internalImportURL(request, project, options, url); } } @@ -230,7 +235,7 @@ public class CreateProjectCommand extends Command { protected void internalImportFile( Project project, Properties options, - String fileName, + String fileName, InputStream inputStream ) throws Exception { @@ -413,7 +418,6 @@ public class CreateProjectCommand extends Command { Importer importer = guessUrlImporter(url); if (importer instanceof UrlImporter) { ((UrlImporter) importer).read(url, project, options); - return; } else { // If we couldn't find one, try opening URL and treating as a stream try { @@ -432,10 +436,9 @@ public class CreateProjectCommand extends Command { } try { - importer = guessImporter(connection.getContentType(), - url.getPath()); - internalInvokeImporter(project, importer, options, inputStream, - connection.getContentEncoding()); + importer = guessImporter(connection.getContentType(), url.getPath()); + + internalInvokeImporter(project, importer, options, inputStream, connection.getContentEncoding()); } finally { inputStream.close(); } diff --git a/main/src/com/google/gridworks/importers/ImporterUtilities.java b/main/src/com/google/gridworks/importers/ImporterUtilities.java index a9f9a4bea..775761536 100644 --- a/main/src/com/google/gridworks/importers/ImporterUtilities.java +++ b/main/src/com/google/gridworks/importers/ImporterUtilities.java @@ -52,7 +52,7 @@ public class ImporterUtilities { if (options.containsKey(name)) { String s = options.getProperty(name); try { - value = Boolean.parseBoolean(s); + value = s.equalsIgnoreCase("on") || s.equals("1") || Boolean.parseBoolean(s); } catch (Exception e) { } } diff --git a/main/src/com/google/gridworks/importers/TsvCsvImporter.java b/main/src/com/google/gridworks/importers/TsvCsvImporter.java index cb9f0c296..ad678cbd1 100644 --- a/main/src/com/google/gridworks/importers/TsvCsvImporter.java +++ b/main/src/com/google/gridworks/importers/TsvCsvImporter.java @@ -24,7 +24,7 @@ public class TsvCsvImporter implements ReaderImporter,StreamImporter { @Override public void read(Reader reader, Project project, Properties options) throws ImportException { boolean splitIntoColumns = ImporterUtilities.getBooleanOption("split-into-columns", options, true); - + String sep = options.getProperty("separator"); // auto-detect if not present int ignoreLines = ImporterUtilities.getIntegerOption("ignore", options, -1); int headerLines = ImporterUtilities.getIntegerOption("header-lines", options, 1); diff --git a/main/src/com/google/gridworks/util/ParsingUtilities.java b/main/src/com/google/gridworks/util/ParsingUtilities.java index fd9deccd7..6a779d457 100644 --- a/main/src/com/google/gridworks/util/ParsingUtilities.java +++ b/main/src/com/google/gridworks/util/ParsingUtilities.java @@ -31,7 +31,6 @@ public class ParsingUtilities { if (query.startsWith("?")) { query = query.substring(1); } - parseParameters(options,query); } return options; diff --git a/main/webapp/modules/core/index.html b/main/webapp/modules/core/index.html index 79b8eea75..413d99847 100644 --- a/main/webapp/modules/core/index.html +++ b/main/webapp/modules/core/index.html @@ -64,6 +64,9 @@ Data File: + Or Data File URL: + + Project Name: @@ -109,7 +112,7 @@
Ignore Quotation Marks
-
Ignore quotation marks, using all newlines and separators
+
Ignore quotation marks,
using all newlines and separators
diff --git a/main/webapp/modules/core/scripts/index.js b/main/webapp/modules/core/scripts/index.js index 39dc92eb4..aea8efac4 100644 --- a/main/webapp/modules/core/scripts/index.js +++ b/main/webapp/modules/core/scripts/index.js @@ -1,22 +1,24 @@ function onClickUploadFileButton(evt) { var projectName = $("#project-name-input")[0].value; + var dataURL = $.trim($("#project-url-input")[0].value); if (! $.trim(projectName).length) { window.alert("You must specify a project name."); - } else if ($("#project-file-input")[0].files.length === 0) { - window.alert("You must specify select a file to upload."); + } else if ($("#project-file-input")[0].files.length === 0 && ! dataURL.length) { + window.alert("You must specify a data file to upload or a URL to retrieve."); } else { $("#file-upload-form").attr("action", "/command/create-project-from-upload?" + [ + "url=" + escape(dataURL), "split-into-columns=" + $("#split-into-columns-input")[0].checked, - "separator=" + $("#separator-input")[0].value, - "ignore=" + $("#ignore-input")[0].value, - "header-lines=" + $("#header-lines-input")[0].value, - "skip=" + $("#skip-input")[0].value, - "limit=" + $("#limit-input")[0].value, - "guess-value-type=" + $("#guess-value-type-input")[0].checked, - "ignore-quotes=" + $("#ignore-quotes-input")[0].checked + "separator=" + $("#separator-input")[0].value, + "ignore=" + $("#ignore-input")[0].value, + "header-lines=" + $("#header-lines-input")[0].value, + "skip=" + $("#skip-input")[0].value, + "limit=" + $("#limit-input")[0].value, + "guess-value-type=" + $("#guess-value-type-input")[0].checked, + "ignore-quotes=" + $("#ignore-quotes-input")[0].checked ].join("&")); return true;