Search in sources :

Example 1 with SmugMugAlbum

use of org.datatransferproject.transfer.smugmug.photos.model.SmugMugAlbum in project data-transfer-project by google.

the class SmugMugPhotosExporter method exportAlbums.

private ExportResult<PhotosContainerResource> exportAlbums(StringPaginationToken paginationData, SmugMugInterface smugMugInterface) throws IOException {
    SmugMugAlbumsResponse albumsResponse;
    try {
        // Make request to SmugMug
        String albumInfoUri = "";
        if (paginationData != null) {
            String pageToken = paginationData.getToken();
            Preconditions.checkState(pageToken.startsWith(ALBUM_TOKEN_PREFIX), "Invalid pagination token " + pageToken);
            albumInfoUri = pageToken.substring(ALBUM_TOKEN_PREFIX.length());
        }
        albumsResponse = smugMugInterface.getAlbums(albumInfoUri);
    } catch (IOException e) {
        monitor.severe(() -> "Unable to get AlbumsResponse: ", e);
        throw e;
    }
    // Set up continuation data
    StringPaginationToken paginationToken = null;
    if (albumsResponse.getPageInfo() != null && albumsResponse.getPageInfo().getNextPage() != null) {
        paginationToken = new StringPaginationToken(ALBUM_TOKEN_PREFIX + albumsResponse.getPageInfo().getNextPage());
    }
    ContinuationData continuationData = new ContinuationData(paginationToken);
    // Build album list
    List<PhotoAlbum> albumsList = new ArrayList<>();
    if (albumsResponse.getAlbums() != null) {
        for (SmugMugAlbum album : albumsResponse.getAlbums()) {
            albumsList.add(new PhotoAlbum(album.getUri(), album.getName(), album.getDescription()));
            continuationData.addContainerResource(new IdOnlyContainerResource(album.getUri()));
        }
    }
    PhotosContainerResource resource = new PhotosContainerResource(albumsList, null);
    // Get result type
    ResultType resultType = ResultType.CONTINUE;
    if (paginationToken == null) {
        resultType = ResultType.END;
    }
    return new ExportResult<>(resultType, resource, continuationData);
}
Also used : ArrayList(java.util.ArrayList) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) IOException(java.io.IOException) ResultType(org.datatransferproject.spi.transfer.provider.ExportResult.ResultType) PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) SmugMugAlbum(org.datatransferproject.transfer.smugmug.photos.model.SmugMugAlbum) SmugMugAlbumsResponse(org.datatransferproject.transfer.smugmug.photos.model.SmugMugAlbumsResponse) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult)

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)1 ResultType (org.datatransferproject.spi.transfer.provider.ExportResult.ResultType)1 ContinuationData (org.datatransferproject.spi.transfer.types.ContinuationData)1 SmugMugAlbum (org.datatransferproject.transfer.smugmug.photos.model.SmugMugAlbum)1 SmugMugAlbumsResponse (org.datatransferproject.transfer.smugmug.photos.model.SmugMugAlbumsResponse)1 StringPaginationToken (org.datatransferproject.types.common.StringPaginationToken)1 IdOnlyContainerResource (org.datatransferproject.types.common.models.IdOnlyContainerResource)1 PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)1 PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)1