Search in sources :

Example 36 with PhotoAlbum

use of org.datatransferproject.types.common.models.photos.PhotoAlbum in project data-transfer-project by google.

the class ImgurPhotoExporterTest method testAlbumsExport.

@Test
public void testAlbumsExport() throws Exception {
    server.enqueue(new MockResponse().setBody(albumsResponse));
    // export albums
    ExportResult<PhotosContainerResource> result = exporter.export(UUID.randomUUID(), token, Optional.empty());
    PhotosContainerResource resource = result.getExportedData();
    assertThat(resource.getPhotos()).isEmpty();
    PhotoAlbum album1 = resource.getAlbums().stream().filter(album -> "albumId1".equals(album.getId())).findFirst().get();
    assertThat(album1.getName()).isEqualTo("Album 1");
    assertThat(album1.getDescription()).isEqualTo(null);
    PhotoAlbum album2 = resource.getAlbums().stream().filter(album -> "albumId2".equals(album.getId())).findFirst().get();
    assertThat(album2.getName()).isEqualTo("Album 2");
    assertThat(album2.getDescription()).isEqualTo("Description for Album 2");
    assertThat(resource.getAlbums()).containsExactly(album1, album2).inOrder();
}
Also used : MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) Test(org.junit.Test)

Example 37 with PhotoAlbum

use of org.datatransferproject.types.common.models.photos.PhotoAlbum in project data-transfer-project by google.

the class KoofrPhotosExporter method export.

@Override
public ExportResult<PhotosContainerResource> export(UUID jobId, TokensAndUrlAuthData authData, Optional<ExportInformation> exportInformation) throws CopyExceptionWithFailureReason {
    Preconditions.checkNotNull(authData);
    KoofrClient koofrClient = koofrClientFactory.create(authData);
    KoofrMediaExport export = new KoofrMediaExport(koofrClient, monitor);
    try {
        export.export();
        List<PhotoAlbum> exportAlbums = export.getPhotoAlbums();
        List<PhotoModel> exportPhotos = export.getPhotos();
        PhotosContainerResource containerResource = new PhotosContainerResource(exportAlbums, exportPhotos);
        return new ExportResult<>(ExportResult.ResultType.END, containerResource, null);
    } catch (IOException e) {
        return new ExportResult<>(e);
    }
}
Also used : PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) PhotoModel(org.datatransferproject.types.common.models.photos.PhotoModel) KoofrClient(org.datatransferproject.transfer.koofr.common.KoofrClient) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) IOException(java.io.IOException) KoofrMediaExport(org.datatransferproject.transfer.koofr.common.KoofrMediaExport) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult)

Example 38 with PhotoAlbum

use of org.datatransferproject.types.common.models.photos.PhotoAlbum in project data-transfer-project by google.

the class KoofrPhotosImporterTest method testImportItemFromURL.

@Test
public void testImportItemFromURL() throws Exception {
    // blank.jpg generated using
    // convert -size 1x1 xc:white blank.jpg
    // exiftool "-CreateDate=2020:08:03 11:55:24" blank.jpg
    final byte[] blankBytes = IOUtils.toByteArray(getClass().getClassLoader().getResourceAsStream("blank.jpg"));
    server.enqueue(new MockResponse().setResponseCode(200).setBody("123"));
    server.enqueue(new MockResponse().setResponseCode(200).setBody("4567"));
    final Buffer blankBuffer = new Buffer();
    blankBuffer.write(blankBytes);
    server.enqueue(new MockResponse().setResponseCode(200).setBody(blankBuffer));
    blankBuffer.close();
    server.enqueue(new MockResponse().setResponseCode(200).setBody("89"));
    server.enqueue(new MockResponse().setResponseCode(200).setBody("0"));
    when(client.ensureRootFolder()).thenReturn("/root");
    when(executor.getCachedValue(eq("id1"))).thenReturn("/root/Album 1");
    when(executor.getCachedValue(eq("id2"))).thenReturn("/root/Album");
    when(client.fileExists("/root/Album 1/pic1.jpg")).thenReturn(false);
    when(client.fileExists("/root/Album 1/pic2.png")).thenReturn(true);
    when(client.fileExists("/root/Album 1/2020-08-03 11.55.24 pic3.jpg")).thenReturn(false);
    when(client.fileExists("/root/Album 1/2020-08-17 11.55.24 pic4.jpg")).thenReturn(false);
    when(client.fileExists("/root/Album/pic5.jpg")).thenReturn(false);
    String description1000 = new String(new char[1000]).replace("\0", "a");
    String description1001 = new String(new char[1001]).replace("\0", "a");
    UUID jobId = UUID.randomUUID();
    PortabilityJob job = mock(PortabilityJob.class);
    when(jobStore.findJob(jobId)).thenReturn(job);
    Collection<PhotoAlbum> albums = ImmutableList.of(new PhotoAlbum("id1", "Album 1", "This is a fake album"), new PhotoAlbum("id2", "", description1001));
    Collection<PhotoModel> photos = ImmutableList.of(new PhotoModel("pic1.jpg", server.url("/1.jpg").toString(), null, "image/jpeg", "p1", "id1", false, null), new PhotoModel("pic2.png", server.url("/2.png").toString(), "fine art", "image/png", "p2", "id1", false, null), new PhotoModel("pic3.jpg", server.url("/3.jpg").toString(), "A pic with EXIF", "image/jpeg", "p3", "id1", false, null), new PhotoModel("pic4.jpg", server.url("/4.jpg").toString(), "A pic with uploaded time", "image/jpeg", "p4", "id1", false, new SimpleDateFormat("yyyy:MM:dd HH:mm:ss").parse("2020:08:17 11:55:24")), new PhotoModel("pic5.jpg", server.url("/5.jpg").toString(), description1001, "image/jpeg", "p5", "id2", false, null));
    PhotosContainerResource resource = spy(new PhotosContainerResource(albums, photos));
    importer.importItem(jobId, executor, authData, resource);
    InOrder clientInOrder = Mockito.inOrder(client);
    verify(resource).transmogrify(any(KoofrTransmogrificationConfig.class));
    clientInOrder.verify(client).ensureRootFolder();
    clientInOrder.verify(client).ensureFolder("/root", "Album 1");
    clientInOrder.verify(client).addDescription("/root/Album 1", "This is a fake album");
    clientInOrder.verify(client).ensureFolder("/root", "Album");
    clientInOrder.verify(client).addDescription("/root/Album", description1000);
    clientInOrder.verify(client).fileExists(eq("/root/Album 1/pic1.jpg"));
    clientInOrder.verify(client).uploadFile(eq("/root/Album 1"), eq("pic1.jpg"), any(), eq("image/jpeg"), isNull(), isNull());
    clientInOrder.verify(client).fileExists(eq("/root/Album 1/pic2.png"));
    clientInOrder.verify(client).fileExists(eq("/root/Album 1/2020-08-03 11.55.24 pic3.jpg"));
    clientInOrder.verify(client).uploadFile(eq("/root/Album 1"), eq("2020-08-03 11.55.24 pic3.jpg"), any(), eq("image/jpeg"), eq(new SimpleDateFormat("yyyy:MM:dd HH:mm:ss").parse("2020:08:03 11:55:24")), eq("A pic with EXIF"));
    clientInOrder.verify(client).uploadFile(eq("/root/Album 1"), eq("2020-08-17 11.55.24 pic4.jpg"), any(), eq("image/jpeg"), eq(new SimpleDateFormat("yyyy:MM:dd HH:mm:ss").parse("2020:08:17 11:55:24")), eq("A pic with uploaded time"));
    clientInOrder.verify(client).fileExists(eq("/root/Album/pic5.jpg"));
    clientInOrder.verify(client).uploadFile(eq("/root/Album"), eq("pic5.jpg"), any(), eq("image/jpeg"), isNull(), eq(description1000));
    clientInOrder.verifyNoMoreInteractions();
}
Also used : Buffer(okio.Buffer) MockResponse(okhttp3.mockwebserver.MockResponse) InOrder(org.mockito.InOrder) PhotoModel(org.datatransferproject.types.common.models.photos.PhotoModel) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PortabilityJob(org.datatransferproject.spi.cloud.types.PortabilityJob) PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) KoofrTransmogrificationConfig(org.datatransferproject.transfer.koofr.KoofrTransmogrificationConfig) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) UUID(java.util.UUID) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 39 with PhotoAlbum

use of org.datatransferproject.types.common.models.photos.PhotoAlbum in project data-transfer-project by google.

the class SmugMugPhotosImporterTest method importEmptyAlbumName.

@Test
public void importEmptyAlbumName() throws Exception {
    UUID jobId = UUID.randomUUID();
    PhotoAlbum photoAlbum = new PhotoAlbum("albumid", "", "albumDescription");
    PhotosContainerResource photosContainerResource = new PhotosContainerResource(Collections.singletonList(photoAlbum), ImmutableList.of());
    SmugMugAlbum smugMugAlbum = new SmugMugAlbum("date", photoAlbum.getDescription(), "Untitled Album", "privacy", "albumUri1", "urlname", "weburi");
    SmugMugAlbumResponse mockAlbumResponse = new SmugMugAlbumResponse(smugMugAlbum.getUri(), "Locator", "LocatorType", smugMugAlbum);
    when(smugMugInterface.createAlbum(eq(smugMugAlbum.getName()))).thenReturn(mockAlbumResponse);
    // Run test
    SmugMugPhotosImporter importer = new SmugMugPhotosImporter(smugMugInterface, config, jobStore, new AppCredentials("key", "secret"), mock(ObjectMapper.class), monitor);
    ImportResult result = importer.importItem(jobId, EXECUTOR, new TokenSecretAuthData("token", "secret"), photosContainerResource);
    // Verify
    verify(smugMugInterface, atLeastOnce()).createAlbum(ArgumentCaptor.forClass(String.class).capture());
}
Also used : PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) ImportResult(org.datatransferproject.spi.transfer.provider.ImportResult) TokenSecretAuthData(org.datatransferproject.types.transfer.auth.TokenSecretAuthData) AppCredentials(org.datatransferproject.types.transfer.auth.AppCredentials) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) UUID(java.util.UUID) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 40 with PhotoAlbum

use of org.datatransferproject.types.common.models.photos.PhotoAlbum in project data-transfer-project by google.

the class SmugMugPhotosImporterTest method importStoresAlbumInJobStore.

@Test
public void importStoresAlbumInJobStore() throws Exception {
    // setup test objects
    UUID jobId = UUID.randomUUID();
    PhotoAlbum photoAlbum1 = new PhotoAlbum("albumId1", "albumName1", "albumDescription1");
    PhotoModel photoModel1 = new PhotoModel("PHOTO_TITLE", "FETCHABLE_URL", "PHOTO_DESCRIPTION", "MEDIA_TYPE", "photoId1", photoAlbum1.getId(), false);
    PhotoModel photoModel2 = new PhotoModel("PHOTO_TITLE", "FETCHABLE_URL", "PHOTO_DESCRIPTION", "MEDIA_TYPE", "photoId2", photoAlbum1.getId(), false);
    PhotoModel photoModel3 = new PhotoModel("PHOTO_TITLE", "FETCHABLE_URL", "PHOTO_DESCRIPTION", "MEDIA_TYPE", "photoId3", photoAlbum1.getId(), false);
    PhotosContainerResource photosContainerResource1 = new PhotosContainerResource(Collections.singletonList(photoAlbum1), ImmutableList.of());
    PhotosContainerResource photosContainerResource2 = new PhotosContainerResource(ImmutableList.of(), ImmutableList.of(photoModel1, photoModel2, photoModel3));
    SmugMugAlbum smugMugAlbum1 = new SmugMugAlbum("date", photoAlbum1.getDescription(), photoAlbum1.getName(), "privacy", "albumUri1", "urlname", "weburi");
    String overflowAlbumName = smugMugAlbum1.getName() + " (1)";
    SmugMugAlbum smugMugAlbum2 = new SmugMugAlbum("date", photoAlbum1.getDescription(), overflowAlbumName, "privacy", "albumUri2", "urlname", "weburi");
    SmugMugAlbumResponse mockAlbumResponse1 = new SmugMugAlbumResponse(smugMugAlbum1.getUri(), "Locator", "LocatorType", smugMugAlbum1);
    SmugMugAlbumResponse mockAlbumResponse2 = new SmugMugAlbumResponse(smugMugAlbum2.getUri(), "Locator", "LocatorType", smugMugAlbum2);
    when(smugMugInterface.createAlbum(eq(smugMugAlbum1.getName()))).thenReturn(mockAlbumResponse1);
    when(smugMugInterface.createAlbum(eq(smugMugAlbum2.getName()))).thenReturn(mockAlbumResponse2);
    SmugMugImageUploadResponse smugMugUploadImageResponse = new SmugMugImageUploadResponse("imageUri", "albumImageUri", new ImageInfo("imageUri", "albumImageUri", "statusImageReplaceUri", "url"));
    when(smugMugInterface.uploadImage(any(), any(), any())).thenReturn(smugMugUploadImageResponse);
    when(smugMugInterface.getImageAsStream(any())).thenReturn(bufferedInputStream);
    // Run test
    SmugMugPhotosImporter importer = new SmugMugPhotosImporter(smugMugInterface, config, jobStore, new AppCredentials("key", "secret"), mock(ObjectMapper.class), monitor);
    ImportResult result = importer.importItem(jobId, EXECUTOR, new TokenSecretAuthData("token", "secret"), photosContainerResource1);
    result = importer.importItem(jobId, EXECUTOR, new TokenSecretAuthData("token", "secret"), photosContainerResource2);
    // Verify
    ArgumentCaptor<String> photoUrlsCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> albumNamesCaptor = ArgumentCaptor.forClass(String.class);
    verify(smugMugInterface, atLeastOnce()).createAlbum(albumNamesCaptor.capture());
    verify(smugMugInterface, atLeastOnce()).getImageAsStream(photoUrlsCaptor.capture());
    List<String> capturedAlbumNames = albumNamesCaptor.getAllValues();
    assertTrue(capturedAlbumNames.contains(smugMugAlbum1.getName()));
    assertTrue(capturedAlbumNames.contains(smugMugAlbum2.getName()));
    List<String> capturedPhotoUrls = photoUrlsCaptor.getAllValues();
    assertTrue(capturedPhotoUrls.contains(photoModel1.getFetchableUrl()));
    assertTrue(capturedPhotoUrls.contains(photoModel2.getFetchableUrl()));
    assertTrue(capturedPhotoUrls.contains(photoModel3.getFetchableUrl()));
    String overflowAlbumId = photoAlbum1.getId() + "-overflow-1";
    assertThat((String) EXECUTOR.getCachedValue(photoAlbum1.getId())).isEqualTo(smugMugAlbum1.getUri());
    assertThat((String) EXECUTOR.getCachedValue(overflowAlbumId)).isEqualTo(smugMugAlbum2.getUri());
    SmugMugPhotoTempData tempData1 = new SmugMugPhotoTempData(photoAlbum1.getId(), smugMugAlbum1.getName(), smugMugAlbum1.getDescription(), smugMugAlbum1.getUri(), 2, overflowAlbumId);
    SmugMugPhotoTempData tempData2 = new SmugMugPhotoTempData(overflowAlbumId, smugMugAlbum2.getName(), smugMugAlbum2.getDescription(), smugMugAlbum2.getUri(), 1, null);
    assertThat(jobStore.findData(jobId, String.format(TEMP_DATA_FORMAT, photoAlbum1.getId()), SmugMugPhotoTempData.class).toString()).isEqualTo(tempData1.toString());
    assertThat(jobStore.findData(jobId, String.format(TEMP_DATA_FORMAT, overflowAlbumId), SmugMugPhotoTempData.class).toString()).isEqualTo(tempData2.toString());
}
Also used : ImportResult(org.datatransferproject.spi.transfer.provider.ImportResult) AppCredentials(org.datatransferproject.types.transfer.auth.AppCredentials) PhotoModel(org.datatransferproject.types.common.models.photos.PhotoModel) PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) TokenSecretAuthData(org.datatransferproject.types.transfer.auth.TokenSecretAuthData) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) UUID(java.util.UUID) ImageInfo(org.datatransferproject.transfer.smugmug.photos.model.SmugMugImageUploadResponse.ImageInfo) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)45 PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)36 Test (org.junit.Test)27 PhotoModel (org.datatransferproject.types.common.models.photos.PhotoModel)23 IdOnlyContainerResource (org.datatransferproject.types.common.models.IdOnlyContainerResource)19 ContinuationData (org.datatransferproject.spi.transfer.types.ContinuationData)18 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)15 ArrayList (java.util.ArrayList)12 StringPaginationToken (org.datatransferproject.types.common.StringPaginationToken)12 UUID (java.util.UUID)11 IOException (java.io.IOException)8 PaginationData (org.datatransferproject.types.common.PaginationData)7 GoogleAlbum (org.datatransferproject.datatransfer.google.mediaModels.GoogleAlbum)6 ImportResult (org.datatransferproject.spi.transfer.provider.ImportResult)6 ContainerResource (org.datatransferproject.types.common.models.ContainerResource)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 InputStreamWrapper (org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore.InputStreamWrapper)5 PortabilityJob (org.datatransferproject.spi.cloud.types.PortabilityJob)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)4