@Override public int hashCode() { return Objects.hash(getAlbums(), getPhotos()); } }
@Override public ImportResult importItem( UUID jobId, TokensAndUrlAuthData authData, PhotosContainerResource data) throws IOException { if (data == null) { // Nothing to do return ImportResult.OK; } // Uploads album metadata if (data.getAlbums() != null && data.getAlbums().size() > 0) { for (PhotoAlbum album : data.getAlbums()) { importSingleAlbum(jobId, authData, album); } } // Uploads photos if (data.getPhotos() != null && data.getPhotos().size() > 0) { for (PhotoModel photo : data.getPhotos()) { importSinglePhoto(jobId, authData, photo); } } return ImportResult.OK; }
@Override public ImportResult importItem( UUID jobId, TokenAuthData authData, PhotosContainerResource resource) throws IOException { TempPhotoData photoData = jobStore.findData(jobId, createCacheKey(), TempPhotoData.class); if (photoData == null) { photoData = new TempPhotoData(jobId.toString()); jobStore.create(jobId, createCacheKey(), photoData); } for (PhotoAlbum album : resource.getAlbums()) { // Create a OneDrive folder and then save the id with the mapping data createOneDriveFolder(album, jobId, authData, photoData); } for (PhotoModel photoModel : resource.getPhotos()) { importPhoto(photoModel, jobId, authData, photoData); } return null; }
@Override public ImportResult importItem( UUID jobId, TokenSecretAuthData authData, PhotosContainerResource data) { try { SmugMugInterface smugMugInterface = getOrCreateSmugMugInterface(authData); for (PhotoAlbum album : data.getAlbums()) { importSingleAlbum(jobId, album, smugMugInterface); } for (PhotoModel photo : data.getPhotos()) { importSinglePhoto(jobId, photo, smugMugInterface); } } catch (IOException e) { monitor.severe(() -> "Error importing", e); return new ImportResult(e); } return ImportResult.OK; }
assertThat(result.getExportedData().getPhotos().stream().map(PhotoModel::getFetchableUrl) .collect(Collectors.toList())).containsExactly(albumlessPhotoUri + "=d"); // download
@Test public void exportPhotoFirstSet() throws IOException { setUpSingleAlbum(); when(albumListResponse.getNextPageToken()).thenReturn(null); GoogleMediaItem mediaItem = setUpSinglePhoto(IMG_URI, PHOTO_ID); when(mediaItemSearchResponse.getMediaItems()).thenReturn(new GoogleMediaItem[]{mediaItem}); when(mediaItemSearchResponse.getNextPageToken()).thenReturn(PHOTO_TOKEN); IdOnlyContainerResource idOnlyContainerResource = new IdOnlyContainerResource(ALBUM_ID); ExportResult<PhotosContainerResource> result = googlePhotosExporter .exportPhotos(null, Optional.of(idOnlyContainerResource), Optional.empty(), uuid); // Check results // Verify correct methods were called verify(photosInterface).listMediaItems(Optional.of(ALBUM_ID), Optional.empty()); verify(mediaItemSearchResponse).getMediaItems(); // Check pagination ContinuationData continuationData = result.getContinuationData(); StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData(); assertThat(paginationToken.getToken()).isEqualTo(PHOTO_TOKEN_PREFIX + PHOTO_TOKEN); // Check albums field of container (should be empty) Collection<PhotoAlbum> actualAlbums = result.getExportedData().getAlbums(); assertThat(actualAlbums).isEmpty(); // Check photos field of container Collection<PhotoModel> actualPhotos = result.getExportedData().getPhotos(); assertThat(actualPhotos.stream().map(PhotoModel::getFetchableUrl).collect(Collectors.toList())) .containsExactly(IMG_URI + "=d"); // for download assertThat(actualPhotos.stream().map(PhotoModel::getAlbumId).collect(Collectors.toList())) .containsExactly(ALBUM_ID); }
@Test public void verifySerializeDeserialize() throws Exception { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerSubtypes(PhotosContainerResource.class); List<PhotoAlbum> albums = ImmutableList.of(new PhotoAlbum("id1", "albumb1", "This is a fake albumb")); List<PhotoModel> photos = ImmutableList.of( new PhotoModel("Pic1", "http://fake.com/1.jpg", "A pic", "image/jpg", "p1", "id1", false), new PhotoModel( "Pic2", "https://fake.com/pic.png", "fine art", "image/png", "p2", "id1", false)); ContainerResource data = new PhotosContainerResource(albums, photos); String serialized = objectMapper.writeValueAsString(data); ContainerResource deserializedModel = objectMapper.readValue(serialized, ContainerResource.class); Truth.assertThat(deserializedModel).isNotNull(); Truth.assertThat(deserializedModel).isInstanceOf(PhotosContainerResource.class); PhotosContainerResource deserialized = (PhotosContainerResource) deserializedModel; Truth.assertThat(deserialized.getAlbums()).hasSize(1); Truth.assertThat(deserialized.getPhotos()).hasSize(2); } }
@Test public void testExportPhoto() { ExportResult<PhotosContainerResource> result = facebookPhotosExporter.export( uuid, new TokensAndUrlAuthData("accessToken", null, null), Optional.of(new ExportInformation(null, new IdOnlyContainerResource(ALBUM_ID)))); assertEquals(ExportResult.ResultType.END, result.getType()); PhotosContainerResource exportedData = result.getExportedData(); assertEquals(1, exportedData.getPhotos().size()); assertEquals( new PhotoModel( PHOTO_ID + ".jpg", PHOTO_SOURCE, PHOTO_NAME, "image/jpg", PHOTO_ID, ALBUM_ID, false), exportedData.getPhotos().toArray()[0]); }
Collection<PhotoModel> actualPhotos = result.getExportedData().getPhotos(); assertThat(actualPhotos).isEmpty();
assertThat(result.getExportedData().getPhotos()).isEmpty(); Collection<PhotoAlbum> albums = result.getExportedData().getAlbums(); assertThat(albums.size()).isEqualTo(1);
exporter.export( UUID.randomUUID(), new TokenSecretAuthData("token", "secret"), Optional.of(exportInformation)); assertThat(result.getExportedData().getPhotos().size()).isEqualTo(numPhotos); assertThat(result.getExportedData().getAlbums()).isEmpty();
Assert.assertEquals("Test Picture Folder", album.getName()); Assert.assertEquals(2, resource.getPhotos().size()); PhotoModel photo1 = resource.getPhotos().stream().filter(p -> "image1".equals(p.getDataId())) .findFirst().get(); Assert.assertEquals("testimage1.png", photo1.getTitle()); Assert.assertEquals(album.getId(), photo1.getAlbumId()); PhotoModel photo2 = resource.getPhotos().stream().filter(p -> "image2".equals(p.getDataId())) .findFirst().get(); Assert.assertEquals("testimage2.png", photo2.getTitle());
@Override public ImportResult importItem( UUID jobId, TokenSecretAuthData authData, PhotosContainerResource data) { Twitter twitterApi = TwitterApiWrapper.getInstance(appCredentials, authData); // Twitter doesn't support an 'Albums' concept, so that information is just lost. for (PhotoModel image : data.getPhotos()) { try { StatusUpdate update = new StatusUpdate(image.getDescription()); InputStreamContent content = new InputStreamContent(null, getImageAsStream(image.getFetchableUrl())); update.media(image.getTitle(), content.getInputStream()); twitterApi.tweets().updateStatus(update); } catch (IOException | TwitterException e) { monitor.severe(() -> "Error importing twitter photo", e); return new ImportResult(e); } } return new ImportResult(ResultType.OK); }