Search in sources :

Example 21 with PhotoModel

use of org.datatransferproject.types.common.models.photos.PhotoModel 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 22 with PhotoModel

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

the class KoofrMediaExport method getPhotos.

public List<PhotoModel> getPhotos() throws IOException, InvalidTokenException {
    ArrayList<PhotoModel> exportPhotos = new ArrayList<>();
    for (PhotoModelContainer photoContainer : photos) {
        PhotoModel photo = photoContainer.photoModel;
        String fetchableUrl = getFetchableUrl(photoContainer.fullPath);
        if (fetchableUrl == null) {
            continue;
        }
        exportPhotos.add(new PhotoModel(photo.getTitle(), fetchableUrl, photo.getDescription(), photo.getMediaType(), photo.getDataId(), photo.getAlbumId(), photo.isInTempStore(), photo.getUploadedTime()));
    }
    return exportPhotos;
}
Also used : PhotoModel(org.datatransferproject.types.common.models.photos.PhotoModel) ArrayList(java.util.ArrayList)

Example 23 with PhotoModel

use of org.datatransferproject.types.common.models.photos.PhotoModel 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 PhotoModel

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

the class InstagramPhotoExporter method exportPhotos.

private ExportResult<PhotosContainerResource> exportPhotos(TokensAndUrlAuthData authData, Optional<PaginationData> pageData) {
    Preconditions.checkNotNull(authData);
    MediaResponse response;
    try {
        response = makeRequest(MEDIA_URL, MediaResponse.class, authData);
    } catch (IOException e) {
        return new ExportResult<>(e);
    }
    List<PhotoModel> photos = new ArrayList<>();
    // TODO: check out paging.
    for (MediaFeedData photo : response.getData()) {
        // TODO json mapping is broken.
        String photoId = photo.getId();
        String url = photo.getImages().getStandardResolution().getUrl();
        String text = (photo.getCaption() != null) ? photo.getCaption().getText() : null;
        photos.add(new PhotoModel("Instagram photo: " + photoId, url, text, null, photoId, FAKE_ALBUM_ID, false));
    }
    List<PhotoAlbum> albums = new ArrayList<>();
    if (!photos.isEmpty() && !pageData.isPresent()) {
        albums.add(new PhotoAlbum(FAKE_ALBUM_ID, "Imported Instagram Photos", "Photos imported from instagram"));
    }
    return new ExportResult<>(ResultType.END, new PhotosContainerResource(albums, photos));
}
Also used : PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) MediaResponse(org.datatransferproject.transfer.instagram.photos.model.MediaResponse) PhotoModel(org.datatransferproject.types.common.models.photos.PhotoModel) ArrayList(java.util.ArrayList) MediaFeedData(org.datatransferproject.transfer.instagram.photos.model.MediaFeedData) IOException(java.io.IOException) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult)

Example 25 with PhotoModel

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

the class MediaContainerResource method ensureRootAlbum.

// Ensures that the model obeys the restrictions of the destination service, grouping all
// un-nested photos into their own root album if allowRootPhotos is true, noop otherwise
void ensureRootAlbum(boolean allowRootPhotos) {
    if (allowRootPhotos) {
        return;
    }
    MediaAlbum rootAlbum = new MediaAlbum(ROOT_ALBUM, ROOT_ALBUM, "A copy of your transferred media that were not in any album");
    boolean usedRootAlbum = false;
    for (PhotoModel photo : photos) {
        if (photo.getAlbumId() == null) {
            photo.reassignToAlbum(rootAlbum.getId());
            usedRootAlbum = true;
        }
    }
    for (VideoModel video : videos) {
        if (video.getAlbumId() == null) {
            video.reassignToAlbum(rootAlbum.getId());
            usedRootAlbum = true;
        }
    }
    if (usedRootAlbum) {
        albums.add(rootAlbum);
    }
}
Also used : PhotoModel(org.datatransferproject.types.common.models.photos.PhotoModel) VideoModel(org.datatransferproject.types.common.models.videos.VideoModel)

Aggregations

PhotoModel (org.datatransferproject.types.common.models.photos.PhotoModel)44 PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)29 PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)24 Test (org.junit.Test)22 ContinuationData (org.datatransferproject.spi.transfer.types.ContinuationData)17 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)16 ArrayList (java.util.ArrayList)14 UUID (java.util.UUID)14 IOException (java.io.IOException)12 IdOnlyContainerResource (org.datatransferproject.types.common.models.IdOnlyContainerResource)12 StringPaginationToken (org.datatransferproject.types.common.StringPaginationToken)10 TokensAndUrlAuthData (org.datatransferproject.types.transfer.auth.TokensAndUrlAuthData)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 InputStream (java.io.InputStream)6 PaginationData (org.datatransferproject.types.common.PaginationData)6 Collection (java.util.Collection)5 List (java.util.List)5 Optional (java.util.Optional)5 Collectors (java.util.stream.Collectors)5 BatchMediaItemResponse (org.datatransferproject.datatransfer.google.mediaModels.BatchMediaItemResponse)5