Search in sources :

Example 41 with StringPaginationToken

use of org.datatransferproject.types.common.StringPaginationToken in project data-transfer-project by google.

the class GooglePhotosExporter method exportPhotos.

@VisibleForTesting
ExportResult<PhotosContainerResource> exportPhotos(TokensAndUrlAuthData authData, Optional<IdOnlyContainerResource> albumData, Optional<PaginationData> paginationData, UUID jobId) throws IOException, InvalidTokenException, PermissionDeniedException {
    Optional<String> albumId = Optional.empty();
    if (albumData.isPresent()) {
        albumId = Optional.of(albumData.get().getId());
    }
    Optional<String> paginationToken = getPhotosPaginationToken(paginationData);
    MediaItemSearchResponse mediaItemSearchResponse = getOrCreatePhotosInterface(authData).listMediaItems(albumId, paginationToken);
    PaginationData nextPageData = null;
    if (!Strings.isNullOrEmpty(mediaItemSearchResponse.getNextPageToken())) {
        nextPageData = new StringPaginationToken(PHOTO_TOKEN_PREFIX + mediaItemSearchResponse.getNextPageToken());
    }
    ContinuationData continuationData = new ContinuationData(nextPageData);
    PhotosContainerResource containerResource = null;
    GoogleMediaItem[] mediaItems = mediaItemSearchResponse.getMediaItems();
    if (mediaItems != null && mediaItems.length > 0) {
        List<PhotoModel> photos = convertPhotosList(albumId, mediaItems, jobId);
        containerResource = new PhotosContainerResource(null, photos);
    }
    ResultType resultType = ResultType.CONTINUE;
    if (nextPageData == null) {
        resultType = ResultType.END;
    }
    return new ExportResult<>(resultType, containerResource, continuationData);
}
Also used : PaginationData(org.datatransferproject.types.common.PaginationData) PhotoModel(org.datatransferproject.types.common.models.photos.PhotoModel) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) ResultType(org.datatransferproject.spi.transfer.provider.ExportResult.ResultType) MediaItemSearchResponse(org.datatransferproject.datatransfer.google.mediaModels.MediaItemSearchResponse) PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) GoogleMediaItem(org.datatransferproject.datatransfer.google.mediaModels.GoogleMediaItem) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

StringPaginationToken (org.datatransferproject.types.common.StringPaginationToken)41 ContinuationData (org.datatransferproject.spi.transfer.types.ContinuationData)36 IdOnlyContainerResource (org.datatransferproject.types.common.models.IdOnlyContainerResource)23 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)22 PaginationData (org.datatransferproject.types.common.PaginationData)20 Test (org.junit.Test)19 PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)18 IOException (java.io.IOException)15 ArrayList (java.util.ArrayList)13 ResultType (org.datatransferproject.spi.transfer.provider.ExportResult.ResultType)12 PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)12 ExportInformation (org.datatransferproject.types.common.ExportInformation)10 ContainerResource (org.datatransferproject.types.common.models.ContainerResource)10 PhotoModel (org.datatransferproject.types.common.models.photos.PhotoModel)10 List (java.util.List)7 Optional (java.util.Optional)7 UUID (java.util.UUID)7 Collectors (java.util.stream.Collectors)7 InOrder (org.mockito.InOrder)7 GoogleMediaItem (org.datatransferproject.datatransfer.google.mediaModels.GoogleMediaItem)6