Search in sources :

Example 1 with ImageStreamProvider

use of org.datatransferproject.transfer.ImageStreamProvider in project data-transfer-project by google.

the class BackblazeTransferExtension method initialize.

@Override
public void initialize(ExtensionContext context) {
    Monitor monitor = context.getMonitor();
    monitor.debug(() -> "Starting Backblaze initialization");
    if (initialized) {
        monitor.severe(() -> "BackblazeTransferExtension already initialized.");
        return;
    }
    TemporaryPerJobDataStore jobStore = context.getService(TemporaryPerJobDataStore.class);
    ImmutableMap.Builder<String, Importer> importerBuilder = ImmutableMap.builder();
    BackblazeDataTransferClientFactory backblazeDataTransferClientFactory = new BackblazeDataTransferClientFactory(monitor);
    ImageStreamProvider isProvider = new ImageStreamProvider();
    importerBuilder.put("PHOTOS", new BackblazePhotosImporter(monitor, jobStore, isProvider, backblazeDataTransferClientFactory));
    importerBuilder.put("VIDEOS", new BackblazeVideosImporter(monitor, jobStore, isProvider, backblazeDataTransferClientFactory));
    importerMap = importerBuilder.build();
    initialized = true;
}
Also used : BackblazeDataTransferClientFactory(org.datatransferproject.datatransfer.backblaze.common.BackblazeDataTransferClientFactory) TemporaryPerJobDataStore(org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore) BackblazePhotosImporter(org.datatransferproject.datatransfer.backblaze.photos.BackblazePhotosImporter) Monitor(org.datatransferproject.api.launcher.Monitor) ImageStreamProvider(org.datatransferproject.transfer.ImageStreamProvider) BackblazeVideosImporter(org.datatransferproject.datatransfer.backblaze.videos.BackblazeVideosImporter) ImmutableMap(com.google.common.collect.ImmutableMap) BackblazeVideosImporter(org.datatransferproject.datatransfer.backblaze.videos.BackblazeVideosImporter) BackblazePhotosImporter(org.datatransferproject.datatransfer.backblaze.photos.BackblazePhotosImporter) Importer(org.datatransferproject.spi.transfer.provider.Importer)

Example 2 with ImageStreamProvider

use of org.datatransferproject.transfer.ImageStreamProvider in project data-transfer-project by google.

the class GooglePhotosImporterTest method setUp.

@Before
public void setUp() throws IOException, InvalidTokenException, PermissionDeniedException {
    googlePhotosInterface = Mockito.mock(GooglePhotosInterface.class);
    monitor = Mockito.mock(Monitor.class);
    executor = new InMemoryIdempotentImportExecutor(monitor);
    Mockito.when(googlePhotosInterface.makePostRequest(anyString(), any(), any(), eq(NewMediaItemResult.class))).thenReturn(Mockito.mock(NewMediaItemResult.class));
    JobStore jobStore = new LocalJobStore();
    InputStream inputStream = Mockito.mock(InputStream.class);
    imageStreamProvider = Mockito.mock(ImageStreamProvider.class);
    HttpURLConnection conn = Mockito.mock(HttpURLConnection.class);
    Mockito.when(imageStreamProvider.getConnection(anyString())).thenReturn(conn);
    Mockito.when(conn.getInputStream()).thenReturn(inputStream);
    Mockito.when(conn.getContentLengthLong()).thenReturn(32L);
    googlePhotosImporter = new GooglePhotosImporter(null, jobStore, null, null, googlePhotosInterface, imageStreamProvider, monitor, 1.0);
}
Also used : LocalJobStore(org.datatransferproject.cloud.local.LocalJobStore) Monitor(org.datatransferproject.api.launcher.Monitor) HttpURLConnection(java.net.HttpURLConnection) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) NewMediaItemResult(org.datatransferproject.datatransfer.google.mediaModels.NewMediaItemResult) ImageStreamProvider(org.datatransferproject.transfer.ImageStreamProvider) LocalJobStore(org.datatransferproject.cloud.local.LocalJobStore) JobStore(org.datatransferproject.spi.cloud.storage.JobStore) InMemoryIdempotentImportExecutor(org.datatransferproject.spi.transfer.idempotentexecutor.InMemoryIdempotentImportExecutor) Before(org.junit.Before)

Example 3 with ImageStreamProvider

use of org.datatransferproject.transfer.ImageStreamProvider in project data-transfer-project by google.

the class FacebookPhotosExporterTest method setUp.

@Before
public void setUp() throws IOException {
    FacebookPhotosInterface photosInterface = mock(FacebookPhotosInterface.class);
    // Set up example album
    Album album = new Album();
    album.setId(ALBUM_ID);
    album.setName(ALBUM_NAME);
    album.setDescription(ALBUM_DESCRIPTION);
    ArrayList<Album> albums = new ArrayList<>();
    albums.add(album);
    @SuppressWarnings("unchecked") Connection<Album> albumConnection = mock(Connection.class);
    when(photosInterface.getAlbums(Mockito.any())).thenReturn(albumConnection);
    when(albumConnection.getData()).thenReturn(albums);
    // Set up example photo
    Photo photo = new Photo();
    photo.setId(PHOTO_ID);
    photo.setCreatedTime(PHOTO_TIME);
    Photo.Image image = new Photo.Image();
    image.setSource(PHOTO_SOURCE);
    photo.addImage(image);
    photo.setName(PHOTO_NAME);
    ArrayList<Photo> photos = new ArrayList<>();
    photos.add(photo);
    @SuppressWarnings("unchecked") Connection<Photo> photoConnection = mock(Connection.class);
    when(photosInterface.getPhotos(ALBUM_ID, Optional.empty())).thenReturn(photoConnection);
    when(photoConnection.getData()).thenReturn(photos);
    final ImageStreamProvider imageStreamProvider = mock(ImageStreamProvider.class);
    InputStream inputStream = getClass().getClassLoader().getResourceAsStream("test.jpeg");
    HttpURLConnection connection = mock(HttpURLConnection.class);
    when(imageStreamProvider.getConnection(ArgumentMatchers.anyString())).thenReturn(connection);
    when(connection.getInputStream()).thenReturn(inputStream);
    final TemporaryPerJobDataStore store = mock(TemporaryPerJobDataStore.class);
    facebookPhotosExporter = new FacebookPhotosExporter(new AppCredentials("key", "secret"), photosInterface, null, store, imageStreamProvider);
}
Also used : TemporaryPerJobDataStore(org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore) AppCredentials(org.datatransferproject.types.transfer.auth.AppCredentials) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) ImageStreamProvider(org.datatransferproject.transfer.ImageStreamProvider) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) Album(com.restfb.types.Album) Photo(com.restfb.types.Photo) HttpURLConnection(java.net.HttpURLConnection) Before(org.junit.Before)

Aggregations

ImageStreamProvider (org.datatransferproject.transfer.ImageStreamProvider)3 InputStream (java.io.InputStream)2 HttpURLConnection (java.net.HttpURLConnection)2 Monitor (org.datatransferproject.api.launcher.Monitor)2 TemporaryPerJobDataStore (org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore)2 Before (org.junit.Before)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Album (com.restfb.types.Album)1 Photo (com.restfb.types.Photo)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ArrayList (java.util.ArrayList)1 LocalJobStore (org.datatransferproject.cloud.local.LocalJobStore)1 BackblazeDataTransferClientFactory (org.datatransferproject.datatransfer.backblaze.common.BackblazeDataTransferClientFactory)1 BackblazePhotosImporter (org.datatransferproject.datatransfer.backblaze.photos.BackblazePhotosImporter)1 BackblazeVideosImporter (org.datatransferproject.datatransfer.backblaze.videos.BackblazeVideosImporter)1 NewMediaItemResult (org.datatransferproject.datatransfer.google.mediaModels.NewMediaItemResult)1 JobStore (org.datatransferproject.spi.cloud.storage.JobStore)1 InMemoryIdempotentImportExecutor (org.datatransferproject.spi.transfer.idempotentexecutor.InMemoryIdempotentImportExecutor)1 Importer (org.datatransferproject.spi.transfer.provider.Importer)1 PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)1