use of com.flickr4java.flickr.photosets.Photosets in project data-transfer-project by google.
the class FlickrPhotosExporterTest method exportAlbumInitial.
@Test
public void exportAlbumInitial() throws FlickrException {
// set up auth, flickr service
when(user.getId()).thenReturn("userId");
when(authInterface.checkToken(any(Token.class))).thenReturn(auth);
when(flickr.getPhotosetsInterface()).thenReturn(photosetsInterface);
when(flickr.getPhotosInterface()).thenReturn(photosInterface);
when(flickr.getAuthInterface()).thenReturn(authInterface);
// setup photoset
Photoset photoset = FlickrTestUtils.initializePhotoset("photosetId", "title", "description");
// setup photoset list (aka album view)
int page = 1;
Photosets photosetsList = new Photosets();
photosetsList.setPage(page);
photosetsList.setPages(page + 1);
photosetsList.setPhotosets(Collections.singletonList(photoset));
when(photosetsInterface.getList(anyString(), anyInt(), anyInt(), anyString())).thenReturn(photosetsList);
// run test
FlickrPhotosExporter exporter = new FlickrPhotosExporter(flickr);
AuthData authData = new TokenSecretAuthData("token", "secret");
ExportResult<PhotosContainerResource> result = exporter.export(UUID.randomUUID(), authData);
// make sure album and photo information is correct
assertThat(result.getExportedData().getPhotos()).isEmpty();
Collection<PhotoAlbum> albums = result.getExportedData().getAlbums();
assertThat(albums.size()).isEqualTo(1);
assertThat(albums).containsExactly(new PhotoAlbum("photosetId", "title", "description"));
// check continuation information
ContinuationData continuationData = (ContinuationData) result.getContinuationData();
assertThat(continuationData.getPaginationData()).isInstanceOf(IntPaginationToken.class);
assertThat(((IntPaginationToken) continuationData.getPaginationData()).getStart()).isEqualTo(page + 1);
Collection<? extends ContainerResource> subResources = continuationData.getContainerResources();
assertThat(subResources.size()).isEqualTo(1);
assertThat(subResources).containsExactly(new IdOnlyContainerResource("photosetId"));
}
use of com.flickr4java.flickr.photosets.Photosets in project data-transfer-project by google.
the class FlickrPhotosExporter method getAlbums.
private ExportResult<PhotosContainerResource> getAlbums(PaginationData paginationData, Auth auth) {
ImmutableList.Builder<PhotoAlbum> albumBuilder = ImmutableList.builder();
List<IdOnlyContainerResource> subResources = new ArrayList<>();
int page = paginationData == null ? 1 : ((IntPaginationToken) paginationData).getStart();
Photosets photoSetList;
try {
photoSetList = photosetsInterface.getList(auth.getUser().getId(), PHOTO_SETS_PER_PAGE, page, PHOTOSET_EXTRAS);
} catch (FlickrException e) {
return new ExportResult<>(ResultType.ERROR, "Error exporting Flickr album: " + e.getErrorMessage());
}
for (Photoset photoSet : photoSetList.getPhotosets()) {
// Saving data to the album allows the target service to recreate the album structure
albumBuilder.add(new PhotoAlbum(photoSet.getId(), photoSet.getTitle(), photoSet.getDescription()));
// Adding subresources tells the framework to recall export to get all the photos
subResources.add(new IdOnlyContainerResource(photoSet.getId()));
}
PaginationData newPage = null;
boolean hasMore = photoSetList.getPage() != photoSetList.getPages() && !photoSetList.getPhotosets().isEmpty();
if (hasMore)
newPage = new IntPaginationToken(page + 1);
PhotosContainerResource photosContainerResource = new PhotosContainerResource(albumBuilder.build(), null);
ContinuationData continuationData = new ContinuationData(newPage);
subResources.forEach(resource -> continuationData.addContainerResource(resource));
// Get result type
ResultType resultType = ResultType.CONTINUE;
if (newPage == null) {
resultType = ResultType.END;
}
return new ExportResult<>(resultType, photosContainerResource, continuationData);
}
use of com.flickr4java.flickr.photosets.Photosets in project data-transfer-project by google.
the class FlickrPhotoService method getAlbums.
private PhotosModelWrapper getAlbums(Optional<PaginationInformation> paginationInformation) throws IOException {
try {
ImmutableList.Builder<PhotoAlbum> results = ImmutableList.builder();
List<IdOnlyResource> subResources = new ArrayList<>();
int page = getPage(paginationInformation);
Photosets photoSetList = photosetsInterface.getList(auth.getUser().getId(), PHOTO_SETS_PER_PAGE, page, PHOTOSET_EXTRAS);
for (Photoset photoset : photoSetList.getPhotosets()) {
// Saving data to the album allows the target service
// to recreate the album structure.
results.add(new PhotoAlbum(photoset.getId(), photoset.getTitle(), photoset.getDescription()));
// Adding sub-resources tells the framework to re-call
// export to get all the photos.
subResources.add(new IdOnlyResource(photoset.getId()));
}
FlickrPaginationInformation newPage = null;
boolean hasMore = photoSetList.getPage() != photoSetList.getPages() && !photoSetList.getPhotosets().isEmpty();
if (hasMore) {
newPage = new FlickrPaginationInformation(page + 1);
}
return new PhotosModelWrapper(results.build(), null, new ContinuationInformation(subResources, newPage));
} catch (FlickrException e) {
throw new IOException("Couldn't fetch albums", e);
}
}
use of com.flickr4java.flickr.photosets.Photosets in project data-transfer-project by google.
the class FlickrPhotoServiceTest method exportAlbumInitial.
@Test
public void exportAlbumInitial() throws IOException, FlickrException {
// Set up initial export information, such as what FlickrPhotoService would see when a transfer
// is initiated
ExportInformation emptyExportInfo = new ExportInformation(Optional.empty(), Optional.empty());
// Set up auth
when(user.getId()).thenReturn("userId");
// Set up photoset
String photosetId = "photosetId";
String photosetTitle = "title";
String photosetDescription = "description";
Photoset photoset = initializePhotoset(photosetId, photosetTitle, photosetDescription);
// Set up photosets list (aka album view)
int page = 1;
Photosets photosetList = new Photosets();
photosetList.setPage(page);
photosetList.setPages(page + 1);
photosetList.setPhotosets(Collections.singletonList(photoset));
when(photosetsInterface.getList(anyString(), anyInt(), anyInt(), anyString())).thenReturn(photosetList);
// Run test
PhotosModelWrapper result = photoService.export(emptyExportInfo);
// Make sure album/photo information is correct
assertThat(result.getPhotos()).isEmpty();
Collection<PhotoAlbum> albums = result.getAlbums();
assertThat(albums.size()).isEqualTo(1);
assertThat(albums).containsExactly(new PhotoAlbum(photosetId, photosetTitle, photosetDescription));
// Make sure continuation information is correct
ContinuationInformation continuationInformation = result.getContinuationInformation();
assertThat((FlickrPaginationInformation) continuationInformation.getPaginationInformation()).isEqualTo(new FlickrPaginationInformation(page + 1));
Collection<? extends Resource> subResources = continuationInformation.getSubResources();
assertThat(subResources.size()).isEqualTo(1);
assertThat(subResources).containsExactly(new IdOnlyResource(photosetId));
}
Aggregations