use of org.dataportabilityproject.dataModels.ContinuationInformation in project data-transfer-project by google.
the class GoogleTaskService method getTaskLists.
private TaskModelWrapper getTaskLists(Optional<PaginationInformation> pageInfo) throws IOException {
Tasks.Tasklists.List query = taskClient.tasklists().list().setMaxResults(PAGE_SIZE);
if (pageInfo.isPresent()) {
query.setPageToken(((StringPaginationToken) pageInfo.get()).getId());
}
TaskLists result = query.execute();
List<TaskListModel> newTaskLists = new ArrayList<>(result.getItems().size());
List<Resource> newResources = new ArrayList<>(result.getItems().size());
for (TaskList taskList : result.getItems()) {
newTaskLists.add(new TaskListModel(taskList.getId(), taskList.getTitle()));
newResources.add(new IdOnlyResource(taskList.getId()));
}
PaginationInformation newPageInfo = null;
if (result.getNextPageToken() != null) {
newPageInfo = new StringPaginationToken(result.getNextPageToken());
}
return new TaskModelWrapper(newTaskLists, null, new ContinuationInformation(newResources, newPageInfo));
}
use of org.dataportabilityproject.dataModels.ContinuationInformation in project data-transfer-project by google.
the class FlickrPhotoService method getAlbums.
private PhotosModelWrapper getAlbums(Optional<PaginationInformation> paginationInformation) throws IOException {
try {
ImmutableList.Builder<PhotoAlbum> results = ImmutableList.builder();
List<IdOnlyResource> subResources = new ArrayList<>();
int page = getPage(paginationInformation);
Photosets photoSetList = photosetsInterface.getList(auth.getUser().getId(), PHOTO_SETS_PER_PAGE, page, PHOTOSET_EXTRAS);
for (Photoset photoset : photoSetList.getPhotosets()) {
// Saving data to the album allows the target service
// to recreate the album structure.
results.add(new PhotoAlbum(photoset.getId(), photoset.getTitle(), photoset.getDescription()));
// Adding sub-resources tells the framework to re-call
// export to get all the photos.
subResources.add(new IdOnlyResource(photoset.getId()));
}
FlickrPaginationInformation newPage = null;
boolean hasMore = photoSetList.getPage() != photoSetList.getPages() && !photoSetList.getPhotosets().isEmpty();
if (hasMore) {
newPage = new FlickrPaginationInformation(page + 1);
}
return new PhotosModelWrapper(results.build(), null, new ContinuationInformation(subResources, newPage));
} catch (FlickrException e) {
throw new IOException("Couldn't fetch albums", e);
}
}
use of org.dataportabilityproject.dataModels.ContinuationInformation 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.ContinuationInformation 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.ContinuationInformation in project data-transfer-project by google.
the class SmugMugPhotoService method getImages.
private PhotosModelWrapper getImages(IdOnlyResource resource, Optional<PaginationInformation> paginationInformation) throws IOException {
List<PhotoModel> photos = new ArrayList<>();
String url;
if (paginationInformation.isPresent()) {
url = ((StringPaginationToken) paginationInformation.get()).getId();
} else {
String id = resource.getId();
url = "/api/v2/album/" + id + "!images";
}
StringPaginationToken pageToken = null;
SmugMugResponse<SmugMugAlbumInfoResponse> albumInfoResponse = makeAlbumInfoRequest(url);
if (albumInfoResponse.getResponse().getImages() != null) {
for (SmugMugAlbumImage image : albumInfoResponse.getResponse().getImages()) {
String title = image.getTitle();
if (Strings.isNullOrEmpty(title)) {
title = image.getFileName();
}
try {
photos.add(new PhotoModel(title, this.authConsumer.sign(image.getArchivedUri()), image.getCaption(), image.getFormat(), resource.getId()));
} catch (OAuthException e) {
throw new IOException("Couldn't sign: " + image.getArchivedUri(), e);
}
}
if (albumInfoResponse.getResponse().getPageInfo().getNextPage() != null) {
pageToken = new StringPaginationToken(albumInfoResponse.getResponse().getPageInfo().getNextPage());
}
}
return new PhotosModelWrapper(null, photos, new ContinuationInformation(null, pageToken));
}
Aggregations