Fixed styling problems introduced to previewed data table during importing stage, as introduced by recent changes to get the data table's headers stuck.
Some refactoring to gdata extension to prepare for other types of document. git-svn-id: http://google-refine.googlecode.com/svn/trunk@2231 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
57c11d0238
commit
f7aa8c2705
@ -28,7 +28,9 @@
|
||||
*/
|
||||
package com.google.refine.extension.gdata;
|
||||
|
||||
import com.google.gdata.client.docs.DocsService;
|
||||
import com.google.gdata.client.spreadsheet.FeedURLFactory;
|
||||
import com.google.gdata.client.spreadsheet.SpreadsheetService;
|
||||
|
||||
/**
|
||||
* @author Tom Morris <tfmorris@gmail.com>
|
||||
@ -46,4 +48,16 @@ abstract public class GDataExtension {
|
||||
}
|
||||
return factory;
|
||||
}
|
||||
|
||||
static public DocsService getDocsService(String token) {
|
||||
DocsService service = new DocsService(SERVICE_APP_NAME);
|
||||
service.setAuthSubToken(token);
|
||||
return service;
|
||||
}
|
||||
|
||||
static public SpreadsheetService getSpreadsheetService(String token) {
|
||||
SpreadsheetService service = new SpreadsheetService(SERVICE_APP_NAME);
|
||||
service.setAuthSubToken(token);
|
||||
return service;
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,7 @@ import java.util.List;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.google.gdata.client.docs.DocsService;
|
||||
import com.google.gdata.client.spreadsheet.CellQuery;
|
||||
import com.google.gdata.client.spreadsheet.SpreadsheetService;
|
||||
import com.google.gdata.data.spreadsheet.Cell;
|
||||
@ -60,6 +61,41 @@ import com.google.refine.util.JSONUtilities;
|
||||
* @license New BSD http://www.opensource.org/licenses/bsd-license.php
|
||||
*/
|
||||
public class GDataImporter {
|
||||
static public 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,
|
||||
job.project,
|
||||
job.metadata,
|
||||
job,
|
||||
limit,
|
||||
options,
|
||||
exceptions
|
||||
);
|
||||
} else if ("table".equals(docType)) {
|
||||
DocsService service = GDataExtension.getDocsService(token);
|
||||
parse(
|
||||
service,
|
||||
job.project,
|
||||
job.metadata,
|
||||
job,
|
||||
limit,
|
||||
options,
|
||||
exceptions
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
static public void parse(
|
||||
SpreadsheetService service,
|
||||
Project project,
|
||||
@ -113,7 +149,7 @@ public class GDataImporter {
|
||||
project,
|
||||
metadata,
|
||||
job,
|
||||
new BatchRowReader(job, fileSource, service, worksheetEntry, 20),
|
||||
new WorksheetBatchRowReader(job, fileSource, service, worksheetEntry, 20),
|
||||
fileSource,
|
||||
limit,
|
||||
options,
|
||||
@ -129,6 +165,21 @@ public class GDataImporter {
|
||||
}
|
||||
}
|
||||
|
||||
static public void parse(
|
||||
DocsService service,
|
||||
Project project,
|
||||
ProjectMetadata metadata,
|
||||
final ImportingJob job,
|
||||
int limit,
|
||||
JSONObject options,
|
||||
List<Exception> exceptions) {
|
||||
|
||||
String docUrlString = JSONUtilities.getString(options, "docUrl", null);
|
||||
if (docUrlString != null) {
|
||||
// TODO[dfhuynh]
|
||||
}
|
||||
}
|
||||
|
||||
static private void setProgress(ImportingJob job, String fileSource, int percent) {
|
||||
JSONObject progress = JSONUtilities.getObject(job.config, "progress");
|
||||
if (progress == null) {
|
||||
@ -139,7 +190,7 @@ public class GDataImporter {
|
||||
JSONUtilities.safePut(progress, "percent", percent);
|
||||
}
|
||||
|
||||
static private class BatchRowReader implements TableDataReader {
|
||||
static private class WorksheetBatchRowReader implements TableDataReader {
|
||||
final ImportingJob job;
|
||||
final String fileSource;
|
||||
|
||||
@ -153,7 +204,7 @@ public class GDataImporter {
|
||||
int batchRowStart = 0; // 0-based
|
||||
List<List<Object>> rowsOfCells = null;
|
||||
|
||||
public BatchRowReader(ImportingJob job, String fileSource,
|
||||
public WorksheetBatchRowReader(ImportingJob job, String fileSource,
|
||||
SpreadsheetService service, WorksheetEntry worksheet,
|
||||
int batchSize) {
|
||||
this.job = job;
|
||||
@ -190,49 +241,50 @@ public class GDataImporter {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static public List<List<Object>> getRowsOfCells(
|
||||
SpreadsheetService service,
|
||||
WorksheetEntry worksheet,
|
||||
int startRow, // 1-based
|
||||
int rowCount
|
||||
) throws IOException, ServiceException {
|
||||
URL cellFeedUrl = worksheet.getCellFeedUrl();
|
||||
|
||||
int minRow = startRow;
|
||||
int maxRow = Math.min(worksheet.getRowCount(), startRow + rowCount - 1);
|
||||
int cols = worksheet.getColCount();
|
||||
int rows = worksheet.getRowCount();
|
||||
|
||||
CellQuery cellQuery = new CellQuery(cellFeedUrl);
|
||||
cellQuery.setMinimumRow(minRow);
|
||||
cellQuery.setMaximumRow(maxRow);
|
||||
cellQuery.setMaximumCol(cols);
|
||||
cellQuery.setMaxResults(rows * cols);
|
||||
cellQuery.setReturnEmpty(false);
|
||||
|
||||
CellFeed cellFeed = service.query(cellQuery, CellFeed.class);
|
||||
List<CellEntry> cellEntries = cellFeed.getEntries();
|
||||
|
||||
List<List<Object>> rowsOfCells = new ArrayList<List<Object>>(rowCount);
|
||||
for (CellEntry cellEntry : cellEntries) {
|
||||
Cell cell = cellEntry.getCell();
|
||||
if (cell != null) {
|
||||
int row = cell.getRow() - startRow;
|
||||
int col = cell.getCol() - 1;
|
||||
|
||||
while (row >= rowsOfCells.size()) {
|
||||
rowsOfCells.add(new ArrayList<Object>());
|
||||
List<List<Object>> getRowsOfCells(
|
||||
SpreadsheetService service,
|
||||
WorksheetEntry worksheet,
|
||||
int startRow, // 1-based
|
||||
int rowCount
|
||||
) throws IOException, ServiceException {
|
||||
URL cellFeedUrl = worksheet.getCellFeedUrl();
|
||||
|
||||
int minRow = startRow;
|
||||
int maxRow = Math.min(worksheet.getRowCount(), startRow + rowCount - 1);
|
||||
int cols = worksheet.getColCount();
|
||||
int rows = worksheet.getRowCount();
|
||||
|
||||
CellQuery cellQuery = new CellQuery(cellFeedUrl);
|
||||
cellQuery.setMinimumRow(minRow);
|
||||
cellQuery.setMaximumRow(maxRow);
|
||||
cellQuery.setMaximumCol(cols);
|
||||
cellQuery.setMaxResults(rows * cols);
|
||||
cellQuery.setReturnEmpty(false);
|
||||
|
||||
CellFeed cellFeed = service.query(cellQuery, CellFeed.class);
|
||||
List<CellEntry> cellEntries = cellFeed.getEntries();
|
||||
|
||||
List<List<Object>> rowsOfCells = new ArrayList<List<Object>>(rowCount);
|
||||
for (CellEntry cellEntry : cellEntries) {
|
||||
Cell cell = cellEntry.getCell();
|
||||
if (cell != null) {
|
||||
int row = cell.getRow() - startRow;
|
||||
int col = cell.getCol() - 1;
|
||||
|
||||
while (row >= rowsOfCells.size()) {
|
||||
rowsOfCells.add(new ArrayList<Object>());
|
||||
}
|
||||
List<Object> rowOfCells = rowsOfCells.get(row);
|
||||
|
||||
while (col >= rowOfCells.size()) {
|
||||
rowOfCells.add(null);
|
||||
}
|
||||
rowOfCells.set(col, cell.getValue());
|
||||
}
|
||||
List<Object> rowOfCells = rowsOfCells.get(row);
|
||||
|
||||
while (col >= rowOfCells.size()) {
|
||||
rowOfCells.add(null);
|
||||
}
|
||||
rowOfCells.set(col, cell.getValue());
|
||||
}
|
||||
return rowsOfCells;
|
||||
}
|
||||
return rowsOfCells;
|
||||
}
|
||||
}
|
@ -49,12 +49,17 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONWriter;
|
||||
|
||||
import com.google.gdata.client.Query;
|
||||
import com.google.gdata.client.docs.DocsService;
|
||||
import com.google.gdata.client.spreadsheet.SpreadsheetService;
|
||||
import com.google.gdata.data.Category;
|
||||
import com.google.gdata.data.DateTime;
|
||||
import com.google.gdata.data.Person;
|
||||
import com.google.gdata.data.docs.DocumentListEntry;
|
||||
import com.google.gdata.data.docs.DocumentListFeed;
|
||||
import com.google.gdata.data.spreadsheet.SpreadsheetEntry;
|
||||
import com.google.gdata.data.spreadsheet.SpreadsheetFeed;
|
||||
import com.google.gdata.data.spreadsheet.TableEntry;
|
||||
import com.google.gdata.data.spreadsheet.WorksheetEntry;
|
||||
import com.google.gdata.util.ServiceException;
|
||||
|
||||
@ -120,9 +125,9 @@ public class GDataImportingController implements ImportingController {
|
||||
writer.array();
|
||||
|
||||
try {
|
||||
DocsService service = getDocsService(token);
|
||||
DocsService service = GDataExtension.getDocsService(token);
|
||||
listSpreadsheets(service, writer);
|
||||
//listDocumentsOfType(service, writer, "http://schemas.google.com/docs/2007#???");
|
||||
listDocumentsOfType(service, writer, "http://schemas.google.com/docs/2007#table");
|
||||
} catch (ServiceException e) {
|
||||
// TODO: just ignore?
|
||||
}
|
||||
@ -164,7 +169,6 @@ public class GDataImportingController implements ImportingController {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
private void listDocumentsOfType(DocsService service, JSONWriter writer, String type)
|
||||
throws IOException, ServiceException, JSONException {
|
||||
URL feedUrl = new URL("https://docs.google.com/feeds/default/private/full");
|
||||
@ -197,7 +201,6 @@ public class GDataImportingController implements ImportingController {
|
||||
writer.endObject();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
private void doInitializeParserUI(
|
||||
HttpServletRequest request, HttpServletResponse response, Properties parameters)
|
||||
@ -228,7 +231,7 @@ public class GDataImportingController implements ImportingController {
|
||||
JSONUtilities.safePut(options, "worksheets", worksheets);
|
||||
|
||||
if ("spreadsheet".equals(type)) {
|
||||
SpreadsheetService spreadsheetService = getSpreadsheetService(token);
|
||||
SpreadsheetService spreadsheetService = GDataExtension.getSpreadsheetService(token);
|
||||
SpreadsheetEntry spreadsheetEntry = spreadsheetService.getEntry(url, SpreadsheetEntry.class);
|
||||
for (WorksheetEntry worksheetEntry : spreadsheetEntry.getWorksheets()) {
|
||||
JSONObject worksheetO = new JSONObject();
|
||||
@ -238,6 +241,16 @@ public class GDataImportingController implements ImportingController {
|
||||
|
||||
JSONUtilities.append(worksheets, worksheetO);
|
||||
}
|
||||
} else if ("table".equals(type)) {
|
||||
DocsService docsService = GDataExtension.getDocsService(token);
|
||||
TableEntry tableEntry = docsService.getEntry(url, TableEntry.class);
|
||||
|
||||
JSONObject worksheetO = new JSONObject();
|
||||
JSONUtilities.safePut(worksheetO, "name", tableEntry.getTitle().getPlainText());
|
||||
JSONUtilities.safePut(worksheetO, "rows", -1);
|
||||
JSONUtilities.safePut(worksheetO, "link", tableEntry.getSelfLink().getHref());
|
||||
|
||||
JSONUtilities.append(worksheets, worksheetO);
|
||||
}
|
||||
/* TODO: else */
|
||||
|
||||
@ -258,7 +271,6 @@ public class GDataImportingController implements ImportingController {
|
||||
return;
|
||||
}
|
||||
|
||||
SpreadsheetService service = getSpreadsheetService(token);
|
||||
|
||||
long jobID = Long.parseLong(parameters.getProperty("jobID"));
|
||||
ImportingJob job = ImportingManager.getJob(jobID);
|
||||
@ -279,7 +291,7 @@ public class GDataImportingController implements ImportingController {
|
||||
job.prepareNewProject();
|
||||
|
||||
GDataImporter.parse(
|
||||
service,
|
||||
token,
|
||||
job.project,
|
||||
job.metadata,
|
||||
job,
|
||||
@ -322,20 +334,19 @@ public class GDataImportingController implements ImportingController {
|
||||
private void doCreateProject(HttpServletRequest request, HttpServletResponse response, Properties parameters)
|
||||
throws ServletException, IOException {
|
||||
|
||||
String token = TokenCookie.getToken(request);
|
||||
final String token = TokenCookie.getToken(request);
|
||||
if (token == null) {
|
||||
HttpUtilities.respond(response, "error", "Not authorized");
|
||||
return;
|
||||
}
|
||||
final SpreadsheetService service = getSpreadsheetService(token);
|
||||
|
||||
|
||||
long jobID = Long.parseLong(parameters.getProperty("jobID"));
|
||||
final ImportingJob job = ImportingManager.getJob(jobID);
|
||||
if (job == null) {
|
||||
HttpUtilities.respond(response, "error", "No such import job");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
final JSONObject optionObj = ParsingUtilities.evaluateJsonStringToObject(
|
||||
request.getParameter("options"));
|
||||
@ -353,7 +364,7 @@ public class GDataImportingController implements ImportingController {
|
||||
pm.setEncoding(JSONUtilities.getString(optionObj, "encoding", "UTF-8"));
|
||||
|
||||
GDataImporter.parse(
|
||||
service,
|
||||
token,
|
||||
project,
|
||||
pm,
|
||||
job,
|
||||
@ -378,16 +389,4 @@ public class GDataImportingController implements ImportingController {
|
||||
throw new ServletException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private DocsService getDocsService(String token) {
|
||||
DocsService service = new DocsService(GDataExtension.SERVICE_APP_NAME);
|
||||
service.setAuthSubToken(token);
|
||||
return service;
|
||||
}
|
||||
|
||||
private SpreadsheetService getSpreadsheetService(String token) {
|
||||
SpreadsheetService service = new SpreadsheetService(GDataExtension.SERVICE_APP_NAME);
|
||||
service.setAuthSubToken(token);
|
||||
return service;
|
||||
}
|
||||
}
|
||||
|
@ -107,7 +107,7 @@ table.data-table > tbody > tr.contextual > td > div {
|
||||
opacity: 0.3;
|
||||
}
|
||||
|
||||
table.data-header-table td.column-header {
|
||||
table.data-header-table td.column-header, table.data-table td.column-header {
|
||||
vertical-align: top;
|
||||
white-space: nowrap;
|
||||
cursor: pointer;
|
||||
@ -116,6 +116,12 @@ table.data-header-table td.column-header {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* For the preview in the importing stage */
|
||||
table.data-table td.column-header {
|
||||
background: @fill_primary;
|
||||
border-bottom: 2px solid @chrome_primary;
|
||||
}
|
||||
|
||||
.column-header-name {
|
||||
margin: 0 0 0 21px;
|
||||
padding: 4px 0 0 0;
|
||||
|
Loading…
Reference in New Issue
Block a user