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