albums.add(album); PhotoModel photoModel = new PhotoModel(name, null, "", mimeType, id, albumId, false);
private PhotoModel convertToPhotoModel(Optional<String> albumId, GoogleMediaItem mediaItem) { Preconditions.checkArgument(mediaItem.getMediaMetadata().getPhoto() != null); return new PhotoModel( "", // TODO: no title? mediaItem.getBaseUrl() + "=d", mediaItem.getDescription(), mediaItem.getMimeType(), mediaItem.getId(), albumId.isPresent() ? albumId.get() : null, false); }
@VisibleForTesting static PhotoModel toCommonPhoto(Photo p, String albumId) { Preconditions.checkArgument( !Strings.isNullOrEmpty(p.getOriginalSize().getSource()), "Photo [" + p.getId() + "] has a null authUrl"); return new PhotoModel( p.getTitle(), p.getOriginalSize().getSource(), p.getDescription(), toMimeType(p.getOriginalFormat()), null, // TODO this needs to be provided albumId, false); }
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)); }
@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); } }
Preconditions.checkNotNull(photo.getImages().get(0).getSource()); exportPhotos.add( new PhotoModel( String.format("%s.jpg", photo.getId()), photo.getImages().get(0).getSource(),
new PhotoModel( title,
for (MediaEntity mediaEntity : status.getMediaEntities()) { photos.add( new PhotoModel( "Twitter Photo " + mediaEntity.getId(), mediaEntity.getMediaURL(),
@Test public void exportPhoto() throws IOException { // Set up PhotoModel photoModel = new PhotoModel(PHOTO_TITLE, IMG_URI, PHOTO_DESCRIPTION, JPEG_MEDIA_TYPE, null, OLD_ALBUM_ID, false); TempPhotosData tempPhotosData = new TempPhotosData(uuid); tempPhotosData.addAlbumId(OLD_ALBUM_ID, NEW_ALBUM_ID); jobStore.create(uuid, "tempPhotosData", tempPhotosData); // Run test googlePhotosImporter.importSinglePhoto(uuid, null, photoModel); // Check results verify(imageStreamProvider).get(IMG_URI); verify(googlePhotosInterface).uploadPhotoContent(inputStream); ArgumentCaptor<NewMediaItemUpload> uploadArgumentCaptor = ArgumentCaptor .forClass(NewMediaItemUpload.class); verify(googlePhotosInterface).createPhoto(uploadArgumentCaptor.capture()); assertEquals(uploadArgumentCaptor.getValue().getAlbumId(), NEW_ALBUM_ID); List<NewMediaItem> newMediaItems = uploadArgumentCaptor.getValue().getNewMediaItems(); assertEquals(newMediaItems.size(), 1); NewMediaItem mediaItem = newMediaItems.get(0); assertEquals(mediaItem.getSimpleMediaItem().getUploadToken(), UPLOAD_TOKEN); assertEquals(mediaItem.getDescription(), "Copy of " + PHOTO_DESCRIPTION); } }
@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]); }