use of com.google.api.services.sheets.v4.model.RowData in project OpenRefine by OpenRefine.
the class SpreadsheetSerializer method sendBatch.
private void sendBatch(List<RowData> rows) {
List<Request> requests = prepareBatch(rows);
// FIXME: We have a 10MB cap on the request size, but I'm not sure we've got a good
// way to quickly tell how big our request is. Just reduce row count for now.
BatchUpdateSpreadsheetRequest requestBody = new BatchUpdateSpreadsheetRequest();
requestBody.setIncludeSpreadsheetInResponse(false);
requestBody.setRequests(requests);
Sheets.Spreadsheets.BatchUpdate request;
try {
logger.debug("spreadsheetId: " + spreadsheetId);
// logger.debug("requestBody:" + requestBody.toString());
request = service.spreadsheets().batchUpdate(spreadsheetId, requestBody);
BatchUpdateSpreadsheetResponse response = request.execute();
logger.debug("response:" + response.toPrettyString());
} catch (IOException e) {
exceptions.add(e);
} finally {
requestBody.clear();
requests.clear();
rows.clear();
}
}
use of com.google.api.services.sheets.v4.model.RowData in project OpenRefine by OpenRefine.
the class SpreadsheetSerializerTests method testDataTypes.
@Test
public void testDataTypes() {
// options is null, but unused
SUT.startFile(options);
List<CellData> row = new ArrayList<>();
row.add(new CellData("null value", null, "null value", null));
row.add(new CellData("string value", "a string", "a string as string", null));
row.add(new CellData("integer value", 42, "42", null));
row.add(new CellData("double value", new Double(42), "42.0", null));
row.add(new CellData("boolean value", true, "true", null));
OffsetDateTime now = OffsetDateTime.now(ZoneId.of("Z"));
row.add(new CellData("datetime value", now, now.toString(), null));
SUT.addRow(row, false);
List<Request> requests = SUT.prepareBatch(SUT.getRows());
assertEquals(requests.size(), 1);
List<RowData> rows = requests.get(0).getAppendCells().getRows();
assertEquals(rows.size(), 1);
List<com.google.api.services.sheets.v4.model.CellData> values = rows.get(0).getValues();
assertEquals(values.size(), 6);
ExtendedValue value = values.get(0).getUserEnteredValue();
assertEquals(value.getStringValue(), "");
value = values.get(1).getUserEnteredValue();
assertEquals(value.getStringValue(), "a string");
value = values.get(2).getUserEnteredValue();
assertEquals(value.getNumberValue(), new Double(42));
value = values.get(3).getUserEnteredValue();
assertEquals(value.getNumberValue(), new Double(42));
value = values.get(4).getUserEnteredValue();
assertEquals(value.getBoolValue(), Boolean.TRUE);
value = values.get(5).getUserEnteredValue();
assertEquals(value.getStringValue(), now.toString());
}
use of com.google.api.services.sheets.v4.model.RowData in project OpenRefine by OpenRefine.
the class SpreadsheetSerializer method addRow.
@Override
public void addRow(List<CellData> cells, boolean isHeader) {
List<com.google.api.services.sheets.v4.model.CellData> cellDatas = new ArrayList<>();
RowData rowData = new RowData();
for (int c = 0; c < cells.size(); c++) {
CellData cellData = cells.get(c);
cellDatas.add(cellData2sheetCellData(cellData));
}
rowData.setValues(cellDatas);
rows.add(rowData);
if (rows.size() >= BATCH_SIZE) {
sendBatch(rows);
if (exceptions.size() > 0) {
throw new RuntimeException(exceptions.get(0));
}
}
}
use of com.google.api.services.sheets.v4.model.RowData in project OpenRefine by OpenRefine.
the class SpreadsheetSerializer method prepareBatch.
protected List<Request> prepareBatch(List<RowData> rows) {
List<Request> requests = new ArrayList<>();
// If this row is wider than our sheet, add columns to the sheet
int columns = rows.get(0).getValues().size();
if (columns > maxColumns) {
AppendDimensionRequest adr = new AppendDimensionRequest();
adr.setDimension("COLUMNS");
adr.setLength(columns - maxColumns);
maxColumns = columns;
Request req = new Request();
req.setAppendDimension(adr);
requests.add(req);
}
AppendCellsRequest acr = new AppendCellsRequest();
acr.setFields("*");
acr.setSheetId(0);
acr.setRows(rows);
Request request = new Request();
request.setAppendCells(acr);
requests.add(request);
return requests;
}
Aggregations