albumId = (String) parentReference.get("id"); String parentName = (String) parentReference.get("name"); PhotoAlbum album = new PhotoAlbum(albumId, parentName, ""); albums.add(album);
new PhotoAlbum( googleAlbum.getId(), googleAlbum.getTitle(),
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)); }
new PhotoAlbum(photoSet.getId(), photoSet.getTitle(), photoSet.getDescription()));
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()));
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 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 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)); }