@Override protected MockLowLevelHttpResponse respond(final String method, final String url) { final SheetProperties cloned = source.getProperties().clone(); return new MockLowLevelHttpResponse().setContent(toJson(cloned)); } }
/** * This is synchronized because if it weren't and two copies were happening at the same time, Google API would * have thrown an undescribed HTTP 500 error when trying to execute the actual copying operation. A working theory * is that all the old sheet IDs are invalidated when a new sheet is added - but this is not verified. * @param sheetsService * @param stonky * @param export * @return * @throws IOException */ private static synchronized SheetProperties copySheet(final Sheets sheetsService, final Spreadsheet stonky, final File export) throws IOException { final int sheetId = sheetsService.spreadsheets().get(export.getId()) .execute() .getSheets() .get(0) // first and only sheet .getProperties() .getSheetId(); final CopySheetToAnotherSpreadsheetRequest r = new CopySheetToAnotherSpreadsheetRequest() .setDestinationSpreadsheetId(stonky.getSpreadsheetId()); LOGGER.debug("Will copy sheet {} from spreadsheet '{}' to spreadsheet '{}'", sheetId, export.getId(), stonky.getSpreadsheetId()); return sheetsService.spreadsheets().sheets() .copyTo(export.getId(), sheetId, r) .execute() .clone(); }
/** * This is synchronized because if it weren't and two copies were happening at the same time, Google API would * have thrown an undescribed HTTP 500 error when trying to execute the actual copying operation. A working theory * is that all the old sheet IDs are invalidated when a new sheet is added - but this is not verified. * @param sheetsService * @param stonky * @param export * @return * @throws IOException */ private static synchronized SheetProperties copySheet(final Sheets sheetsService, final Spreadsheet stonky, final File export) throws IOException { final int sheetId = sheetsService.spreadsheets().get(export.getId()) .execute() .getSheets() .get(0) // first and only sheet .getProperties() .getSheetId(); final CopySheetToAnotherSpreadsheetRequest r = new CopySheetToAnotherSpreadsheetRequest() .setDestinationSpreadsheetId(stonky.getSpreadsheetId()); LOGGER.debug("Will copy sheet {} from spreadsheet '{}' to spreadsheet '{}'", sheetId, export.getId(), stonky.getSpreadsheetId()); return sheetsService.spreadsheets().sheets() .copyTo(export.getId(), sheetId, r) .execute() .clone(); }