Search in sources :

Example 1 with UploadMetaData

use of com.flickr4java.flickr.uploader.UploadMetaData in project data-transfer-project by google.

the class FlickrPhotoService method uploadPhoto.

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);
}
Also used : BufferedInputStream(java.io.BufferedInputStream) UploadMetaData(com.flickr4java.flickr.uploader.UploadMetaData)

Example 2 with UploadMetaData

use of com.flickr4java.flickr.uploader.UploadMetaData in project data-transfer-project by google.

the class FlickrPhotosImporter method uploadPhoto.

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);
}
Also used : BufferedInputStream(java.io.BufferedInputStream) UploadMetaData(com.flickr4java.flickr.uploader.UploadMetaData)

Example 3 with UploadMetaData

use of com.flickr4java.flickr.uploader.UploadMetaData in project data-transfer-project by google.

the class FlickrPhotosImporterTest method importStoresAlbumInJobStore.

@Test
public void importStoresAlbumInJobStore() throws FlickrException, IOException {
    UUID jobId = UUID.randomUUID();
    PhotosContainerResource photosContainerResource = new PhotosContainerResource(Collections.singletonList(PHOTO_ALBUM), Collections.singletonList(PHOTO_MODEL));
    // Setup Mock
    when(user.getId()).thenReturn("userId");
    when(authInterface.checkToken(any(Token.class))).thenReturn(auth);
    when(flickr.getPhotosetsInterface()).thenReturn(photosetsInterface);
    when(flickr.getUploader()).thenReturn(uploader);
    when(flickr.getAuthInterface()).thenReturn(authInterface);
    when(imageStreamProvider.get(FETCHABLE_URL)).thenReturn(bufferedInputStream);
    when(uploader.upload(any(BufferedInputStream.class), any(UploadMetaData.class))).thenReturn(FLICKR_PHOTO_ID);
    String flickrAlbumTitle = FlickrPhotosImporter.COPY_PREFIX + ALBUM_NAME;
    Photoset photoset = FlickrTestUtils.initializePhotoset(FLICKR_ALBUM_ID, ALBUM_DESCRIPTION, FLICKR_PHOTO_ID);
    when(photosetsInterface.create(flickrAlbumTitle, ALBUM_DESCRIPTION, FLICKR_PHOTO_ID)).thenReturn(photoset);
    // Run test
    FlickrPhotosImporter importer = new FlickrPhotosImporter(flickr, jobStore, imageStreamProvider);
    ImportResult result = importer.importItem(jobId, new TokenSecretAuthData("token", "secret"), photosContainerResource);
    // Verify that the image stream provider got the correct URL and that the correct info was uploaded
    verify(imageStreamProvider).get(FETCHABLE_URL);
    ArgumentCaptor<UploadMetaData> uploadMetaDataArgumentCaptor = ArgumentCaptor.forClass(UploadMetaData.class);
    verify(uploader).upload(eq(bufferedInputStream), uploadMetaDataArgumentCaptor.capture());
    UploadMetaData actualUploadMetaData = uploadMetaDataArgumentCaptor.getValue();
    assertThat(actualUploadMetaData.getTitle()).isEqualTo(FlickrPhotosImporter.COPY_PREFIX + PHOTO_TITLE);
    assertThat(actualUploadMetaData.getDescription()).isEqualTo(PHOTO_DESCRIPTION);
    // Verify the photosets interface got the command to create the correct album
    verify(photosetsInterface).create(flickrAlbumTitle, ALBUM_DESCRIPTION, FLICKR_PHOTO_ID);
    // Check contents of JobStore
    TempPhotosData tempPhotosData = jobStore.findData(TempPhotosData.class, jobId);
    assertThat(tempPhotosData).isNotNull();
    String expectedAlbumKey = FlickrPhotosImporter.CACHE_ALBUM_METADATA_PREFIX + ALBUM_ID;
    assertThat(tempPhotosData.lookupAlbum(expectedAlbumKey)).isNotNull();
    assertThat(tempPhotosData.lookupAlbum(expectedAlbumKey)).isEqualTo(PHOTO_ALBUM);
    assertThat(tempPhotosData.lookupNewAlbumId(ALBUM_ID)).isEqualTo(FLICKR_ALBUM_ID);
}
Also used : PhotosContainerResource(org.dataportabilityproject.types.transfer.models.photos.PhotosContainerResource) TempPhotosData(org.dataportabilityproject.spi.transfer.types.TempPhotosData) ImportResult(org.dataportabilityproject.spi.transfer.provider.ImportResult) TokenSecretAuthData(org.dataportabilityproject.types.transfer.auth.TokenSecretAuthData) BufferedInputStream(java.io.BufferedInputStream) Photoset(com.flickr4java.flickr.photosets.Photoset) Token(org.scribe.model.Token) UploadMetaData(com.flickr4java.flickr.uploader.UploadMetaData) UUID(java.util.UUID) Test(org.junit.Test)

Example 4 with UploadMetaData

use of com.flickr4java.flickr.uploader.UploadMetaData in project data-transfer-project by google.

the class FlickrPhotoServiceTest method importStoresAlbumsInJobCache.

@Test
public void importStoresAlbumsInJobCache() throws IOException, FlickrException {
    // Set up input: a single photo album with a single photo
    PhotosModelWrapper wrapper = new PhotosModelWrapper(Collections.singletonList(PHOTO_ALBUM), Collections.singletonList(PHOTO_MODEL), new ContinuationInformation(null, null));
    // Set up mocks
    when(imageStreamProvider.get(FETCHABLE_URL)).thenReturn(bufferedInputStream);
    when(uploader.upload(any(BufferedInputStream.class), any(UploadMetaData.class))).thenReturn(FLICKR_PHOTO_ID);
    String flickrAlbumTitle = FlickrPhotoService.COPY_PREFIX + ALBUM_NAME;
    Photoset photoSet = initializePhotoset(FLICKR_ALBUM_ID, flickrAlbumTitle, ALBUM_DESCRIPTION);
    when(photosetsInterface.create(flickrAlbumTitle, ALBUM_DESCRIPTION, FLICKR_PHOTO_ID)).thenReturn(photoSet);
    // Run test
    photoService.importItem(wrapper);
    // Verify the image stream provider got the correct url
    verify(imageStreamProvider).get(FETCHABLE_URL);
    // Verify the correct photo information was uploaded
    ArgumentCaptor<UploadMetaData> uploadMetaDataArgumentCaptor = ArgumentCaptor.forClass(UploadMetaData.class);
    verify(uploader).upload(eq(bufferedInputStream), uploadMetaDataArgumentCaptor.capture());
    UploadMetaData actualUploadMetaData = uploadMetaDataArgumentCaptor.getValue();
    assertThat(actualUploadMetaData.getTitle()).isEqualTo(FlickrPhotoService.COPY_PREFIX + PHOTO_TITLE);
    assertThat(actualUploadMetaData.getDescription()).isEqualTo(PHOTO_DESCRIPTION);
    // Verify the photosets interface got the command to create the correct album
    verify(photosetsInterface).create(flickrAlbumTitle, ALBUM_DESCRIPTION, FLICKR_PHOTO_ID);
    // Check jobDataCache contents
    String expectedAlbumKey = FlickrPhotoService.CACHE_ALBUM_METADATA_PREFIX + ALBUM_ID;
    assertThat(jobDataCache.hasKey(expectedAlbumKey)).isTrue();
    assertThat(jobDataCache.getData(expectedAlbumKey, PhotoAlbum.class)).isEqualTo(PHOTO_ALBUM);
    assertThat(jobDataCache.getData(ALBUM_ID, String.class)).isEqualTo(FLICKR_ALBUM_ID);
}
Also used : ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) BufferedInputStream(java.io.BufferedInputStream) Photoset(com.flickr4java.flickr.photosets.Photoset) PhotosModelWrapper(org.dataportabilityproject.dataModels.photos.PhotosModelWrapper) UploadMetaData(com.flickr4java.flickr.uploader.UploadMetaData) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

UploadMetaData (com.flickr4java.flickr.uploader.UploadMetaData)4 BufferedInputStream (java.io.BufferedInputStream)4 Photoset (com.flickr4java.flickr.photosets.Photoset)2 Test (org.junit.Test)2 UUID (java.util.UUID)1 ContinuationInformation (org.dataportabilityproject.dataModels.ContinuationInformation)1 PhotosModelWrapper (org.dataportabilityproject.dataModels.photos.PhotosModelWrapper)1 ImportResult (org.dataportabilityproject.spi.transfer.provider.ImportResult)1 TempPhotosData (org.dataportabilityproject.spi.transfer.types.TempPhotosData)1 TokenSecretAuthData (org.dataportabilityproject.types.transfer.auth.TokenSecretAuthData)1 PhotosContainerResource (org.dataportabilityproject.types.transfer.models.photos.PhotosContainerResource)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Token (org.scribe.model.Token)1