diff --git a/.classpath b/.classpath
index 84016272a..b55cf5463 100644
--- a/.classpath
+++ b/.classpath
@@ -38,16 +38,7 @@
-
-
-
-
-
-
-
-
-
@@ -63,14 +54,6 @@
-
-
-
-
-
-
-
-
@@ -82,7 +65,6 @@
-
@@ -119,5 +101,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.gitignore b/.gitignore
index ccafd80f9..4f246f10d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,5 +23,6 @@ broker/core/data/
broker/core/test-output/
tmp/
/test-output
+test-out/
/bin
open-refine.log
diff --git a/extensions/gdata/module/MOD-INF/controller.js b/extensions/gdata/module/MOD-INF/controller.js
index 428941de3..a5ef68568 100644
--- a/extensions/gdata/module/MOD-INF/controller.js
+++ b/extensions/gdata/module/MOD-INF/controller.js
@@ -40,7 +40,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
var html = "text/html";
var encoding = "UTF-8";
-var version = "0.2";
+var version = "0.3";
var ClientSideResourceManager = Packages.com.google.refine.ClientSideResourceManager;
/*
@@ -61,10 +61,6 @@ function init() {
new Packages.com.google.refine.extension.gdata.GDataImportingController()
);
-
-//Packages.com.google.refine.exporters.ExporterRegistry.registerExporter(
-//"gdata-exporter", new Packages.com.google.refine.extension.gdata.GDataExporter());
-
// Script files to inject into /index page
ClientSideResourceManager.addPaths(
"index/scripts",
@@ -102,7 +98,7 @@ function process(path, request, response) {
// Analyze path and handle this request yourself.
if (path == "authorize") {
var context = {};
- context.authorizationUrl = Packages.com.google.refine.extension.gdata.GDataExtension.getAuthorizationUrl(module, request);
+ context.authorizationUrl = Packages.com.google.refine.extension.gdata.GoogleAPIExtension.getAuthorizationUrl(module, request);
send(request, response, "authorize.vt", context);
} else if (path == "authorized") {
@@ -111,9 +107,10 @@ function process(path, request, response) {
context.callback = request.getParameter("cb");
(function() {
- var token = Packages.com.google.refine.extension.gdata.GDataExtension.getTokenFromCode(module,request);
- if (token) {
- Packages.com.google.refine.extension.gdata.TokenCookie.setToken(request, response, token);
+ var tokenAndExpiresInSeconds = Packages.com.google.refine.extension.gdata.GoogleAPIExtension.getTokenFromCode(module,request);
+ if (tokenAndExpiresInSeconds) {
+ var tokenInfo = tokenAndExpiresInSeconds.split(",");
+ Packages.com.google.refine.extension.gdata.TokenCookie.setToken(request, response, tokenInfo[0], tokenInfo[1]);
return;
}
Packages.com.google.refine.extension.gdata.TokenCookie.deleteToken(request, response);
diff --git a/extensions/gdata/module/MOD-INF/lib/gdata-base-1.0.jar b/extensions/gdata/module/MOD-INF/lib/gdata-base-1.0.jar
deleted file mode 100644
index 2f65d50ae..000000000
Binary files a/extensions/gdata/module/MOD-INF/lib/gdata-base-1.0.jar and /dev/null differ
diff --git a/extensions/gdata/module/MOD-INF/lib/gdata-client-1.0.jar b/extensions/gdata/module/MOD-INF/lib/gdata-client-1.0.jar
deleted file mode 100644
index 99d073cab..000000000
Binary files a/extensions/gdata/module/MOD-INF/lib/gdata-client-1.0.jar and /dev/null differ
diff --git a/extensions/gdata/module/MOD-INF/lib/gdata-client-meta-1.0.jar b/extensions/gdata/module/MOD-INF/lib/gdata-client-meta-1.0.jar
deleted file mode 100644
index 362bca10d..000000000
Binary files a/extensions/gdata/module/MOD-INF/lib/gdata-client-meta-1.0.jar and /dev/null differ
diff --git a/extensions/gdata/module/MOD-INF/lib/gdata-core-1.0.jar b/extensions/gdata/module/MOD-INF/lib/gdata-core-1.0.jar
deleted file mode 100644
index 8c493c674..000000000
Binary files a/extensions/gdata/module/MOD-INF/lib/gdata-core-1.0.jar and /dev/null differ
diff --git a/extensions/gdata/module/MOD-INF/lib/gdata-docs-3.0.jar b/extensions/gdata/module/MOD-INF/lib/gdata-docs-3.0.jar
deleted file mode 100644
index 9f28745e6..000000000
Binary files a/extensions/gdata/module/MOD-INF/lib/gdata-docs-3.0.jar and /dev/null differ
diff --git a/extensions/gdata/module/MOD-INF/lib/gdata-docs-meta-3.0.jar b/extensions/gdata/module/MOD-INF/lib/gdata-docs-meta-3.0.jar
deleted file mode 100644
index f5edda213..000000000
Binary files a/extensions/gdata/module/MOD-INF/lib/gdata-docs-meta-3.0.jar and /dev/null differ
diff --git a/extensions/gdata/module/MOD-INF/lib/gdata-media-1.0.jar b/extensions/gdata/module/MOD-INF/lib/gdata-media-1.0.jar
deleted file mode 100644
index 69a545ae4..000000000
Binary files a/extensions/gdata/module/MOD-INF/lib/gdata-media-1.0.jar and /dev/null differ
diff --git a/extensions/gdata/module/MOD-INF/lib/gdata-spreadsheet-3.0.jar b/extensions/gdata/module/MOD-INF/lib/gdata-spreadsheet-3.0.jar
deleted file mode 100644
index e4ddb4ac6..000000000
Binary files a/extensions/gdata/module/MOD-INF/lib/gdata-spreadsheet-3.0.jar and /dev/null differ
diff --git a/extensions/gdata/module/MOD-INF/lib/gdata-spreadsheet-meta-3.0.jar b/extensions/gdata/module/MOD-INF/lib/gdata-spreadsheet-meta-3.0.jar
deleted file mode 100644
index e46c83e1a..000000000
Binary files a/extensions/gdata/module/MOD-INF/lib/gdata-spreadsheet-meta-3.0.jar and /dev/null differ
diff --git a/extensions/gdata/module/MOD-INF/lib/google-api-client-1.20.0.jar b/extensions/gdata/module/MOD-INF/lib/google-api-client-1.20.0.jar
deleted file mode 100644
index 778aa0192..000000000
Binary files a/extensions/gdata/module/MOD-INF/lib/google-api-client-1.20.0.jar and /dev/null differ
diff --git a/extensions/gdata/module/MOD-INF/lib/google-api-client-1.23.0.jar b/extensions/gdata/module/MOD-INF/lib/google-api-client-1.23.0.jar
new file mode 100644
index 000000000..3df306b2c
Binary files /dev/null and b/extensions/gdata/module/MOD-INF/lib/google-api-client-1.23.0.jar differ
diff --git a/extensions/gdata/module/MOD-INF/lib/google-api-client-servlet-1.20.0.jar b/extensions/gdata/module/MOD-INF/lib/google-api-client-servlet-1.20.0.jar
deleted file mode 100644
index d3389c132..000000000
Binary files a/extensions/gdata/module/MOD-INF/lib/google-api-client-servlet-1.20.0.jar and /dev/null differ
diff --git a/extensions/gdata/module/MOD-INF/lib/google-api-client-servlet-1.23.0.jar b/extensions/gdata/module/MOD-INF/lib/google-api-client-servlet-1.23.0.jar
new file mode 100644
index 000000000..95bd0431c
Binary files /dev/null and b/extensions/gdata/module/MOD-INF/lib/google-api-client-servlet-1.23.0.jar differ
diff --git a/extensions/gdata/module/MOD-INF/lib/google-api-services-drive-v2-rev168-1.20.0.jar b/extensions/gdata/module/MOD-INF/lib/google-api-services-drive-v2-rev168-1.20.0.jar
deleted file mode 100644
index 79ff52bb3..000000000
Binary files a/extensions/gdata/module/MOD-INF/lib/google-api-services-drive-v2-rev168-1.20.0.jar and /dev/null differ
diff --git a/extensions/gdata/module/MOD-INF/lib/google-api-services-drive-v3-rev101-1.23.0.jar b/extensions/gdata/module/MOD-INF/lib/google-api-services-drive-v3-rev101-1.23.0.jar
new file mode 100644
index 000000000..a20f60fd0
Binary files /dev/null and b/extensions/gdata/module/MOD-INF/lib/google-api-services-drive-v3-rev101-1.23.0.jar differ
diff --git a/extensions/gdata/module/MOD-INF/lib/google-api-services-fusiontables-v2-rev21-1.23.0.jar b/extensions/gdata/module/MOD-INF/lib/google-api-services-fusiontables-v2-rev21-1.23.0.jar
new file mode 100644
index 000000000..c215965ff
Binary files /dev/null and b/extensions/gdata/module/MOD-INF/lib/google-api-services-fusiontables-v2-rev21-1.23.0.jar differ
diff --git a/extensions/gdata/module/MOD-INF/lib/google-api-services-fusiontables-v2-rev3-1.20.0.jar b/extensions/gdata/module/MOD-INF/lib/google-api-services-fusiontables-v2-rev3-1.20.0.jar
deleted file mode 100644
index 5ef00235d..000000000
Binary files a/extensions/gdata/module/MOD-INF/lib/google-api-services-fusiontables-v2-rev3-1.20.0.jar and /dev/null differ
diff --git a/extensions/gdata/module/MOD-INF/lib/google-api-services-sheets-v4-rev502-1.23.0.jar b/extensions/gdata/module/MOD-INF/lib/google-api-services-sheets-v4-rev502-1.23.0.jar
new file mode 100644
index 000000000..87b3b0f43
Binary files /dev/null and b/extensions/gdata/module/MOD-INF/lib/google-api-services-sheets-v4-rev502-1.23.0.jar differ
diff --git a/extensions/gdata/module/MOD-INF/lib/google-auth-library-oauth2-http-0.9.0.jar b/extensions/gdata/module/MOD-INF/lib/google-auth-library-oauth2-http-0.9.0.jar
new file mode 100644
index 000000000..b14bd5f10
Binary files /dev/null and b/extensions/gdata/module/MOD-INF/lib/google-auth-library-oauth2-http-0.9.0.jar differ
diff --git a/extensions/gdata/module/MOD-INF/lib/google-http-client-1.20.0.jar b/extensions/gdata/module/MOD-INF/lib/google-http-client-1.20.0.jar
deleted file mode 100644
index 82887fb3e..000000000
Binary files a/extensions/gdata/module/MOD-INF/lib/google-http-client-1.20.0.jar and /dev/null differ
diff --git a/extensions/gdata/module/MOD-INF/lib/google-http-client-1.23.0.jar b/extensions/gdata/module/MOD-INF/lib/google-http-client-1.23.0.jar
new file mode 100644
index 000000000..3e6667d29
Binary files /dev/null and b/extensions/gdata/module/MOD-INF/lib/google-http-client-1.23.0.jar differ
diff --git a/extensions/gdata/module/MOD-INF/lib/google-http-client-jackson-1.23.0.jar b/extensions/gdata/module/MOD-INF/lib/google-http-client-jackson-1.23.0.jar
new file mode 100644
index 000000000..61d1a3a75
Binary files /dev/null and b/extensions/gdata/module/MOD-INF/lib/google-http-client-jackson-1.23.0.jar differ
diff --git a/extensions/gdata/module/MOD-INF/lib/google-http-client-jackson2-1.20.0.jar b/extensions/gdata/module/MOD-INF/lib/google-http-client-jackson2-1.20.0.jar
deleted file mode 100644
index 674aea920..000000000
Binary files a/extensions/gdata/module/MOD-INF/lib/google-http-client-jackson2-1.20.0.jar and /dev/null differ
diff --git a/extensions/gdata/module/MOD-INF/lib/google-oauth-client-1.20.0.jar b/extensions/gdata/module/MOD-INF/lib/google-oauth-client-1.20.0.jar
deleted file mode 100644
index 417dc5152..000000000
Binary files a/extensions/gdata/module/MOD-INF/lib/google-oauth-client-1.20.0.jar and /dev/null differ
diff --git a/extensions/gdata/module/MOD-INF/lib/google-oauth-client-1.23.0.jar b/extensions/gdata/module/MOD-INF/lib/google-oauth-client-1.23.0.jar
new file mode 100644
index 000000000..be88de28a
Binary files /dev/null and b/extensions/gdata/module/MOD-INF/lib/google-oauth-client-1.23.0.jar differ
diff --git a/extensions/gdata/module/MOD-INF/lib/google-oauth-client-jetty-1.23.0.jar b/extensions/gdata/module/MOD-INF/lib/google-oauth-client-jetty-1.23.0.jar
new file mode 100644
index 000000000..f0d2ee31c
Binary files /dev/null and b/extensions/gdata/module/MOD-INF/lib/google-oauth-client-jetty-1.23.0.jar differ
diff --git a/extensions/gdata/module/MOD-INF/lib/google-oauth-client-servlet-1.20.0.jar b/extensions/gdata/module/MOD-INF/lib/google-oauth-client-servlet-1.23.0.jar
similarity index 82%
rename from extensions/gdata/module/MOD-INF/lib/google-oauth-client-servlet-1.20.0.jar
rename to extensions/gdata/module/MOD-INF/lib/google-oauth-client-servlet-1.23.0.jar
index d444049ca..487e3c62d 100644
Binary files a/extensions/gdata/module/MOD-INF/lib/google-oauth-client-servlet-1.20.0.jar and b/extensions/gdata/module/MOD-INF/lib/google-oauth-client-servlet-1.23.0.jar differ
diff --git a/extensions/gdata/module/langs/translation-en.json b/extensions/gdata/module/langs/translation-en.json
index 089eaeac7..150432d77 100644
--- a/extensions/gdata/module/langs/translation-en.json
+++ b/extensions/gdata/module/langs/translation-en.json
@@ -44,6 +44,7 @@
"gdata-exporter": {
"uploading": "Uploading...",
"upload-error": "Upload error: ",
+ "upload-success": "Project was uploaded successfully to Google Drive with Id ",
"new-spreadsheet": "A new Google spreadsheet",
"enter-spreadsheet": "Enter a name for the new Google spreadsheet",
"new-fusion": "A new Google Fusion table",
diff --git a/extensions/gdata/module/scripts/index/gdata-source-ui.js b/extensions/gdata/module/scripts/index/gdata-source-ui.js
index 597725b03..9a430877e 100644
--- a/extensions/gdata/module/scripts/index/gdata-source-ui.js
+++ b/extensions/gdata/module/scripts/index/gdata-source-ui.js
@@ -83,7 +83,13 @@ Refine.GDataSourceUI.prototype.attachUI = function(body) {
} else {
doc.type = 'table';
}
- self._controller.startImportingDocument(doc);
+
+ if (GdataExtension.isAuthorized()) {
+ self._controller.startImportingDocument(doc);
+ } else {
+ var fn = self._controller.startImportingDocument;
+ GdataExtension.showAuthorizationDialog(fn.bind(self._controller, doc));
+ }
}
});
diff --git a/extensions/gdata/src/com/google/refine/extension/gdata/FusionTableHandler.java b/extensions/gdata/src/com/google/refine/extension/gdata/FusionTableHandler.java
index 16b35562c..c7f219f78 100644
--- a/extensions/gdata/src/com/google/refine/extension/gdata/FusionTableHandler.java
+++ b/extensions/gdata/src/com/google/refine/extension/gdata/FusionTableHandler.java
@@ -121,8 +121,8 @@ public class FusionTableHandler {
static public Fusiontables getFusionTablesService(String token) {
Credential credential = new GoogleCredential().setAccessToken(token);
Fusiontables fusiontables = new Fusiontables.Builder(
- GDataExtension.HTTP_TRANSPORT, GDataExtension.JSON_FACTORY, credential)
- .setApplicationName(GDataExtension.SERVICE_APP_NAME)
+ GoogleAPIExtension.HTTP_TRANSPORT, GoogleAPIExtension.JSON_FACTORY, credential)
+ .setApplicationName(GoogleAPIExtension.SERVICE_APP_NAME)
.build();;
return fusiontables;
diff --git a/extensions/gdata/src/com/google/refine/extension/gdata/GDataExtension.java b/extensions/gdata/src/com/google/refine/extension/gdata/GDataExtension.java
deleted file mode 100644
index 62aa91d32..000000000
--- a/extensions/gdata/src/com/google/refine/extension/gdata/GDataExtension.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * Copyright (c) 2010, Thomas F. Morris
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * - Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * Neither the name of Google nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package com.google.refine.extension.gdata;
-
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Arrays;
-
-import javax.servlet.http.HttpServletRequest;
-
-import com.google.api.client.auth.oauth2.AuthorizationCodeResponseUrl;
-import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeRequestUrl;
-import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequest;
-import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
-import com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse;
-import com.google.api.client.http.HttpTransport;
-import com.google.api.client.http.javanet.NetHttpTransport;
-import com.google.api.client.json.JsonFactory;
-import com.google.api.client.json.jackson2.JacksonFactory;
-import com.google.api.services.drive.Drive;
-import com.google.gdata.client.docs.DocsService;
-import com.google.gdata.client.spreadsheet.SpreadsheetService;
-
-import com.google.refine.util.ParsingUtilities;
-
-import edu.mit.simile.butterfly.ButterflyModule;
-
-/**
- * @author Tom Morris
- * @copyright 2010 Thomas F. Morris
- * @license New BSD http://www.opensource.org/licenses/bsd-license.php
- */
-abstract public class GDataExtension {
- static final String SERVICE_APP_NAME = "OpenRefine-GData-Extension";
- static final String CLIENT_ID = "647865400439.apps.googleusercontent.com";
- static final String CLIENT_SECRET = "0mW9OJji1yrgJk5AjJc5Pn6I"; // not really that secret, but the protocol accounts for that
-
- /** Global instance of the HTTP transport. */
- static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
-
- /** Global instance of the JSON factory. */
- static final JsonFactory JSON_FACTORY = new JacksonFactory();
-
- static public String getAuthorizationUrl(ButterflyModule module, HttpServletRequest request)
- throws MalformedURLException {
- String authorizedUrl = makeRedirectUrl(module, request);
-
- // New Oauth2
- GoogleAuthorizationCodeRequestUrl url = new GoogleAuthorizationCodeRequestUrl(
- CLIENT_ID,
- authorizedUrl, // execution continues at authorized on redirect
- Arrays.asList("https://www.googleapis.com/auth/fusiontables",
- "https://www.googleapis.com/auth/drive", // create new spreadsheets
- "https://spreadsheets.google.com/feeds"));
-
- return url.toString();
-
- }
-
- private static String makeRedirectUrl(ButterflyModule module, HttpServletRequest request)
- throws MalformedURLException {
- StringBuffer sb = new StringBuffer(module.getMountPoint().getMountPoint());
- sb.append("authorized?winname=");
- sb.append(ParsingUtilities.encode(request.getParameter("winname")));
- sb.append("&cb=");
- sb.append(ParsingUtilities.encode(request.getParameter("cb")));
-
- URL thisUrl = new URL(request.getRequestURL().toString());
- URL authorizedUrl = new URL(thisUrl, sb.toString());
- return authorizedUrl.toExternalForm();
- }
-
- static public String getTokenFromCode(ButterflyModule module, HttpServletRequest request)
- throws MalformedURLException {
- String redirectUrl = makeRedirectUrl(module, request);
- StringBuffer fullUrlBuf = request.getRequestURL();
- if (request.getQueryString() != null) {
- fullUrlBuf.append('?').append(request.getQueryString());
- }
- AuthorizationCodeResponseUrl authResponse =
- new AuthorizationCodeResponseUrl(fullUrlBuf.toString());
- // check for user-denied error
- if (authResponse.getError() != null) {
- // authorization denied...
- } else {
- // request access token using authResponse.getCode()...
- String code = authResponse.getCode();
- try {
- GoogleTokenResponse response = new GoogleAuthorizationCodeTokenRequest(HTTP_TRANSPORT,
- JSON_FACTORY, CLIENT_ID, CLIENT_SECRET, code, redirectUrl).execute();
- String token = response.getAccessToken();
- return token;
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- return null;
- }
-
-
- static public DocsService getDocsService(String token) {
- DocsService service = new DocsService(SERVICE_APP_NAME);
- if (token != null) {
- service.setAuthSubToken(token);
- }
- return service;
- }
-
- static public SpreadsheetService getSpreadsheetService(String token) {
- SpreadsheetService service = new SpreadsheetService(SERVICE_APP_NAME);
- if (token != null) {
- service.setAuthSubToken(token);
- }
- return service;
- }
-
- static public Drive getDriveService(String token) {
- GoogleCredential credential = new GoogleCredential().setAccessToken(token);
- return new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
- .setApplicationName(SERVICE_APP_NAME).build();
- }
-
- static boolean isSpreadsheetURL(String url) {
- // e.g. http://spreadsheets.google.com/ccc?key=tI36b9Fxk1lFBS83iR_3XQA&hl=en
- // TODO: The following should work, but the GData implementation is too limited
-// try {
-// FeedURLFactory.getSpreadsheetKeyFromUrl(url);
-// return true;
-// } catch (IllegalArgumentException e) {
-// return false;
-// }
- try {
- return url.contains("spreadsheet") && getSpreadsheetID(new URL(url)) != null;
- } catch (MalformedURLException e) {
- return false;
- }
- }
-
- static String getSpreadsheetID(URL url) {
- return getParamValue(url,"key");
- }
-
- static private String getParamValue(URL url, String key) {
- String query = url.getQuery();
- if (query != null) {
- String[] parts = query.split("&");
- for (String part : parts) {
- if (part.startsWith(key+"=")) {
- int offset = key.length()+1;
- String tableId = part.substring(offset);
- return tableId;
- }
- }
- }
- return null;
- }
-
-}
diff --git a/extensions/gdata/src/com/google/refine/extension/gdata/GDataImporter.java b/extensions/gdata/src/com/google/refine/extension/gdata/GDataImporter.java
index a4d58c2a6..3e2e1d9fd 100644
--- a/extensions/gdata/src/com/google/refine/extension/gdata/GDataImporter.java
+++ b/extensions/gdata/src/com/google/refine/extension/gdata/GDataImporter.java
@@ -1,49 +1,19 @@
-/*
- * Copyright (c) 2010, Thomas F. Morris
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * - Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- *
- * Neither the name of Google nor the names of its contributors may be used to
- * endorse or promote products derived from this software without specific
- * prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
package com.google.refine.extension.gdata;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.ArrayList;
import java.util.List;
+import org.apache.commons.lang3.exception.ExceptionUtils;
import org.json.JSONObject;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
-import com.google.gdata.client.spreadsheet.CellQuery;
-import com.google.gdata.client.spreadsheet.SpreadsheetService;
-import com.google.gdata.data.spreadsheet.Cell;
-import com.google.gdata.data.spreadsheet.CellEntry;
-import com.google.gdata.data.spreadsheet.CellFeed;
-import com.google.gdata.data.spreadsheet.SpreadsheetEntry;
-import com.google.gdata.data.spreadsheet.WorksheetEntry;
-import com.google.gdata.util.ServiceException;
+import com.google.api.services.sheets.v4.Sheets;
+import com.google.api.services.sheets.v4.model.Sheet;
+import com.google.api.services.sheets.v4.model.Spreadsheet;
+import com.google.api.services.sheets.v4.model.ValueRange;
import com.google.refine.importers.TabularImportingParserBase;
import com.google.refine.importers.TabularImportingParserBase.TableDataReader;
@@ -52,14 +22,9 @@ import com.google.refine.model.Project;
import com.google.refine.model.medadata.ProjectMetadata;
import com.google.refine.util.JSONUtilities;
-/**
- * OpenRefine parser for Google Spreadsheets.
- *
- * @author Tom Morris
- * @copyright 2010 Thomas F. Morris
- * @license New BSD http://www.opensource.org/licenses/bsd-license.php
- */
public class GDataImporter {
+ static final Logger logger = LoggerFactory.getLogger("GDataImporter");
+
static public void parse(
String token,
Project project,
@@ -67,11 +32,11 @@ public class GDataImporter {
final ImportingJob job,
int limit,
JSONObject options,
- List exceptions) {
+ List exceptions) throws IOException {
String docType = JSONUtilities.getString(options, "docType", null);
if ("spreadsheet".equals(docType)) {
- SpreadsheetService service = GDataExtension.getSpreadsheetService(token);
+ Sheets service = GoogleAPIExtension.getSheetsService(token);
parse(
service,
project,
@@ -94,7 +59,7 @@ public class GDataImporter {
}
static public void parse(
- SpreadsheetService service,
+ Sheets service,
Project project,
ProjectMetadata metadata,
final ImportingJob job,
@@ -104,6 +69,10 @@ public class GDataImporter {
String docUrlString = JSONUtilities.getString(options, "docUrl", null);
String worksheetUrlString = JSONUtilities.getString(options, "sheetUrl", null);
+
+ // the index of the worksheet
+ int worksheetIndex = JSONUtilities.getInt(options, "worksheetIndex", 0);
+
if (docUrlString != null && worksheetUrlString != null) {
try {
parseOneWorkSheet(
@@ -112,7 +81,7 @@ public class GDataImporter {
metadata,
job,
new URL(docUrlString),
- new URL(worksheetUrlString),
+ worksheetIndex,
limit,
options,
exceptions);
@@ -124,35 +93,35 @@ public class GDataImporter {
}
static public void parseOneWorkSheet(
- SpreadsheetService service,
+ Sheets service,
Project project,
ProjectMetadata metadata,
final ImportingJob job,
URL docURL,
- URL worksheetURL,
+ int worksheetIndex,
int limit,
JSONObject options,
List exceptions) {
try {
- WorksheetEntry worksheetEntry = service.getEntry(worksheetURL, WorksheetEntry.class);
+ String spreadsheetId = GoogleAPIExtension.extractSpreadSheetId(docURL.toString());
+
+ Spreadsheet response = service.spreadsheets().get(spreadsheetId)
+ .setIncludeGridData(true)
+ .execute();
+ Sheet worksheetEntry = response.getSheets().get(worksheetIndex);
+
String spreadsheetName = docURL.toExternalForm();
- try {
- SpreadsheetEntry spreadsheetEntry = service.getEntry(docURL, SpreadsheetEntry.class);
- spreadsheetName = spreadsheetEntry.getTitle().getPlainText();
- } catch (ServiceException e) { // RedirectRequiredException among others
- // fall back to just using the URL (better for traceability anyway?)
- }
String fileSource = spreadsheetName + " # " +
- worksheetEntry.getTitle().getPlainText();
+ worksheetEntry.getProperties().getTitle();
setProgress(job, fileSource, 0);
TabularImportingParserBase.readTable(
project,
metadata,
job,
- new WorksheetBatchRowReader(job, fileSource, service, worksheetEntry, 20),
+ new WorksheetBatchRowReader(job, fileSource, service, spreadsheetId, worksheetEntry),
fileSource,
limit,
options,
@@ -160,10 +129,7 @@ public class GDataImporter {
);
setProgress(job, fileSource, 100);
} catch (IOException e) {
- e.printStackTrace();
- exceptions.add(e);
- } catch (ServiceException e) {
- e.printStackTrace();
+ logger.error(ExceptionUtils.getStackTrace(e));
exceptions.add(e);
}
}
@@ -176,98 +142,61 @@ public class GDataImporter {
final ImportingJob job;
final String fileSource;
- final SpreadsheetService service;
- final WorksheetEntry worksheet;
- final int batchSize;
+ final Sheets service;
+ final String spreadsheetId;
+ final Sheet worksheet;
- final int totalRows;
-
- int nextRow = 0; // 0-based
- int batchRowStart = 0; // 0-based
- List> rowsOfCells = null;
+ private int indexRow = 0;
+ private List> rowsOfCells = null;
public WorksheetBatchRowReader(ImportingJob job, String fileSource,
- SpreadsheetService service, WorksheetEntry worksheet,
- int batchSize) {
+ Sheets service, String spreadsheetId, Sheet worksheet) {
this.job = job;
this.fileSource = fileSource;
this.service = service;
+ this.spreadsheetId = spreadsheetId;
this.worksheet = worksheet;
- this.batchSize = batchSize;
-
- this.totalRows = worksheet.getRowCount();
}
@Override
public List