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);
}
}
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;
}
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);
}
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();
}
Aggregations