use of org.dataportabilityproject.dataModels.PaginationInformation in project data-transfer-project by google.
the class FlickrPhotoService method getPhotos.
private PhotosModelWrapper getPhotos(String photosetId, Optional<PaginationInformation> paginationInformation) throws IOException {
try {
int page = getPage(paginationInformation);
PhotoList<Photo> photoSetList;
if (null == photosetId) {
RequestContext.getRequestContext().setExtras(EXTRAS);
photoSetList = photosInterface.getNotInSet(PHOTO_PER_PAGE, page);
RequestContext.getRequestContext().setExtras(ImmutableList.of());
} else {
photoSetList = photosetsInterface.getPhotos(photosetId, ImmutableSet.copyOf(EXTRAS), 0, PHOTO_PER_PAGE, page);
}
boolean hasMore = photoSetList.getPage() != photoSetList.getPages() && !photoSetList.isEmpty();
Collection<PhotoModel> photos = photoSetList.stream().map(p -> toCommonPhoto(p, photosetId)).collect(Collectors.toList());
FlickrPaginationInformation newPage = null;
if (hasMore) {
newPage = new FlickrPaginationInformation(page + 1);
}
return new PhotosModelWrapper(null, photos, new ContinuationInformation(null, newPage));
} catch (FlickrException e) {
throw new IOException("Couldn't fetch photos in album: " + photosetId, e);
}
}
use of org.dataportabilityproject.dataModels.PaginationInformation in project data-transfer-project by google.
the class GoogleCalendarService method getCalendarEvents.
private CalendarModelWrapper getCalendarEvents(String id, Optional<PaginationInformation> pageInfo) throws IOException {
Calendar.Events.List listRequest = calendarClient.events().list(id).setMaxAttendees(100);
if (pageInfo.isPresent()) {
listRequest.setPageToken(((StringPaginationToken) pageInfo.get()).getId());
}
Events listResult = listRequest.execute();
List<CalendarEventModel> results = new ArrayList<>(listResult.getItems().size());
for (Event eventData : listResult.getItems()) {
CalendarEventModel model = GoogleCalendarToModelConverter.convertToCalendarEventModel(id, eventData);
results.add(model);
}
PaginationInformation newPageInfo = null;
if (listResult.getNextPageToken() != null) {
newPageInfo = new StringPaginationToken(listResult.getNextPageToken());
}
return new CalendarModelWrapper(null, results, new ContinuationInformation(null, newPageInfo));
}
use of org.dataportabilityproject.dataModels.PaginationInformation in project data-transfer-project by google.
the class GoogleCalendarServiceTest method testExportEventSubsequentSet.
@Test
public void testExportEventSubsequentSet() throws IOException {
setUpSingleEventResponse();
;
// Looking at subsequent page, with no pages after it
Resource resource = new IdOnlyResource(CALENDAR_ID);
PaginationInformation paginationInformation = new StringPaginationToken(NEXT_TOKEN);
ExportInformation resourceExportInformation = new ExportInformation(Optional.of(resource), Optional.of(paginationInformation));
eventListResponse.setNextPageToken(null);
// Run test
CalendarModelWrapper wrapper = calendarService.export(resourceExportInformation);
// Check results
// Verify correct methods were called in order
InOrder inOrder = Mockito.inOrder(eventListRequest);
inOrder.verify(eventListRequest).setPageToken(NEXT_TOKEN);
inOrder.verify(eventListRequest).execute();
// Check pagination token
StringPaginationToken paginationToken = (StringPaginationToken) wrapper.getContinuationInformation().getPaginationInformation();
assertThat(paginationToken).isNull();
}
Aggregations