Search in sources :

Example 6 with PaginationInformation

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);
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) Importer(org.dataportabilityproject.dataModels.Importer) FlickrException(com.flickr4java.flickr.FlickrException) AppCredentials(org.dataportabilityproject.shared.AppCredentials) LoggerFactory(org.slf4j.LoggerFactory) Photoset(com.flickr4java.flickr.photosets.Photoset) REST(com.flickr4java.flickr.REST) PhotoAlbum(org.dataportabilityproject.dataModels.photos.PhotoAlbum) ArrayList(java.util.ArrayList) Photo(com.flickr4java.flickr.photos.Photo) Strings(com.google.api.client.repackaged.com.google.common.base.Strings) ImmutableList(com.google.common.collect.ImmutableList) PaginationInformation(org.dataportabilityproject.dataModels.PaginationInformation) PhotoModel(org.dataportabilityproject.dataModels.photos.PhotoModel) JobDataCache(org.dataportabilityproject.cloud.interfaces.JobDataCache) Uploader(com.flickr4java.flickr.uploader.Uploader) Flickr(com.flickr4java.flickr.Flickr) PhotoList(com.flickr4java.flickr.photos.PhotoList) Auth(com.flickr4java.flickr.auth.Auth) ImageStreamProvider(org.dataportabilityproject.shared.ImageStreamProvider) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) PhotosInterface(com.flickr4java.flickr.photos.PhotosInterface) Resource(org.dataportabilityproject.dataModels.Resource) ExportInformation(org.dataportabilityproject.dataModels.ExportInformation) Collection(java.util.Collection) IOException(java.io.IOException) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) UploadMetaData(com.flickr4java.flickr.uploader.UploadMetaData) Exporter(org.dataportabilityproject.dataModels.Exporter) Photosets(com.flickr4java.flickr.photosets.Photosets) List(java.util.List) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) RequestContext(com.flickr4java.flickr.RequestContext) PhotosModelWrapper(org.dataportabilityproject.dataModels.photos.PhotosModelWrapper) PhotosetsInterface(com.flickr4java.flickr.photosets.PhotosetsInterface) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) FlickrException(com.flickr4java.flickr.FlickrException) PhotoModel(org.dataportabilityproject.dataModels.photos.PhotoModel) PhotosModelWrapper(org.dataportabilityproject.dataModels.photos.PhotosModelWrapper) Photo(com.flickr4java.flickr.photos.Photo) IOException(java.io.IOException)

Example 7 with PaginationInformation

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));
}
Also used : CalendarModelWrapper(org.dataportabilityproject.dataModels.calendar.CalendarModelWrapper) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) Events(com.google.api.services.calendar.model.Events) ArrayList(java.util.ArrayList) Event(com.google.api.services.calendar.model.Event) CalendarEventModel(org.dataportabilityproject.dataModels.calendar.CalendarEventModel) PaginationInformation(org.dataportabilityproject.dataModels.PaginationInformation) StringPaginationToken(org.dataportabilityproject.shared.StringPaginationToken)

Example 8 with PaginationInformation

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();
}
Also used : CalendarModelWrapper(org.dataportabilityproject.dataModels.calendar.CalendarModelWrapper) ExportInformation(org.dataportabilityproject.dataModels.ExportInformation) InOrder(org.mockito.InOrder) Resource(org.dataportabilityproject.dataModels.Resource) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) PaginationInformation(org.dataportabilityproject.dataModels.PaginationInformation) StringPaginationToken(org.dataportabilityproject.shared.StringPaginationToken) Test(org.junit.Test)

Aggregations

PaginationInformation (org.dataportabilityproject.dataModels.PaginationInformation)8 ContinuationInformation (org.dataportabilityproject.dataModels.ContinuationInformation)7 ArrayList (java.util.ArrayList)6 Resource (org.dataportabilityproject.dataModels.Resource)6 IdOnlyResource (org.dataportabilityproject.shared.IdOnlyResource)6 StringPaginationToken (org.dataportabilityproject.shared.StringPaginationToken)6 ExportInformation (org.dataportabilityproject.dataModels.ExportInformation)3 CalendarModelWrapper (org.dataportabilityproject.dataModels.calendar.CalendarModelWrapper)3 TaskList (com.google.api.services.tasks.model.TaskList)2 TaskLists (com.google.api.services.tasks.model.TaskLists)2 IOException (java.io.IOException)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 JobDataCache (org.dataportabilityproject.cloud.interfaces.JobDataCache)2 Exporter (org.dataportabilityproject.dataModels.Exporter)2 Importer (org.dataportabilityproject.dataModels.Importer)2 MailMessageModel (org.dataportabilityproject.dataModels.mail.MailMessageModel)2 MailModelWrapper (org.dataportabilityproject.dataModels.mail.MailModelWrapper)2 Flickr (com.flickr4java.flickr.Flickr)1