use of org.dataportabilityproject.transfer.smugmug.photos.model.SmugMugAlbumsResponse in project data-transfer-project by google.
the class SmugMugPhotosExporter method exportAlbums.
private ExportResult<PhotosContainerResource> exportAlbums(Optional<PaginationData> paginationData) throws IOException {
// Make request to SmugMug
String albumInfoUri;
if (paginationData.isPresent()) {
String token = ((StringPaginationToken) paginationData.get()).getToken();
Preconditions.checkState(token.startsWith(ALBUM_TOKEN_PREFIX), "Invalid pagination token " + token);
albumInfoUri = token.substring(ALBUM_TOKEN_PREFIX.length());
} else {
SmugMugResponse<SmugMugUserResponse> userResponse = smugMugInterface.makeUserRequest(USER_URL);
albumInfoUri = userResponse.getResponse().getUser().getUris().get(ALBUMS_KEY).getUri();
}
SmugMugResponse<SmugMugAlbumsResponse> albumsResponse = smugMugInterface.makeAlbumRequest(albumInfoUri);
// Set up continuation data
StringPaginationToken paginationToken = null;
if (albumsResponse.getResponse().getPageInfo() != null && albumsResponse.getResponse().getPageInfo().getNextPage() != null) {
paginationToken = new StringPaginationToken(ALBUM_TOKEN_PREFIX + albumsResponse.getResponse().getPageInfo().getNextPage());
}
ContinuationData continuationData = new ContinuationData(paginationToken);
// Build album list
List<PhotoAlbum> albumsList = new ArrayList<>();
for (SmugMugAlbum album : albumsResponse.getResponse().getAlbums()) {
albumsList.add(new PhotoAlbum(album.getAlbumKey(), album.getTitle(), album.getDescription()));
continuationData.addContainerResource(new IdOnlyContainerResource(album.getAlbumKey()));
}
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