Search in sources :

Example 21 with PhotosContainerResource

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

the class KoofrPhotosExporterTest method testExport.

@Test
public void testExport() throws Exception {
    when(client.getRootPath()).thenReturn("/Data transfer");
    when(client.listRecursive("/Data transfer")).thenReturn(Fixtures.listRecursiveItems);
    when(client.fileLink("/Data transfer/Album 1/Photo 1.jpg")).thenReturn("https://app-1.koofr.net/content/files/get/Photo+1.jpg?base=TESTBASE");
    when(client.fileLink("/Data transfer/Album 1/Photo 2.jpg")).thenReturn("https://app-1.koofr.net/content/files/get/Photo+2.jpg?base=TESTBASE");
    when(client.fileLink("/Data transfer/Album 2 :heart:/Photo 3.jpg")).thenReturn("https://app-1.koofr.net/content/files/get/Photo+3.jpg?base=TESTBASE");
    UUID jobId = UUID.randomUUID();
    ExportResult<PhotosContainerResource> result = exporter.export(jobId, authData, Optional.empty());
    assertEquals(ExportResult.ResultType.END, result.getType());
    assertNull(result.getContinuationData());
    PhotosContainerResource exportedData = result.getExportedData();
    List<PhotoAlbum> expectedAlbums = ImmutableList.of(new PhotoAlbum("/Album 1", "Album 1", null), new PhotoAlbum("/Album 2 :heart:", "Album 2 ❤️", "Album 2 description ❤️"));
    assertEquals(expectedAlbums, exportedData.getAlbums());
    List<PhotoModel> expectedPhotos = ImmutableList.of(new PhotoModel("Photo 1.jpg", "https://app-1.koofr.net/content/files/get/Photo+1.jpg?base=TESTBASE", "Photo 1 description", "image/jpeg", "/Album 1/Photo 1.jpg", "/Album 1", false, new Date(1324824491000L)), new PhotoModel("Photo 2.jpg", "https://app-1.koofr.net/content/files/get/Photo+2.jpg?base=TESTBASE", null, "image/jpeg", "/Album 1/Photo 2.jpg", "/Album 1", false, new Date(1368774569000L)), new PhotoModel("Photo 3.jpg", "https://app-1.koofr.net/content/files/get/Photo+3.jpg?base=TESTBASE", "Photo 3 description", "image/jpeg", "/Album 2 :heart:/Photo 3.jpg", "/Album 2 :heart:", false, new Date(1489345497000L)));
    assertEquals(expectedPhotos, exportedData.getPhotos());
}
Also used : PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) PhotoModel(org.datatransferproject.types.common.models.photos.PhotoModel) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) UUID(java.util.UUID) Date(java.util.Date) Test(org.junit.Test)

Example 22 with PhotosContainerResource

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

the class KoofrPhotosImporterTest method testImportItemFromJobStore.

@Test
public void testImportItemFromJobStore() throws Exception {
    ByteArrayInputStream inputStream = new ByteArrayInputStream(new byte[] { 0, 1, 2, 3, 4 });
    when(client.ensureRootFolder()).thenReturn("/root");
    when(jobStore.getStream(any(), any())).thenReturn(new InputStreamWrapper(inputStream, 5L));
    doNothing().when(jobStore).removeData(any(), anyString());
    when(executor.getCachedValue(eq("id1"))).thenReturn("/root/Album 1");
    UUID jobId = UUID.randomUUID();
    Collection<PhotoAlbum> albums = ImmutableList.of(new PhotoAlbum("id1", "Album 1", "This is a fake album"));
    Collection<PhotoModel> photos = ImmutableList.of(new PhotoModel("pic1.jpg", "http://fake.com/1.jpg", "A pic", "image/jpeg", "p1", "id1", true), new PhotoModel("pic2.png", "https://fake.com/2.png", "fine art", "image/png", "p2", "id1", true));
    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).uploadFile(eq("/root/Album 1"), eq("pic1.jpg"), any(), eq("image/jpeg"), isNull(), eq("A pic"));
    clientInOrder.verify(client).uploadFile(eq("/root/Album 1"), eq("pic2.png"), any(), eq("image/png"), isNull(), eq("fine art"));
    verify(jobStore, Mockito.times(2)).removeData(any(), anyString());
}
Also used : PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) InputStreamWrapper(org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore.InputStreamWrapper) InOrder(org.mockito.InOrder) ByteArrayInputStream(java.io.ByteArrayInputStream) KoofrTransmogrificationConfig(org.datatransferproject.transfer.koofr.KoofrTransmogrificationConfig) PhotoModel(org.datatransferproject.types.common.models.photos.PhotoModel) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) UUID(java.util.UUID) Test(org.junit.Test)

Example 23 with PhotosContainerResource

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

the class KoofrTransmogrificationConfigTest method testPhotoTitleName.

@Test
public void testPhotoTitleName() {
    Collection<PhotoAlbum> albums = ImmutableList.of(new PhotoAlbum("id1", "Album ~\"#%&*:<>?/\\{|}1", "This is a fake album"));
    Collection<PhotoModel> photos = ImmutableList.of(new PhotoModel("pic1~\"#%&*:<>?/\\{|}.jpg", "http://fake.com/1.jpg", "A pic", "image/jpg", "p1", "id1", true), new PhotoModel("pic2~\"#%&*:<>?/\\{|}.jpg", "https://fake.com/2.png", "fine art", "image/png", "p2", "id1", true));
    PhotosContainerResource container = new PhotosContainerResource(albums, photos);
    KoofrTransmogrificationConfig config = new KoofrTransmogrificationConfig();
    container.transmogrify(config);
    PhotoAlbum[] albumsArray = container.getAlbums().toArray(new PhotoAlbum[0]);
    PhotoModel[] photosArray = container.getPhotos().toArray(new PhotoModel[0]);
    Assert.assertEquals(1, albumsArray.length);
    Assert.assertEquals("Album _______________1", albumsArray[0].getName());
    Assert.assertEquals(2, photosArray.length);
    Assert.assertEquals("pic1_______________.jpg", photosArray[0].getTitle());
    Assert.assertEquals("pic2_______________.jpg", photosArray[1].getTitle());
}
Also used : PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) PhotoModel(org.datatransferproject.types.common.models.photos.PhotoModel) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) Test(org.junit.Test)

Example 24 with PhotosContainerResource

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

the class ImgurPhotosExporter method requestAlbums.

/**
 * Exports albums.
 *
 * @param authData authentication information
 * @param paginationData pagination information to use for subsequent calls
 */
private ExportResult<PhotosContainerResource> requestAlbums(TokensAndUrlAuthData authData, PaginationData paginationData) throws IOException {
    ImmutableList.Builder<PhotoAlbum> albumBuilder = ImmutableList.builder();
    List<IdOnlyContainerResource> albumIds = new ArrayList<>();
    int page = paginationData == null ? 0 : ((IntPaginationToken) paginationData).getStart();
    String url = format(ALBUMS_URL_TEMPLATE, page);
    List<Map<String, Object>> items = requestData(authData, url);
    // Request result doesn't indicate if it's the last page
    boolean hasMore = (items != null && items.size() != 0);
    for (Map<String, Object> item : items) {
        albumBuilder.add(new PhotoAlbum((String) item.get("id"), (String) item.get("title"), (String) item.get("description")));
        // Save album id for recalling export to get all the photos in albums
        albumIds.add(new IdOnlyContainerResource((String) item.get("id")));
    }
    if (page == 0) {
        // For checking non-album photos. Their export should be performed after all the others
        // Album will be created later
        albumIds.add(new IdOnlyContainerResource(DEFAULT_ALBUM_ID));
    }
    PaginationData newPage = null;
    if (hasMore) {
        newPage = new IntPaginationToken(page + 1);
        int start = ((IntPaginationToken) newPage).getStart();
        monitor.info(() -> format("albums size: %s, newPage: %s", items.size(), start));
    }
    PhotosContainerResource photosContainerResource = new PhotosContainerResource(albumBuilder.build(), null);
    ContinuationData continuationData = new ContinuationData(newPage);
    albumIds.forEach(continuationData::addContainerResource);
    ExportResult.ResultType resultType = ExportResult.ResultType.CONTINUE;
    if (newPage == null) {
        resultType = ExportResult.ResultType.END;
    }
    return new ExportResult<>(resultType, photosContainerResource, continuationData);
}
Also used : IntPaginationToken(org.datatransferproject.types.common.IntPaginationToken) PaginationData(org.datatransferproject.types.common.PaginationData) ImmutableList(com.google.common.collect.ImmutableList) 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) Map(java.util.Map) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult)

Example 25 with PhotosContainerResource

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

the class ImgurPhotoExporterTest method testNonAlbumPhotoExport.

@Test
public void testNonAlbumPhotoExport() throws Exception {
    // all photos are non-album
    server.enqueue(new MockResponse().setBody(allImagesResponse));
    ExportResult<PhotosContainerResource> nonAlbumPhotosResult = exporter.export(UUID.randomUUID(), token, Optional.of(new ExportInformation(null, new IdOnlyContainerResource(ImgurPhotosExporter.DEFAULT_ALBUM_ID))));
    PhotosContainerResource resource = nonAlbumPhotosResult.getExportedData();
    assertEquals(3, resource.getPhotos().size());
}
Also used : MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) ExportInformation(org.datatransferproject.types.common.ExportInformation) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) Test(org.junit.Test)

Aggregations

PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)57 PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)37 Test (org.junit.Test)37 IdOnlyContainerResource (org.datatransferproject.types.common.models.IdOnlyContainerResource)29 PhotoModel (org.datatransferproject.types.common.models.photos.PhotoModel)29 ContinuationData (org.datatransferproject.spi.transfer.types.ContinuationData)27 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)21 ArrayList (java.util.ArrayList)18 StringPaginationToken (org.datatransferproject.types.common.StringPaginationToken)18 UUID (java.util.UUID)14 PaginationData (org.datatransferproject.types.common.PaginationData)12 IOException (java.io.IOException)10 ExportInformation (org.datatransferproject.types.common.ExportInformation)9 ImportResult (org.datatransferproject.spi.transfer.provider.ImportResult)8 IntPaginationToken (org.datatransferproject.types.common.IntPaginationToken)8 InputStreamWrapper (org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore.InputStreamWrapper)6 ContainerResource (org.datatransferproject.types.common.models.ContainerResource)6 TokensAndUrlAuthData (org.datatransferproject.types.transfer.auth.TokensAndUrlAuthData)6 Photoset (com.flickr4java.flickr.photosets.Photoset)5 ImmutableList (com.google.common.collect.ImmutableList)5