use of com.flickr4java.flickr.photos.Photo in project data-transfer-project by google.
the class FlickrPhotoServiceTest method toCommonPhoto.
@Test
public void toCommonPhoto() {
Photo photo = initializePhoto(PHOTO_TITLE, FETCHABLE_URL, PHOTO_DESCRIPTION);
PhotoModel photoModel = FlickrPhotoService.toCommonPhoto(photo, ALBUM_ID);
assertThat(photoModel.getAlbumId()).isEqualTo(ALBUM_ID);
assertThat(photoModel.getFetchableUrl()).isEqualTo(FETCHABLE_URL);
assertThat(photoModel.getTitle()).isEqualTo(PHOTO_TITLE);
assertThat(photoModel.getDescription()).isEqualTo(PHOTO_DESCRIPTION);
assertThat(photoModel.getMediaType()).isEqualTo("image/jpeg");
}
use of com.flickr4java.flickr.photos.Photo in project data-transfer-project by google.
the class FlickrPhotosExporter method getPhotos.
private ExportResult<PhotosContainerResource> getPhotos(IdOnlyContainerResource resource, PaginationData paginationData) {
String photoSetId = resource.getId();
int page = paginationData == null ? 1 : ((IntPaginationToken) paginationData).getStart();
PhotoList<Photo> photoSetList;
try {
if (photoSetId == null) {
RequestContext.getRequestContext().setExtras(EXTRAS);
photoSetList = photosInterface.getNotInSet(PHOTO_PER_PAGE, page);
RequestContext.getRequestContext().setExtras(ImmutableList.of());
} else {
photoSetList = photosetsInterface.getPhotos(photoSetId, ImmutableSet.copyOf(EXTRAS), 0, PHOTO_PER_PAGE, page);
}
} catch (FlickrException e) {
return new ExportResult<>(ResultType.ERROR, "Error exporting Flickr photo: " + e.getErrorMessage());
}
boolean hasMore = photoSetList.getPage() != photoSetList.getPages() && !photoSetList.isEmpty();
Collection<PhotoModel> photos = photoSetList.stream().map(p -> toCommonPhoto(p, photoSetId)).collect(Collectors.toList());
PaginationData newPage = null;
if (hasMore) {
newPage = new IntPaginationToken(page + 1);
}
// Get result type
ResultType resultType = ResultType.CONTINUE;
if (newPage == null) {
resultType = ResultType.END;
}
PhotosContainerResource photosContainerResource = new PhotosContainerResource(null, photos);
return new ExportResult<>(resultType, photosContainerResource, new ContinuationData(newPage));
}
use of com.flickr4java.flickr.photos.Photo in project data-transfer-project by google.
the class FlickrPhotosExporterTest method toCommonPhoto.
@Test
public void toCommonPhoto() {
Photo photo = FlickrTestUtils.initializePhoto(PHOTO_TITLE, FETCHABLE_URL, PHOTO_DESCRIPTION, MEDIA_TYPE);
PhotoModel photoModel = FlickrPhotosExporter.toCommonPhoto(photo, ALBUM_ID);
assertThat(photoModel.getAlbumId()).isEqualTo(ALBUM_ID);
assertThat(photoModel.getFetchableUrl()).isEqualTo(FETCHABLE_URL);
assertThat(photoModel.getTitle()).isEqualTo(PHOTO_TITLE);
assertThat(photoModel.getDescription()).isEqualTo(PHOTO_DESCRIPTION);
assertThat(photoModel.getMediaType()).isEqualTo("image/jpeg");
}
use of com.flickr4java.flickr.photos.Photo in project data-transfer-project by google.
the class FlickrPhotosExporterTest method exportPhotosFromPhotoset.
@Test
public void exportPhotosFromPhotoset() 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);
// getting photos from a set with id photosetsId and page 1
int page = 1;
String photosetsId = "photosetsId";
ExportInformation exportInformation = new ExportInformation(null, new IdOnlyContainerResource(photosetsId));
// make lots of photos and add them to PhotoList (also adding pagination information)
int numPhotos = 4;
PhotoList<Photo> photosList = new PhotoList<>();
for (int i = 0; i < numPhotos; i++) {
photosList.add(FlickrTestUtils.initializePhoto("title" + 1, "url" + i, "description" + i, MEDIA_TYPE));
}
photosList.setPage(page);
photosList.setPages(page + 1);
when(photosetsInterface.getPhotos(anyString(), anySet(), anyInt(), anyInt(), anyInt())).thenReturn(photosList);
// run test
FlickrPhotosExporter exporter = new FlickrPhotosExporter(flickr);
ExportResult<PhotosContainerResource> result = exporter.export(UUID.randomUUID(), new TokenSecretAuthData("token", "secret"), exportInformation);
assertThat(result.getExportedData().getPhotos().size()).isEqualTo(numPhotos);
assertThat(result.getExportedData().getAlbums()).isEmpty();
ContinuationData continuationData = (ContinuationData) result.getContinuationData();
assertThat(continuationData.getContainerResources()).isEmpty();
assertThat(((IntPaginationToken) continuationData.getPaginationData()).getStart()).isEqualTo(page + 1);
}
use of com.flickr4java.flickr.photos.Photo in project data-transfer-project by google.
the class FlickrTestUtils method initializePhoto.
public static Photo initializePhoto(String title, String url, String description, String mediaType) {
Photo photo = new Photo();
photo.setTitle(title);
photo.setDescription(description);
photo.setOriginalFormat(mediaType);
Size size = new Size();
size.setSource(url);
size.setLabel(Size.ORIGINAL);
photo.setSizes(Collections.singletonList(size));
return photo;
}
Aggregations