Search in sources :

Example 1 with SmugMugImage

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

the class SmugMugPhotosExporter method exportPhotos.

private ExportResult<PhotosContainerResource> exportPhotos(IdOnlyContainerResource containerResource, StringPaginationToken paginationData, SmugMugInterface smugMugInterface, UUID jobId) throws IOException {
    List<PhotoModel> photoList = new ArrayList<>();
    // Make request to SmugMug
    String photoInfoUri;
    if (paginationData != null) {
        String token = paginationData.getToken();
        Preconditions.checkState(token.startsWith(PHOTO_TOKEN_PREFIX), "Invalid pagination token " + token);
        photoInfoUri = token.substring(PHOTO_TOKEN_PREFIX.length());
    } else {
        photoInfoUri = containerResource.getId();
    }
    SmugMugAlbumImageResponse albumImageList;
    try {
        albumImageList = smugMugInterface.getListOfAlbumImages(photoInfoUri + "!images");
    } catch (IOException e) {
        monitor.severe(() -> "Unable to get SmugMugAlbumImageResponse");
        throw e;
    }
    // Set up continuation data
    StringPaginationToken pageToken = null;
    if (albumImageList.getPageInfo().getNextPage() != null) {
        pageToken = new StringPaginationToken(PHOTO_TOKEN_PREFIX + albumImageList.getPageInfo().getNextPage());
    }
    ContinuationData continuationData = new ContinuationData(pageToken);
    // Make list of photos - images may be empty if the album provided is empty
    List<SmugMugImage> images = albumImageList.getAlbumImages() == null ? ImmutableList.of() : albumImageList.getAlbumImages();
    for (SmugMugImage albumImage : images) {
        if (!albumImage.isPhoto()) {
            continue;
        }
        String title = albumImage.getTitle();
        if (Strings.isNullOrEmpty(title)) {
            title = albumImage.getFileName();
        }
        PhotoModel model = new PhotoModel(title, albumImage.getArchivedUri(), albumImage.getCaption(), getMimeType(albumImage.getFormat()), albumImage.getArchivedUri(), containerResource.getId(), true);
        InputStream inputStream = smugMugInterface.getImageAsStream(model.getFetchableUrl());
        jobStore.create(jobId, model.getFetchableUrl(), inputStream);
        photoList.add(model);
    }
    PhotosContainerResource resource = new PhotosContainerResource(null, photoList);
    // Get result type
    ResultType resultType = ResultType.CONTINUE;
    if (pageToken == null) {
        resultType = ResultType.END;
    }
    return new ExportResult<>(resultType, resource, continuationData);
}
Also used : InputStream(java.io.InputStream) PhotoModel(org.datatransferproject.types.common.models.photos.PhotoModel) ArrayList(java.util.ArrayList) SmugMugImage(org.datatransferproject.transfer.smugmug.photos.model.SmugMugImage) 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) SmugMugAlbumImageResponse(org.datatransferproject.transfer.smugmug.photos.model.SmugMugAlbumImageResponse) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)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 SmugMugAlbumImageResponse (org.datatransferproject.transfer.smugmug.photos.model.SmugMugAlbumImageResponse)1 SmugMugImage (org.datatransferproject.transfer.smugmug.photos.model.SmugMugImage)1 StringPaginationToken (org.datatransferproject.types.common.StringPaginationToken)1 PhotoModel (org.datatransferproject.types.common.models.photos.PhotoModel)1 PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)1