Search in sources :

Example 1 with MediaItemSearchResponse

use of org.datatransferproject.datatransfer.google.mediaModels.MediaItemSearchResponse in project data-transfer-project by google.

the class GooglePhotosExporterTest method populateContainedPhotosList.

@Test
public void populateContainedPhotosList() throws IOException, InvalidTokenException, PermissionDeniedException {
    // Set up an album with two photos
    setUpSingleAlbum();
    when(albumListResponse.getNextPageToken()).thenReturn(null);
    MediaItemSearchResponse albumMediaResponse = mock(MediaItemSearchResponse.class);
    GoogleMediaItem firstPhoto = setUpSinglePhoto(IMG_URI, PHOTO_ID);
    String secondUri = "second uri";
    String secondId = "second id";
    GoogleMediaItem secondPhoto = setUpSinglePhoto(secondUri, secondId);
    when(photosInterface.listMediaItems(eq(Optional.of(ALBUM_ID)), any(Optional.class))).thenReturn(albumMediaResponse);
    when(albumMediaResponse.getMediaItems()).thenReturn(new GoogleMediaItem[] { firstPhoto, secondPhoto });
    when(albumMediaResponse.getNextPageToken()).thenReturn(null);
    // Run test
    googlePhotosExporter.populateContainedPhotosList(uuid, null);
    // Check contents of job store
    ArgumentCaptor<InputStream> inputStreamArgumentCaptor = ArgumentCaptor.forClass(InputStream.class);
    verify(jobStore).create(eq(uuid), eq("tempPhotosData"), inputStreamArgumentCaptor.capture());
    TempPhotosData tempPhotosData = new ObjectMapper().readValue(inputStreamArgumentCaptor.getValue(), TempPhotosData.class);
    assertThat(tempPhotosData.lookupContainedPhotoIds()).containsExactly(PHOTO_ID, secondId);
}
Also used : TempPhotosData(org.datatransferproject.spi.transfer.types.TempPhotosData) Optional(java.util.Optional) InputStream(java.io.InputStream) GoogleMediaItem(org.datatransferproject.datatransfer.google.mediaModels.GoogleMediaItem) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MediaItemSearchResponse(org.datatransferproject.datatransfer.google.mediaModels.MediaItemSearchResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 2 with MediaItemSearchResponse

use of org.datatransferproject.datatransfer.google.mediaModels.MediaItemSearchResponse in project data-transfer-project by google.

the class GoogleVideosExporter method exportVideos.

@VisibleForTesting
ExportResult<VideosContainerResource> exportVideos(TokensAndUrlAuthData authData, Optional<StringPaginationToken> paginationData) throws IOException {
    Optional<String> paginationToken = paginationData.map(StringPaginationToken::getToken);
    MediaItemSearchResponse mediaItemSearchResponse = getOrCreateVideosInterface(authData).listVideoItems(paginationToken);
    PaginationData nextPageData = null;
    if (!Strings.isNullOrEmpty(mediaItemSearchResponse.getNextPageToken())) {
        nextPageData = new StringPaginationToken(mediaItemSearchResponse.getNextPageToken());
    }
    ContinuationData continuationData = new ContinuationData(nextPageData);
    VideosContainerResource containerResource = null;
    GoogleMediaItem[] mediaItems = mediaItemSearchResponse.getMediaItems();
    if (mediaItems != null && mediaItems.length > 0) {
        List<VideoModel> videos = convertVideosList(mediaItems);
        containerResource = new VideosContainerResource(null, videos);
    }
    ResultType resultType = ResultType.CONTINUE;
    if (nextPageData == null) {
        resultType = ResultType.END;
    }
    return new ExportResult<>(resultType, containerResource, continuationData);
}
Also used : PaginationData(org.datatransferproject.types.common.PaginationData) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) ResultType(org.datatransferproject.spi.transfer.provider.ExportResult.ResultType) VideoModel(org.datatransferproject.types.common.models.videos.VideoModel) MediaItemSearchResponse(org.datatransferproject.datatransfer.google.mediaModels.MediaItemSearchResponse) VideosContainerResource(org.datatransferproject.types.common.models.videos.VideosContainerResource) GoogleMediaItem(org.datatransferproject.datatransfer.google.mediaModels.GoogleMediaItem) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with MediaItemSearchResponse

use of org.datatransferproject.datatransfer.google.mediaModels.MediaItemSearchResponse in project data-transfer-project by google.

the class GooglePhotosExporterTest method setup.

@Before
public void setup() throws IOException, InvalidTokenException, PermissionDeniedException {
    GoogleCredentialFactory credentialFactory = mock(GoogleCredentialFactory.class);
    jobStore = mock(TemporaryPerJobDataStore.class);
    when(jobStore.getStream(any(), anyString())).thenReturn(mock(InputStreamWrapper.class));
    photosInterface = mock(GooglePhotosInterface.class);
    albumListResponse = mock(AlbumListResponse.class);
    mediaItemSearchResponse = mock(MediaItemSearchResponse.class);
    Monitor monitor = mock(Monitor.class);
    googlePhotosExporter = new GooglePhotosExporter(credentialFactory, jobStore, new JacksonFactory(), photosInterface, monitor);
    when(photosInterface.listAlbums(any(Optional.class))).thenReturn(albumListResponse);
    when(photosInterface.listMediaItems(any(Optional.class), any(Optional.class))).thenReturn(mediaItemSearchResponse);
    verifyNoInteractions(credentialFactory);
}
Also used : TemporaryPerJobDataStore(org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore) AlbumListResponse(org.datatransferproject.datatransfer.google.mediaModels.AlbumListResponse) InputStreamWrapper(org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore.InputStreamWrapper) Monitor(org.datatransferproject.api.launcher.Monitor) Optional(java.util.Optional) GoogleCredentialFactory(org.datatransferproject.datatransfer.google.common.GoogleCredentialFactory) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory) MediaItemSearchResponse(org.datatransferproject.datatransfer.google.mediaModels.MediaItemSearchResponse) Before(org.junit.Before)

Example 4 with MediaItemSearchResponse

use of org.datatransferproject.datatransfer.google.mediaModels.MediaItemSearchResponse in project data-transfer-project by google.

the class GooglePhotosExporterTest method onlyExportAlbumlessPhoto.

@Test
public /* Tests that when there is no album information passed along to exportPhotos, only albumless
  photos are exported.
  */
void onlyExportAlbumlessPhoto() throws IOException, InvalidTokenException, PermissionDeniedException {
    // Set up - two photos will be returned by a media item search without an album id, but one of
    // them will have already been put into the list of contained photos
    String containedPhotoUri = "contained photo uri";
    String containedPhotoId = "contained photo id";
    GoogleMediaItem containedPhoto = setUpSinglePhoto(containedPhotoUri, containedPhotoId);
    String albumlessPhotoUri = "albumless photo uri";
    String albumlessPhotoId = "albumless photo id";
    GoogleMediaItem albumlessPhoto = setUpSinglePhoto(albumlessPhotoUri, albumlessPhotoId);
    MediaItemSearchResponse mediaItemSearchResponse = mock(MediaItemSearchResponse.class);
    when(photosInterface.listMediaItems(eq(Optional.empty()), eq(Optional.empty()))).thenReturn(mediaItemSearchResponse);
    when(mediaItemSearchResponse.getMediaItems()).thenReturn(new GoogleMediaItem[] { containedPhoto, albumlessPhoto });
    when(mediaItemSearchResponse.getNextPageToken()).thenReturn(null);
    TempPhotosData tempPhotosData = new TempPhotosData(uuid);
    tempPhotosData.addContainedPhotoId(containedPhotoId);
    InputStream stream = GooglePhotosExporter.convertJsonToInputStream(tempPhotosData);
    when(jobStore.getStream(uuid, "tempPhotosData")).thenReturn(new InputStreamWrapper(stream));
    // Run test
    ExportResult<PhotosContainerResource> result = googlePhotosExporter.exportPhotos(null, Optional.empty(), Optional.empty(), uuid);
    // Check results
    assertThat(result.getExportedData().getPhotos().stream().map(PhotoModel::getFetchableUrl).collect(Collectors.toList())).containsExactly(// download
    albumlessPhotoUri + "=d");
}
Also used : PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) TempPhotosData(org.datatransferproject.spi.transfer.types.TempPhotosData) InputStreamWrapper(org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore.InputStreamWrapper) InputStream(java.io.InputStream) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) GoogleMediaItem(org.datatransferproject.datatransfer.google.mediaModels.GoogleMediaItem) MediaItemSearchResponse(org.datatransferproject.datatransfer.google.mediaModels.MediaItemSearchResponse) Test(org.junit.Test)

Example 5 with MediaItemSearchResponse

use of org.datatransferproject.datatransfer.google.mediaModels.MediaItemSearchResponse in project data-transfer-project by google.

the class GoogleVideosExporterTest method setup.

@Before
public void setup() throws IOException {
    GoogleCredentialFactory credentialFactory = mock(GoogleCredentialFactory.class);
    jobStore = mock(TemporaryPerJobDataStore.class);
    videosInterface = mock(GoogleVideosInterface.class);
    albumListResponse = mock(AlbumListResponse.class);
    mediaItemSearchResponse = mock(MediaItemSearchResponse.class);
    googleVideosExporter = new GoogleVideosExporter(credentialFactory, videosInterface);
    when(videosInterface.listVideoItems(any(Optional.class))).thenReturn(mediaItemSearchResponse);
    verifyNoInteractions(credentialFactory);
}
Also used : TemporaryPerJobDataStore(org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore) AlbumListResponse(org.datatransferproject.datatransfer.google.mediaModels.AlbumListResponse) Optional(java.util.Optional) GoogleCredentialFactory(org.datatransferproject.datatransfer.google.common.GoogleCredentialFactory) MediaItemSearchResponse(org.datatransferproject.datatransfer.google.mediaModels.MediaItemSearchResponse) Before(org.junit.Before)

Aggregations

MediaItemSearchResponse (org.datatransferproject.datatransfer.google.mediaModels.MediaItemSearchResponse)7 GoogleMediaItem (org.datatransferproject.datatransfer.google.mediaModels.GoogleMediaItem)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 InputStream (java.io.InputStream)3 Optional (java.util.Optional)3 AlbumListResponse (org.datatransferproject.datatransfer.google.mediaModels.AlbumListResponse)3 TempPhotosData (org.datatransferproject.spi.transfer.types.TempPhotosData)3 GoogleCredentialFactory (org.datatransferproject.datatransfer.google.common.GoogleCredentialFactory)2 TemporaryPerJobDataStore (org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore)2 InputStreamWrapper (org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore.InputStreamWrapper)2 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)2 ResultType (org.datatransferproject.spi.transfer.provider.ExportResult.ResultType)2 ContinuationData (org.datatransferproject.spi.transfer.types.ContinuationData)2 PaginationData (org.datatransferproject.types.common.PaginationData)2 StringPaginationToken (org.datatransferproject.types.common.StringPaginationToken)2 PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)2 Before (org.junit.Before)2 Test (org.junit.Test)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1