use of org.datatransferproject.transfer.smugmug.photos.model.SmugMugAlbumImageResponse 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);
}
Aggregations