Search in sources :

Example 1 with SmugMugAlbumImage

use of org.dataportabilityproject.transfer.smugmug.photos.model.SmugMugAlbumImage in project data-transfer-project by google.

the class SmugMugPhotosExporter method exportPhotos.

private ExportResult<PhotosContainerResource> exportPhotos(IdOnlyContainerResource containerResource, Optional<PaginationData> paginationData) throws IOException {
    List<PhotoModel> photoList = new ArrayList<>();
    // Make request to SmugMug
    String photoInfoUri;
    if (paginationData.isPresent()) {
        String token = ((StringPaginationToken) paginationData.get()).getToken();
        Preconditions.checkState(token.startsWith(PHOTO_TOKEN_PREFIX), "Invalid pagination token " + token);
        photoInfoUri = token.substring(PHOTO_TOKEN_PREFIX.length());
    } else {
        String id = containerResource.getId();
        photoInfoUri = String.format(ALBUM_URL_FORMATTER, id);
    }
    SmugMugResponse<SmugMugAlbumInfoResponse> albumInfoResponse = smugMugInterface.makeAlbumInfoRequest(photoInfoUri);
    // Set up continuation data
    StringPaginationToken pageToken = null;
    if (albumInfoResponse.getResponse().getPageInfo().getNextPage() != null) {
        pageToken = new StringPaginationToken(PHOTO_TOKEN_PREFIX + albumInfoResponse.getResponse().getPageInfo().getNextPage());
    }
    ContinuationData continuationData = new ContinuationData(pageToken);
    // Make list of photos
    for (SmugMugAlbumImage image : albumInfoResponse.getResponse().getImages()) {
        String title = image.getTitle();
        if (Strings.isNullOrEmpty(title)) {
            title = image.getFileName();
        }
        // TODO(olsona): this.authConsumer.sign(image.getArchivedUri()) ?
        photoList.add(new PhotoModel(title, image.getArchivedUri(), image.getCaption(), image.getFormat(), containerResource.getId()));
    }
    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 : PhotosContainerResource(org.dataportabilityproject.types.transfer.models.photos.PhotosContainerResource) PhotoModel(org.dataportabilityproject.types.transfer.models.photos.PhotoModel) SmugMugAlbumImage(org.dataportabilityproject.transfer.smugmug.photos.model.SmugMugAlbumImage) ArrayList(java.util.ArrayList) ContinuationData(org.dataportabilityproject.spi.transfer.types.ContinuationData) ResultType(org.dataportabilityproject.spi.transfer.provider.ExportResult.ResultType) StringPaginationToken(org.dataportabilityproject.spi.transfer.types.StringPaginationToken) SmugMugAlbumInfoResponse(org.dataportabilityproject.transfer.smugmug.photos.model.SmugMugAlbumInfoResponse) ExportResult(org.dataportabilityproject.spi.transfer.provider.ExportResult)

Aggregations

ArrayList (java.util.ArrayList)1 ExportResult (org.dataportabilityproject.spi.transfer.provider.ExportResult)1 ResultType (org.dataportabilityproject.spi.transfer.provider.ExportResult.ResultType)1 ContinuationData (org.dataportabilityproject.spi.transfer.types.ContinuationData)1 StringPaginationToken (org.dataportabilityproject.spi.transfer.types.StringPaginationToken)1 SmugMugAlbumImage (org.dataportabilityproject.transfer.smugmug.photos.model.SmugMugAlbumImage)1 SmugMugAlbumInfoResponse (org.dataportabilityproject.transfer.smugmug.photos.model.SmugMugAlbumInfoResponse)1 PhotoModel (org.dataportabilityproject.types.transfer.models.photos.PhotoModel)1 PhotosContainerResource (org.dataportabilityproject.types.transfer.models.photos.PhotosContainerResource)1