Search in sources :

Example 1 with SpreadsheetService

use of com.google.gdata.client.spreadsheet.SpreadsheetService in project OpenRefine by OpenRefine.

the class GDataImporter method parse.

public static void parse(String token, Project project, ProjectMetadata metadata, final ImportingJob job, int limit, JSONObject options, List<Exception> exceptions) {
    String docType = JSONUtilities.getString(options, "docType", null);
    if ("spreadsheet".equals(docType)) {
        SpreadsheetService service = GDataExtension.getSpreadsheetService(token);
        parse(service, project, metadata, job, limit, options, exceptions);
    } else if ("table".equals(docType)) {
        FusionTableImporter.parse(token, project, metadata, job, limit, options, exceptions);
    }
}
Also used : SpreadsheetService(com.google.gdata.client.spreadsheet.SpreadsheetService)

Example 2 with SpreadsheetService

use of com.google.gdata.client.spreadsheet.SpreadsheetService in project OpenRefine by OpenRefine.

the class UploadCommand method uploadSpreadsheet.

private static String uploadSpreadsheet(final Project project, final Engine engine, final Properties params, String token, String name, List<Exception> exceptions) {
    Drive driveService = GDataExtension.getDriveService(token);
    final SpreadsheetService spreadsheetService = GDataExtension.getSpreadsheetService(token);
    try {
        File body = new File();
        body.setTitle(name);
        body.setDescription("Spreadsheet uploaded from OpenRefine project: " + name);
        body.setMimeType("application/vnd.google-apps.spreadsheet");
        File file = driveService.files().insert(body).execute();
        String fileID = file.getId();
        // Iterate through all spreadsheets to find one with our ID
        SpreadsheetEntry spreadsheetEntry2 = null;
        SpreadsheetFeed feed = spreadsheetService.getFeed(new URL(SPREADSHEET_FEED), SpreadsheetFeed.class);
        List<com.google.gdata.data.spreadsheet.SpreadsheetEntry> spreadsheets = feed.getEntries();
        for (com.google.gdata.data.spreadsheet.SpreadsheetEntry spreadsheet : spreadsheets) {
            if (spreadsheet.getId().endsWith(fileID)) {
                spreadsheetEntry2 = spreadsheet;
            }
        }
        // Bail if we didn't find our spreadsheet (shouldn't happen)
        if (spreadsheetEntry2 == null) {
            logger.error("Failed to find match for ID: " + fileID);
            return null;
        }
        int[] size = CustomizableTabularExporterUtilities.countColumnsRows(project, engine, params);
        URL worksheetFeedUrl = spreadsheetEntry2.getWorksheetFeedUrl();
        WorksheetEntry worksheetEntry = new WorksheetEntry(size[1], size[0]);
        worksheetEntry.setTitle(new PlainTextConstruct("Uploaded Data"));
        final WorksheetEntry worksheetEntry2 = spreadsheetService.insert(worksheetFeedUrl, worksheetEntry);
        spreadsheetEntry2.getDefaultWorksheet().delete();
        final SpreadsheetEntry spreadsheetEntry3 = spreadsheetEntry2;
        new Thread() {

            @Override
            public void run() {
                spreadsheetService.setProtocolVersion(SpreadsheetService.Versions.V3);
                try {
                    uploadToCellFeed(project, engine, params, spreadsheetService, spreadsheetEntry3, worksheetEntry2);
                } catch (Exception e) {
                    logger.error("Error uploading data to Google Spreadsheets", e);
                }
            }
        }.start();
        return spreadsheetEntry2.getSpreadsheetLink().getHref();
    } catch (IOException | ServiceException e) {
        exceptions.add(e);
    }
    return null;
}
Also used : SpreadsheetService(com.google.gdata.client.spreadsheet.SpreadsheetService) SpreadsheetEntry(com.google.gdata.data.spreadsheet.SpreadsheetEntry) IOException(java.io.IOException) URL(java.net.URL) WorksheetEntry(com.google.gdata.data.spreadsheet.WorksheetEntry) PlainTextConstruct(com.google.gdata.data.PlainTextConstruct) ServletException(javax.servlet.ServletException) ServiceException(com.google.gdata.util.ServiceException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) SpreadsheetEntry(com.google.gdata.data.spreadsheet.SpreadsheetEntry) ServiceException(com.google.gdata.util.ServiceException) SpreadsheetFeed(com.google.gdata.data.spreadsheet.SpreadsheetFeed) Drive(com.google.api.services.drive.Drive) File(com.google.api.services.drive.model.File)

Example 3 with SpreadsheetService

use of com.google.gdata.client.spreadsheet.SpreadsheetService in project OpenRefine by OpenRefine.

the class GDataImportingController method getWorksheetEntriesForDoc.

private List<WorksheetEntry> getWorksheetEntriesForDoc(URL docUrl, String token) throws IOException, ServiceException {
    if (token != null) {
        try {
            SpreadsheetService spreadsheetService = GDataExtension.getSpreadsheetService(token);
            SpreadsheetEntry spreadsheetEntry = spreadsheetService.getEntry(docUrl, SpreadsheetEntry.class);
            return spreadsheetEntry.getWorksheets();
        } catch (ServiceException e) {
        // Ignore and fall through, pretending that we're not logged in.
        }
    }
    return getWorksheetEntriesForDoc(docUrl);
}
Also used : ServiceException(com.google.gdata.util.ServiceException) SpreadsheetService(com.google.gdata.client.spreadsheet.SpreadsheetService) SpreadsheetEntry(com.google.gdata.data.spreadsheet.SpreadsheetEntry)

Example 4 with SpreadsheetService

use of com.google.gdata.client.spreadsheet.SpreadsheetService in project OpenRefine by OpenRefine.

the class GDataImportingController method getWorksheetEntriesForDoc.

private List<WorksheetEntry> getWorksheetEntriesForDoc(URL docUrl) throws IOException, ServiceException {
    SpreadsheetService spreadsheetService = GDataExtension.getSpreadsheetService(null);
    String visibility = "public";
    FeedURLFactory factory = FeedURLFactory.getDefault();
    String key = GDataExtension.getSpreadsheetID(docUrl);
    docUrl = factory.getWorksheetFeedUrl(key, visibility, "values");
    WorksheetFeed feed = spreadsheetService.getFeed(docUrl, WorksheetFeed.class);
    return feed.getEntries();
}
Also used : FeedURLFactory(com.google.gdata.client.spreadsheet.FeedURLFactory) SpreadsheetService(com.google.gdata.client.spreadsheet.SpreadsheetService) WorksheetFeed(com.google.gdata.data.spreadsheet.WorksheetFeed)

Aggregations

SpreadsheetService (com.google.gdata.client.spreadsheet.SpreadsheetService)4 SpreadsheetEntry (com.google.gdata.data.spreadsheet.SpreadsheetEntry)2 ServiceException (com.google.gdata.util.ServiceException)2 Drive (com.google.api.services.drive.Drive)1 File (com.google.api.services.drive.model.File)1 FeedURLFactory (com.google.gdata.client.spreadsheet.FeedURLFactory)1 PlainTextConstruct (com.google.gdata.data.PlainTextConstruct)1 SpreadsheetFeed (com.google.gdata.data.spreadsheet.SpreadsheetFeed)1 WorksheetEntry (com.google.gdata.data.spreadsheet.WorksheetEntry)1 WorksheetFeed (com.google.gdata.data.spreadsheet.WorksheetFeed)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ServletException (javax.servlet.ServletException)1