From 5b153dcfba83010c4ae79f9ce0785fb09ac2929b Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Mon, 5 Nov 2018 16:47:18 +0000 Subject: [PATCH] Migrate gdata extension importers to Jackson --- .../refine/extension/gdata/DeAuthorizeCommand.java | 1 - .../refine/extension/gdata/FusionTableImporter.java | 8 +++----- .../refine/extension/gdata/FusionTableSerializer.java | 3 --- .../com/google/refine/extension/gdata/GDataImporter.java | 9 ++++----- .../refine/extension/gdata/GDataImportingController.java | 7 +++---- .../refine/extension/gdata/GoogleAPIExtension.java | 1 - .../refine/extension/gdata/SpreadsheetSerializer.java | 3 --- .../com/google/refine/extension/gdata/UploadCommand.java | 4 +--- 8 files changed, 11 insertions(+), 25 deletions(-) diff --git a/extensions/gdata/src/com/google/refine/extension/gdata/DeAuthorizeCommand.java b/extensions/gdata/src/com/google/refine/extension/gdata/DeAuthorizeCommand.java index 7a1dd1ead..9ea0a706b 100644 --- a/extensions/gdata/src/com/google/refine/extension/gdata/DeAuthorizeCommand.java +++ b/extensions/gdata/src/com/google/refine/extension/gdata/DeAuthorizeCommand.java @@ -40,7 +40,6 @@ import com.google.api.client.http.HttpRequestFactory; import com.google.api.client.http.HttpResponse; import com.google.api.client.http.HttpTransport; import com.google.api.client.http.javanet.NetHttpTransport; - import com.google.refine.commands.Command; public class DeAuthorizeCommand extends Command { diff --git a/extensions/gdata/src/com/google/refine/extension/gdata/FusionTableImporter.java b/extensions/gdata/src/com/google/refine/extension/gdata/FusionTableImporter.java index c56f9d27e..2d6fd8633 100644 --- a/extensions/gdata/src/com/google/refine/extension/gdata/FusionTableImporter.java +++ b/extensions/gdata/src/com/google/refine/extension/gdata/FusionTableImporter.java @@ -32,13 +32,11 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import org.json.JSONObject; - +import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.api.services.fusiontables.Fusiontables; import com.google.api.services.fusiontables.model.Column; import com.google.api.services.fusiontables.model.Sqlresponse; import com.google.api.services.fusiontables.model.Table; - import com.google.refine.importers.TabularImportingParserBase; import com.google.refine.importers.TabularImportingParserBase.TableDataReader; import com.google.refine.importing.ImportingJob; @@ -60,7 +58,7 @@ public class FusionTableImporter { ProjectMetadata metadata, final ImportingJob job, int limit, - JSONObject options, + ObjectNode options, List exceptions) { Fusiontables service = FusionTableHandler.getFusionTablesService(token); @@ -206,7 +204,7 @@ public class FusionTableImporter { ProjectMetadata metadata, final ImportingJob job, int limit, - JSONObject options, + ObjectNode options, List exceptions) { String docUrlString = JSONUtilities.getString(options, "docUrl", null); diff --git a/extensions/gdata/src/com/google/refine/extension/gdata/FusionTableSerializer.java b/extensions/gdata/src/com/google/refine/extension/gdata/FusionTableSerializer.java index 230d836be..86e6cef90 100644 --- a/extensions/gdata/src/com/google/refine/extension/gdata/FusionTableSerializer.java +++ b/extensions/gdata/src/com/google/refine/extension/gdata/FusionTableSerializer.java @@ -5,13 +5,10 @@ import java.util.ArrayList; import java.util.List; import com.fasterxml.jackson.databind.JsonNode; - import com.google.api.client.http.AbstractInputStreamContent; import com.google.api.client.http.ByteArrayContent; import com.google.api.client.http.HttpResponseException; import com.google.api.services.fusiontables.Fusiontables; - -import com.google.refine.exporters.CustomizableTabularExporterConfiguration; import com.google.refine.exporters.TabularSerializer; final class FusionTableSerializer implements TabularSerializer { 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 05598e737..714c66167 100644 --- a/extensions/gdata/src/com/google/refine/extension/gdata/GDataImporter.java +++ b/extensions/gdata/src/com/google/refine/extension/gdata/GDataImporter.java @@ -6,15 +6,14 @@ import java.net.URL; 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.fasterxml.jackson.databind.node.ObjectNode; 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; import com.google.refine.importing.ImportingJob; @@ -31,7 +30,7 @@ public class GDataImporter { ProjectMetadata metadata, final ImportingJob job, int limit, - JSONObject options, + ObjectNode options, List exceptions) throws IOException { String docType = JSONUtilities.getString(options, "docType", null); @@ -64,7 +63,7 @@ public class GDataImporter { ProjectMetadata metadata, final ImportingJob job, int limit, - JSONObject options, + ObjectNode options, List exceptions) { String docUrlString = JSONUtilities.getString(options, "docUrl", null); @@ -100,7 +99,7 @@ public class GDataImporter { URL docURL, int worksheetIndex, int limit, - JSONObject options, + ObjectNode options, List exceptions) { try { diff --git a/extensions/gdata/src/com/google/refine/extension/gdata/GDataImportingController.java b/extensions/gdata/src/com/google/refine/extension/gdata/GDataImportingController.java index 8b243bbe6..8a35d4612 100644 --- a/extensions/gdata/src/com/google/refine/extension/gdata/GDataImportingController.java +++ b/extensions/gdata/src/com/google/refine/extension/gdata/GDataImportingController.java @@ -18,7 +18,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.fasterxml.jackson.core.JsonGenerator; - +import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.api.services.drive.Drive; import com.google.api.services.drive.model.File; import com.google.api.services.drive.model.FileList; @@ -29,7 +29,6 @@ import com.google.api.services.fusiontables.model.TableList; 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.refine.ProjectManager; import com.google.refine.RefineServlet; import com.google.refine.commands.HttpUtilities; @@ -237,7 +236,7 @@ public class GDataImportingController implements ImportingController { job.updating = true; try { - JSONObject optionObj = ParsingUtilities.evaluateJsonStringToObject( + ObjectNode optionObj = ParsingUtilities.evaluateJsonStringToObjectNode( request.getParameter("options")); List exceptions = new LinkedList(); @@ -301,7 +300,7 @@ public class GDataImportingController implements ImportingController { job.updating = true; try { - final JSONObject optionObj = ParsingUtilities.evaluateJsonStringToObject( + final ObjectNode optionObj = ParsingUtilities.evaluateJsonStringToObjectNode( request.getParameter("options")); final List exceptions = new LinkedList(); diff --git a/extensions/gdata/src/com/google/refine/extension/gdata/GoogleAPIExtension.java b/extensions/gdata/src/com/google/refine/extension/gdata/GoogleAPIExtension.java index dd68b505a..dc9d707e2 100644 --- a/extensions/gdata/src/com/google/refine/extension/gdata/GoogleAPIExtension.java +++ b/extensions/gdata/src/com/google/refine/extension/gdata/GoogleAPIExtension.java @@ -25,7 +25,6 @@ import com.google.api.services.drive.DriveScopes; import com.google.api.services.fusiontables.FusiontablesScopes; import com.google.api.services.sheets.v4.Sheets; import com.google.api.services.sheets.v4.SheetsScopes; - import com.google.refine.ProjectManager; import com.google.refine.preference.PreferenceStore; import com.google.refine.util.ParsingUtilities; diff --git a/extensions/gdata/src/com/google/refine/extension/gdata/SpreadsheetSerializer.java b/extensions/gdata/src/com/google/refine/extension/gdata/SpreadsheetSerializer.java index 1aa6300e1..769793dcd 100644 --- a/extensions/gdata/src/com/google/refine/extension/gdata/SpreadsheetSerializer.java +++ b/extensions/gdata/src/com/google/refine/extension/gdata/SpreadsheetSerializer.java @@ -10,7 +10,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.fasterxml.jackson.databind.JsonNode; - import com.google.api.services.sheets.v4.Sheets; import com.google.api.services.sheets.v4.model.AppendCellsRequest; import com.google.api.services.sheets.v4.model.BatchUpdateSpreadsheetRequest; @@ -18,8 +17,6 @@ import com.google.api.services.sheets.v4.model.BatchUpdateSpreadsheetResponse; import com.google.api.services.sheets.v4.model.ExtendedValue; import com.google.api.services.sheets.v4.model.Request; import com.google.api.services.sheets.v4.model.RowData; - -import com.google.refine.exporters.CustomizableTabularExporterConfiguration; import com.google.refine.exporters.TabularSerializer; final class SpreadsheetSerializer implements TabularSerializer { diff --git a/extensions/gdata/src/com/google/refine/extension/gdata/UploadCommand.java b/extensions/gdata/src/com/google/refine/extension/gdata/UploadCommand.java index f1879065a..e2272fecd 100644 --- a/extensions/gdata/src/com/google/refine/extension/gdata/UploadCommand.java +++ b/extensions/gdata/src/com/google/refine/extension/gdata/UploadCommand.java @@ -14,19 +14,17 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.exception.ExceptionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.apache.commons.codec.binary.Base64; import com.fasterxml.jackson.core.JsonGenerator; - import com.google.api.client.http.FileContent; import com.google.api.services.drive.Drive; import com.google.api.services.drive.model.File; import com.google.api.services.drive.model.File.ContentHints; import com.google.api.services.drive.model.File.ContentHints.Thumbnail; - import com.google.refine.ProjectManager; import com.google.refine.browsing.Engine; import com.google.refine.commands.Command;