@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; PhotoModel that = (PhotoModel) o; return Objects.equal(getTitle(), that.getTitle()) && Objects.equal(getFetchableUrl(), that.getFetchableUrl()) && Objects.equal(getDescription(), that.getDescription()) && Objects.equal(getMediaType(), that.getMediaType()) && Objects.equal(getDataId(), that.getDataId()) && Objects.equal(getAlbumId(), that.getAlbumId()); } }
private void importAlbums(Collection<PhotoAlbum> albums, TempPhotosData tempPhotosData) { for (PhotoAlbum album : albums) { tempPhotosData.addTempAlbumMapping(album.getId(), album); } }
@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); } }
albumId = (String) parentReference.get("id"); String parentName = (String) parentReference.get("name"); PhotoAlbum album = new PhotoAlbum(albumId, parentName, ""); albums.add(album); PhotoModel photoModel = new PhotoModel(name, null, "", mimeType, id, albumId, false); return new PhotosContainerResource(albums, photoModels);
@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); }
private String uploadPhoto(PhotoModel photo) throws IOException, FlickrException { BufferedInputStream inStream = imageStreamProvider.get(photo.getFetchableUrl()); UploadMetaData uploadMetaData = new UploadMetaData() .setAsync(false) .setPublicFlag(false) .setFriendFlag(false) .setFamilyFlag(false) .setTitle(COPY_PREFIX + photo.getTitle()) .setDescription(photo.getDescription()); return uploader.upload(inStream, uploadMetaData); }
@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)); }
@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]); }
@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); }
private void importSinglePhoto(UUID id, PhotoModel photo) throws FlickrException, IOException { String photoId = uploadPhoto(photo); String oldAlbumId = photo.getAlbumId(); photosetsInterface.create(COPY_PREFIX + album.getName(), album.getDescription(), photoId);
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); }
@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"); }
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, 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); }
@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); }
@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, 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; }
@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; }