Search in sources :

Example 6 with GoogleAlbum

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

the class GooglePhotosImporterTest method importAlbum.

@Test
public void importAlbum() throws Exception {
    // 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);
    Mockito.when(googlePhotosInterface.createAlbum(any(GoogleAlbum.class))).thenReturn(responseAlbum);
    // Run test
    googlePhotosImporter.importSingleAlbum(uuid, null, albumModel);
    // Check results
    ArgumentCaptor<GoogleAlbum> albumArgumentCaptor = ArgumentCaptor.forClass(GoogleAlbum.class);
    Mockito.verify(googlePhotosInterface).createAlbum(albumArgumentCaptor.capture());
    assertEquals(albumArgumentCaptor.getValue().getTitle(), albumName);
    assertNull(albumArgumentCaptor.getValue().getId());
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) GoogleAlbum(org.datatransferproject.datatransfer.google.mediaModels.GoogleAlbum) Test(org.junit.Test)

Example 7 with GoogleAlbum

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

the class GooglePhotosExporter method exportPhotosContainer.

private ExportResult<PhotosContainerResource> exportPhotosContainer(PhotosContainerResource container, TokensAndUrlAuthData authData) throws IOException, InvalidTokenException, PermissionDeniedException {
    ImmutableList.Builder<PhotoAlbum> albumBuilder = ImmutableList.builder();
    ImmutableList.Builder<PhotoModel> photosBuilder = ImmutableList.builder();
    List<IdOnlyContainerResource> subResources = new ArrayList<>();
    for (PhotoAlbum album : container.getAlbums()) {
        GoogleAlbum googleAlbum = getOrCreatePhotosInterface(authData).getAlbum(album.getId());
        albumBuilder.add(new PhotoAlbum(googleAlbum.getId(), googleAlbum.getTitle(), null));
        // Adding subresources tells the framework to recall export to get all the photos
        subResources.add(new IdOnlyContainerResource(googleAlbum.getId()));
    }
    for (PhotoModel photo : container.getPhotos()) {
        GoogleMediaItem googleMediaItem = getOrCreatePhotosInterface(authData).getMediaItem(photo.getDataId());
        photosBuilder.add(convertToPhotoModel(Optional.empty(), googleMediaItem));
    }
    PhotosContainerResource photosContainerResource = new PhotosContainerResource(albumBuilder.build(), photosBuilder.build());
    ContinuationData continuationData = new ContinuationData(null);
    subResources.forEach(resource -> continuationData.addContainerResource(resource));
    return new ExportResult<>(ResultType.CONTINUE, photosContainerResource, continuationData);
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) PhotoModel(org.datatransferproject.types.common.models.photos.PhotoModel) ArrayList(java.util.ArrayList) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) GoogleMediaItem(org.datatransferproject.datatransfer.google.mediaModels.GoogleMediaItem) GoogleAlbum(org.datatransferproject.datatransfer.google.mediaModels.GoogleAlbum) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult)

Example 8 with GoogleAlbum

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

the class GooglePhotosExporter method populateContainedPhotosList.

/**
 * Method for storing a list of all photos that are already contained in albums
 */
@VisibleForTesting
void populateContainedPhotosList(UUID jobId, TokensAndUrlAuthData authData) throws IOException, InvalidTokenException, PermissionDeniedException {
    // This method is only called once at the beginning of the transfer, so we can start by
    // initializing a new TempPhotosData to be store in the job store.
    TempPhotosData tempPhotosData = new TempPhotosData(jobId);
    String albumToken = null;
    AlbumListResponse albumListResponse;
    MediaItemSearchResponse containedMediaSearchResponse;
    do {
        albumListResponse = getOrCreatePhotosInterface(authData).listAlbums(Optional.ofNullable(albumToken));
        if (albumListResponse.getAlbums() != null) {
            for (GoogleAlbum album : albumListResponse.getAlbums()) {
                String albumId = album.getId();
                String photoToken = null;
                do {
                    containedMediaSearchResponse = getOrCreatePhotosInterface(authData).listMediaItems(Optional.of(albumId), Optional.ofNullable(photoToken));
                    if (containedMediaSearchResponse.getMediaItems() != null) {
                        for (GoogleMediaItem mediaItem : containedMediaSearchResponse.getMediaItems()) {
                            tempPhotosData.addContainedPhotoId(mediaItem.getId());
                        }
                    }
                    photoToken = containedMediaSearchResponse.getNextPageToken();
                } while (photoToken != null);
            }
        }
        albumToken = albumListResponse.getNextPageToken();
    } while (albumToken != null);
    // TODO: if we see complaints about objects being too large for JobStore in other places, we
    // should consider putting logic in JobStore itself to handle it
    InputStream stream = convertJsonToInputStream(tempPhotosData);
    jobStore.create(jobId, createCacheKey(), stream);
}
Also used : TempPhotosData(org.datatransferproject.spi.transfer.types.TempPhotosData) AlbumListResponse(org.datatransferproject.datatransfer.google.mediaModels.AlbumListResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) GoogleMediaItem(org.datatransferproject.datatransfer.google.mediaModels.GoogleMediaItem) GoogleAlbum(org.datatransferproject.datatransfer.google.mediaModels.GoogleAlbum) MediaItemSearchResponse(org.datatransferproject.datatransfer.google.mediaModels.MediaItemSearchResponse) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

GoogleAlbum (org.datatransferproject.datatransfer.google.mediaModels.GoogleAlbum)8 PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 Test (org.junit.Test)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 ArrayList (java.util.ArrayList)2 LocalJobStore (org.datatransferproject.cloud.local.LocalJobStore)2 AlbumListResponse (org.datatransferproject.datatransfer.google.mediaModels.AlbumListResponse)2 GoogleMediaItem (org.datatransferproject.datatransfer.google.mediaModels.GoogleMediaItem)2 JobStore (org.datatransferproject.spi.cloud.storage.JobStore)2 PortabilityJob (org.datatransferproject.spi.cloud.types.PortabilityJob)2 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)2 ContinuationData (org.datatransferproject.spi.transfer.types.ContinuationData)2 IdOnlyContainerResource (org.datatransferproject.types.common.models.IdOnlyContainerResource)2 PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)2 ImmutableList (com.google.common.collect.ImmutableList)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 MediaItemSearchResponse (org.datatransferproject.datatransfer.google.mediaModels.MediaItemSearchResponse)1 ResultType (org.datatransferproject.spi.transfer.provider.ExportResult.ResultType)1