Search in sources :

Example 11 with ContinuationInformation

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));
}
Also used : TaskList(com.google.api.services.tasks.model.TaskList) ArrayList(java.util.ArrayList) Resource(org.dataportabilityproject.dataModels.Resource) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) TaskModelWrapper(org.dataportabilityproject.dataModels.tasks.TaskModelWrapper) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) TaskLists(com.google.api.services.tasks.model.TaskLists) TaskListModel(org.dataportabilityproject.dataModels.tasks.TaskListModel) PaginationInformation(org.dataportabilityproject.dataModels.PaginationInformation) StringPaginationToken(org.dataportabilityproject.shared.StringPaginationToken)

Example 12 with ContinuationInformation

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);
    }
}
Also used : FlickrException(com.flickr4java.flickr.FlickrException) ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) PhotosModelWrapper(org.dataportabilityproject.dataModels.photos.PhotosModelWrapper) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) IOException(java.io.IOException) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) Photoset(com.flickr4java.flickr.photosets.Photoset) Photosets(com.flickr4java.flickr.photosets.Photosets) PhotoAlbum(org.dataportabilityproject.dataModels.photos.PhotoAlbum)

Example 13 with ContinuationInformation

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);
    }
}
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 14 with ContinuationInformation

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));
}
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 15 with ContinuationInformation

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));
}
Also used : ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) PhotoModel(org.dataportabilityproject.dataModels.photos.PhotoModel) SmugMugAlbumImage(org.dataportabilityproject.serviceProviders.smugmug.model.SmugMugAlbumImage) OAuthException(oauth.signpost.exception.OAuthException) ArrayList(java.util.ArrayList) PhotosModelWrapper(org.dataportabilityproject.dataModels.photos.PhotosModelWrapper) IOException(java.io.IOException) StringPaginationToken(org.dataportabilityproject.shared.StringPaginationToken) SmugMugAlbumInfoResponse(org.dataportabilityproject.serviceProviders.smugmug.model.SmugMugAlbumInfoResponse)

Aggregations

ContinuationInformation (org.dataportabilityproject.dataModels.ContinuationInformation)18 ArrayList (java.util.ArrayList)13 IdOnlyResource (org.dataportabilityproject.shared.IdOnlyResource)11 Resource (org.dataportabilityproject.dataModels.Resource)10 IOException (java.io.IOException)8 PhotosModelWrapper (org.dataportabilityproject.dataModels.photos.PhotosModelWrapper)8 StringPaginationToken (org.dataportabilityproject.shared.StringPaginationToken)8 PaginationInformation (org.dataportabilityproject.dataModels.PaginationInformation)7 ExportInformation (org.dataportabilityproject.dataModels.ExportInformation)5 Photoset (com.flickr4java.flickr.photosets.Photoset)4 PhotoAlbum (org.dataportabilityproject.dataModels.photos.PhotoAlbum)4 Photosets (com.flickr4java.flickr.photosets.Photosets)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 FlickrException (com.flickr4java.flickr.FlickrException)2 UploadMetaData (com.flickr4java.flickr.uploader.UploadMetaData)2 Credential (com.google.api.client.auth.oauth2.Credential)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ImmutableList (com.google.common.collect.ImmutableList)2 BufferedInputStream (java.io.BufferedInputStream)2