albumId = (String) parentReference.get("id"); String parentName = (String) parentReference.get("name"); PhotoAlbum album = new PhotoAlbum(albumId, parentName, ""); albums.add(album);
private void importAlbums(Collection<PhotoAlbum> albums, TempPhotosData tempPhotosData) { for (PhotoAlbum album : albums) { tempPhotosData.addTempAlbumMapping(album.getId(), album); } }
photosetsInterface.create(COPY_PREFIX + album.getName(), album.getDescription(), photoId);
ContinuationData continuationData = new ContinuationData(null); for (PhotoAlbum album : photosContainerResource.getAlbums()) { continuationData.addContainerResource(new IdOnlyContainerResource(album.getId()));
new PhotoAlbum( googleAlbum.getId(), googleAlbum.getTitle(),
@VisibleForTesting void importSingleAlbum(UUID jobId, TokensAndUrlAuthData authData, PhotoAlbum inputAlbum) throws IOException { // Set up album GoogleAlbum googleAlbum = new GoogleAlbum(); googleAlbum.setTitle(COPY_PREFIX + inputAlbum.getName()); GoogleAlbum responseAlbum = getOrCreatePhotosInterface(authData).createAlbum(googleAlbum); TempPhotosData tempPhotosData = jobStore.findData(jobId, TEMP_PHOTOS_KEY, TempPhotosData.class); if (tempPhotosData == null) { tempPhotosData = new TempPhotosData(jobId); jobStore.create(jobId, TEMP_PHOTOS_KEY, tempPhotosData); } tempPhotosData.addAlbumId(inputAlbum.getId(), responseAlbum.getId()); jobStore.update(jobId, TEMP_PHOTOS_KEY, tempPhotosData); }
private ExportResult<PhotosContainerResource> exportPhotos(TokensAndUrlAuthData authData, Optional<PaginationData> pageData) { Preconditions.checkNotNull(authData); MediaResponse response; try { response = makeRequest(MEDIA_URL, MediaResponse.class, authData); } catch (IOException e) { return new ExportResult<>(e); } List<PhotoModel> photos = new ArrayList<>(); // TODO: check out paging. for (MediaFeedData photo : response.getData()) { // TODO json mapping is broken. String photoId = photo.getId(); String url = photo.getImages().getStandardResolution().getUrl(); String text = (photo.getCaption() != null) ? photo.getCaption().getText() : null; photos.add(new PhotoModel("Instagram photo: " + photoId, url, text, null, null, FAKE_ALBUM_ID, false)); } List<PhotoAlbum> albums = new ArrayList<>(); if (!photos.isEmpty() && !pageData.isPresent()) { albums.add( new PhotoAlbum( FAKE_ALBUM_ID, "Imported Instagram Photos", "Photos imported from instagram")); } return new ExportResult<>(ResultType.END, new PhotosContainerResource(albums, photos)); }
@VisibleForTesting void importSingleAlbum(UUID jobId, PhotoAlbum inputAlbum, SmugMugInterface smugMugInterface) throws IOException { SmugMugAlbumResponse response = smugMugInterface.createAlbum(inputAlbum.getName()); // Put new album ID in job store so photos can be assigned to correct album // TODO(olsona): thread safety! TempPhotosData tempPhotosData = jobStore.findData(jobId, createCacheKey(), TempPhotosData.class); if (tempPhotosData == null) { tempPhotosData = new TempPhotosData(jobId); jobStore.create(jobId, createCacheKey(), tempPhotosData); } tempPhotosData.addAlbumId(inputAlbum.getId(), response.getUri()); jobStore.update(jobId, createCacheKey(), tempPhotosData); }
new PhotoAlbum(photoSet.getId(), photoSet.getTitle(), photoSet.getDescription()));
Assert.assertEquals("folder1", album.getId()); Assert.assertEquals("Test Picture Folder", album.getName()); Assert.assertEquals("image1", photo1.getDataId()); Assert.assertEquals("image/png", photo1.getMediaType()); Assert.assertEquals(album.getId(), photo1.getAlbumId()); Assert.assertEquals("image2", photo2.getDataId()); Assert.assertEquals("image/jpeg", photo2.getMediaType()); Assert.assertEquals(album.getId(), photo2.getAlbumId());
for (SmugMugAlbum album : albumsResponse.getAlbums()) { if (!album.getPrivacy().equals(PRIVATE_ALBUM)) { albumsList.add(new PhotoAlbum(album.getWebUri(), album.getName(), album.getDescription())); continuationData.addContainerResource(new IdOnlyContainerResource(album.getUri()));
@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); } }
private ExportResult<PhotosContainerResource> exportAlbums( TokensAndUrlAuthData authData, Optional<StringPaginationToken> paginationData) { Optional<String> paginationToken = stripTokenPrefix(paginationData, ALBUM_TOKEN_PREFIX); ArrayList<PhotoAlbum> exportAlbums = new ArrayList<>(); // Get albums Connection<Album> connection = getOrCreatePhotosInterface(authData).getAlbums(paginationToken); PaginationData nextPageData = null; String token = connection.getAfterCursor(); if (!Strings.isNullOrEmpty(token)) { nextPageData = new StringPaginationToken(ALBUM_TOKEN_PREFIX + token); } ContinuationData continuationData = new ContinuationData(nextPageData); List<Album> albums = connection.getData(); for (Album album : albums) { exportAlbums.add(new PhotoAlbum(album.getId(), album.getName(), album.getDescription())); continuationData.addContainerResource(new IdOnlyContainerResource(album.getId())); } return new ExportResult<>( ExportResult.ResultType.CONTINUE, new PhotosContainerResource(exportAlbums, null), continuationData); }
@Test public void exportAlbum() throws IOException { // Set up String albumName = "Album Name"; String albumDescription = "Album description"; PhotoAlbum albumModel = new PhotoAlbum(OLD_ALBUM_ID, albumName, albumDescription); GoogleAlbum responseAlbum = new GoogleAlbum(); responseAlbum.setId(NEW_ALBUM_ID); when(googlePhotosInterface.createAlbum(Matchers.any(GoogleAlbum.class))) .thenReturn(responseAlbum); // Run test googlePhotosImporter.importSingleAlbum(uuid, null, albumModel); // Check results ArgumentCaptor<GoogleAlbum> albumArgumentCaptor = ArgumentCaptor.forClass(GoogleAlbum.class); verify(googlePhotosInterface).createAlbum(albumArgumentCaptor.capture()); assertEquals(albumArgumentCaptor.getValue().getTitle(), "Copy of " + albumName); assertNull(albumArgumentCaptor.getValue().getId()); TempPhotosData tempPhotosData = jobStore.findData(uuid, "tempPhotosData", TempPhotosData.class); assertEquals(tempPhotosData.lookupNewAlbumId(OLD_ALBUM_ID), NEW_ALBUM_ID); }
@Test public void testSpecifiedAlbums() { ExportResult<PhotosContainerResource> result = facebookPhotosExporter.export( uuid, new TokensAndUrlAuthData("accessToken", null, null), Optional.of( new ExportInformation( new StringPaginationToken(PHOTO_TOKEN_PREFIX), new PhotosContainerResource( Lists.newArrayList(new PhotoAlbum(ALBUM_ID, ALBUM_NAME, ALBUM_DESCRIPTION)), new ArrayList<>())))); assertEquals(ExportResult.ResultType.CONTINUE, result.getType()); PhotosContainerResource exportedData = result.getExportedData(); assertEquals(1, exportedData.getAlbums().size()); assertEquals( new PhotoAlbum(ALBUM_ID, ALBUM_NAME, ALBUM_DESCRIPTION), exportedData.getAlbums().toArray()[0]); assertNull((result.getContinuationData().getPaginationData())); assertThat(result.getContinuationData().getContainerResources()) .contains(new IdOnlyContainerResource(ALBUM_ID)); }
Collection<PhotoAlbum> albums = result.getExportedData().getAlbums(); assertThat(albums.size()).isEqualTo(1); assertThat(albums).containsExactly(new PhotoAlbum("photosetId", "title", "description"));
new PhotosContainerResource( Lists.newArrayList( new PhotoAlbum("album_id", "album name", "album description")), null))) .setCreatedTimestamp(date)
@Test public void testExportAlbum() { ExportResult<PhotosContainerResource> result = facebookPhotosExporter.export( uuid, new TokensAndUrlAuthData("accessToken", null, null), Optional.empty()); assertEquals(ExportResult.ResultType.CONTINUE, result.getType()); PhotosContainerResource exportedData = result.getExportedData(); assertEquals(1, exportedData.getAlbums().size()); assertEquals( new PhotoAlbum(ALBUM_ID, ALBUM_NAME, ALBUM_DESCRIPTION), exportedData.getAlbums().toArray()[0]); assertNull(result.getContinuationData().getPaginationData()); assertThat(result.getContinuationData().getContainerResources()) .contains(new IdOnlyContainerResource(ALBUM_ID)); }