com.google.gdata.data.Link Java Examples

The following examples show how to use com.google.gdata.data.Link. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GoogleSheetsService.java    From q with Apache License 2.0 6 votes vote down vote up
private void updateWorksheetWithAllItems(WorksheetEntry worksheet, String[] header, List<ReportItem> reportItems, int numberOfRows, int numberOfColumns, String reportSpreadsheetName)
        throws BatchInterruptedException, MalformedURLException, IOException, ServiceException
{
    URL cellFeedUrl = worksheet.getCellFeedUrl();
    CellFeed cellFeed = spreadsheetService.getFeed(cellFeedUrl, CellFeed.class);

    Map<String, CellEntry> cellEntries = prepareBatchByQueringWorksheet(cellFeedUrl, numberOfRows, numberOfColumns);

    int startingRow = 1;
    int rowsInBatch = ((Double) Math.ceil((double)numberOfRows / Properties.googleSheetsBatchUploadSizeSplitFactor.get())).intValue();
    int endingRow = rowsInBatch;
    for (int i = 0; i < Properties.googleSheetsBatchUploadSizeSplitFactor.get(); i++) {
        CellFeed batchRequest = createBatchRequest(header, reportItems, startingRow, endingRow, numberOfColumns, cellEntries);
        Link batchLink = cellFeed.getLink(Link.Rel.FEED_BATCH, Link.Type.ATOM);
        CellFeed batchResponse = spreadsheetService.batch(new URL(batchLink.getHref()), batchRequest);
        boolean isSuccess = checkResults(batchResponse);
        logger.info((isSuccess ? "Batch operations successful: " : "Batch operations failed: ") + reportSpreadsheetName + " " + worksheet.getTitle().getPlainText() + " starting row: " + startingRow +", through row: " + endingRow);
        if(endingRow==startingRow) break;
        startingRow = startingRow + rowsInBatch;
        endingRow = Math.min(numberOfRows, endingRow + rowsInBatch);
    }
}
 
Example #2
Source File: GoogleSheetsService.java    From q with Apache License 2.0 6 votes vote down vote up
private Map<String, CellEntry> prepareBatchByQueringWorksheet(URL cellFeedUrl, int numberOfRows, int numberOfColumns) throws IOException, ServiceException
{
    CellFeed batchRequest = new CellFeed();
    for (int rowIndex = 1; rowIndex <= numberOfRows; rowIndex++) {
        for (int columnIndex = 1; columnIndex <= numberOfColumns; columnIndex++) {
            String id = getR1C1Id(rowIndex, columnIndex);
            CellEntry batchEntry = new CellEntry(rowIndex, columnIndex, id);
            batchEntry.setId(String.format("%s/%s", cellFeedUrl.toString(), id));
            BatchUtils.setBatchId(batchEntry, id);
            BatchUtils.setBatchOperationType(batchEntry, BatchOperationType.QUERY);
            batchRequest.getEntries().add(batchEntry);
        }
    }

    CellFeed cellFeed = spreadsheetService.getFeed(cellFeedUrl, CellFeed.class);
    CellFeed queryBatchResponse = spreadsheetService.batch(new URL(cellFeed.getLink(Link.Rel.FEED_BATCH, Link.Type.ATOM).getHref()), batchRequest);

    Map<String, CellEntry> cellEntryMap = new HashMap<String, CellEntry>(numberOfColumns);
    for (CellEntry entry : queryBatchResponse.getEntries()) {
        cellEntryMap.put(BatchUtils.getBatchId(entry), entry);
    }
    return cellEntryMap;
}
 
Example #3
Source File: EntryUtils.java    From google-sites-liberation with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the id given by the given entry's parent link, or null if it has
 * no parent link.
 */
public static String getParentId(BaseContentEntry<?> entry) {
  Link link = entry.getLink(SitesLink.Rel.PARENT, ILink.Type.ATOM);
  if (link == null) {
    return null;
  }
  return link.getHref();
}