Search in sources :

Example 26 with Monitor

use of org.datatransferproject.api.launcher.Monitor in project data-transfer-project by google.

the class KoofrClientTest method setUp.

@Before
public void setUp() throws IOException {
    server = new MockWebServer();
    server.start();
    httpClient = new OkHttpClient.Builder().build();
    mapper = new ObjectMapper();
    monitor = mock(Monitor.class);
    credentialFactory = mock(KoofrCredentialFactory.class);
    credential = new Credential.Builder(BearerToken.authorizationHeaderAccessMethod()).build();
    credential.setAccessToken("acc");
    credential.setExpirationTimeMilliseconds(null);
    when(credentialFactory.createCredential(any())).thenReturn(credential);
    client = new KoofrClient(server.url("").toString(), httpClient, httpClient, mapper, monitor, credentialFactory);
    authData = new TokensAndUrlAuthData("acc", "refresh", "");
    client.getOrCreateCredential(authData);
}
Also used : Monitor(org.datatransferproject.api.launcher.Monitor) MockWebServer(okhttp3.mockwebserver.MockWebServer) TokensAndUrlAuthData(org.datatransferproject.types.transfer.auth.TokensAndUrlAuthData) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 27 with Monitor

use of org.datatransferproject.api.launcher.Monitor in project data-transfer-project by google.

the class KoofrPhotosExporterTest method setUp.

@Before
public void setUp() throws Exception {
    client = mock(KoofrClient.class);
    clientFactory = mock(KoofrClientFactory.class);
    when(clientFactory.create(any())).thenReturn(client);
    monitor = mock(Monitor.class);
    exporter = new KoofrPhotosExporter(clientFactory, monitor);
    authData = new TokensAndUrlAuthData("acc", "refresh", "");
}
Also used : KoofrClientFactory(org.datatransferproject.transfer.koofr.common.KoofrClientFactory) Monitor(org.datatransferproject.api.launcher.Monitor) KoofrClient(org.datatransferproject.transfer.koofr.common.KoofrClient) TokensAndUrlAuthData(org.datatransferproject.types.transfer.auth.TokensAndUrlAuthData) Before(org.junit.Before)

Example 28 with Monitor

use of org.datatransferproject.api.launcher.Monitor in project data-transfer-project by google.

the class SpotifyTransferExtension method initialize.

@Override
public void initialize(ExtensionContext context) {
    if (initialized) {
        Monitor monitor = context.getMonitor();
        monitor.severe(() -> "SpotifyTransferExtension already initialized");
        return;
    }
    AppCredentials appCredentials;
    try {
        appCredentials = context.getService(AppCredentialStore.class).getAppCredentials("SPOTIFY_KEY", "SPOTIFY_SECRET");
    } catch (IOException e) {
        Monitor monitor = context.getMonitor();
        monitor.info(() -> "Unable to retrieve Spotify AppCredentials. " + "Did you set SPOTIFY_KEY and SPOTIFY_SECRET?");
        return;
    }
    Monitor monitor = context.getMonitor();
    SpotifyApi spotifyApi = new SpotifyApi.Builder().setClientId(appCredentials.getKey()).setClientSecret(appCredentials.getSecret()).build();
    exporter = new SpotifyPlaylistExporter(monitor, spotifyApi);
    importer = new SpotifyPlaylistImporter(monitor, spotifyApi);
    initialized = true;
}
Also used : Monitor(org.datatransferproject.api.launcher.Monitor) AppCredentials(org.datatransferproject.types.transfer.auth.AppCredentials) SpotifyApi(com.wrapper.spotify.SpotifyApi) SpotifyPlaylistExporter(org.datatransferproject.transfer.spotify.playlists.SpotifyPlaylistExporter) SpotifyPlaylistImporter(org.datatransferproject.transfer.spotify.playlists.SpotifyPlaylistImporter) IOException(java.io.IOException)

Example 29 with Monitor

use of org.datatransferproject.api.launcher.Monitor in project data-transfer-project by google.

the class DataTypesActionTest method testGetRequestType.

@Test
public void testGetRequestType() {
    AuthServiceProviderRegistry registry = mock(AuthServiceProviderRegistry.class);
    DataTypesAction dataTypesAction = new DataTypesAction(registry, new Monitor() {
    });
    Class<GetDataTypes> actual = dataTypesAction.getRequestType();
    Assert.assertNotEquals(actual, null);
    Assert.assertEquals(actual, GetDataTypes.class);
}
Also used : Monitor(org.datatransferproject.api.launcher.Monitor) AuthServiceProviderRegistry(org.datatransferproject.spi.api.auth.AuthServiceProviderRegistry) GetDataTypes(org.datatransferproject.types.client.datatype.GetDataTypes) Test(org.junit.Test)

Example 30 with Monitor

use of org.datatransferproject.api.launcher.Monitor in project data-transfer-project by google.

the class GoogleTransferExtension method initialize.

@Override
public void initialize(ExtensionContext context) {
    // times.
    if (initialized)
        return;
    JobStore jobStore = context.getService(JobStore.class);
    HttpTransport httpTransport = context.getService(HttpTransport.class);
    JsonFactory jsonFactory = context.getService(JsonFactory.class);
    AppCredentials appCredentials;
    try {
        appCredentials = context.getService(AppCredentialStore.class).getAppCredentials("GOOGLE_KEY", "GOOGLE_SECRET");
    } catch (IOException e) {
        Monitor monitor = context.getMonitor();
        monitor.info(() -> "Unable to retrieve Google AppCredentials. Did you set GOOGLE_KEY and GOOGLE_SECRET?");
        return;
    }
    Monitor monitor = context.getMonitor();
    // Create the GoogleCredentialFactory with the given {@link AppCredentials}.
    GoogleCredentialFactory credentialFactory = new GoogleCredentialFactory(httpTransport, jsonFactory, appCredentials, monitor);
    ImmutableMap.Builder<String, Importer> importerBuilder = ImmutableMap.builder();
    importerBuilder.put("BLOBS", new DriveImporter(credentialFactory, jobStore, monitor));
    importerBuilder.put("CONTACTS", new GoogleContactsImporter(credentialFactory));
    importerBuilder.put("CALENDAR", new GoogleCalendarImporter(credentialFactory));
    importerBuilder.put("MAIL", new GoogleMailImporter(credentialFactory, monitor));
    importerBuilder.put("TASKS", new GoogleTasksImporter(credentialFactory));
    importerBuilder.put("PHOTOS", new GooglePhotosImporter(credentialFactory, jobStore, jsonFactory, monitor, context.getSetting("googleWritesPerSecond", 1.0)));
    importerBuilder.put("VIDEOS", new GoogleVideosImporter(appCredentials, jobStore, monitor));
    importerMap = importerBuilder.build();
    ImmutableMap.Builder<String, Exporter> exporterBuilder = ImmutableMap.builder();
    exporterBuilder.put("BLOBS", new DriveExporter(credentialFactory, jobStore, monitor));
    exporterBuilder.put("CONTACTS", new GoogleContactsExporter(credentialFactory));
    exporterBuilder.put("CALENDAR", new GoogleCalendarExporter(credentialFactory));
    exporterBuilder.put("MAIL", new GoogleMailExporter(credentialFactory));
    exporterBuilder.put("SOCIAL-POSTS", new GooglePlusExporter(credentialFactory));
    exporterBuilder.put("TASKS", new GoogleTasksExporter(credentialFactory, monitor));
    exporterBuilder.put("PHOTOS", new GooglePhotosExporter(credentialFactory, jobStore, jsonFactory, monitor));
    exporterBuilder.put("VIDEOS", new GoogleVideosExporter(credentialFactory, jsonFactory));
    exporterMap = exporterBuilder.build();
    initialized = true;
}
Also used : GoogleCalendarImporter(org.datatransferproject.datatransfer.google.calendar.GoogleCalendarImporter) GoogleTasksExporter(org.datatransferproject.datatransfer.google.tasks.GoogleTasksExporter) AppCredentials(org.datatransferproject.types.transfer.auth.AppCredentials) GooglePhotosImporter(org.datatransferproject.datatransfer.google.photos.GooglePhotosImporter) JsonFactory(com.google.api.client.json.JsonFactory) GoogleMailImporter(org.datatransferproject.datatransfer.google.mail.GoogleMailImporter) GoogleCredentialFactory(org.datatransferproject.datatransfer.google.common.GoogleCredentialFactory) GoogleCalendarExporter(org.datatransferproject.datatransfer.google.calendar.GoogleCalendarExporter) GoogleVideosExporter(org.datatransferproject.datatransfer.google.videos.GoogleVideosExporter) DriveExporter(org.datatransferproject.datatransfer.google.drive.DriveExporter) GoogleMailExporter(org.datatransferproject.datatransfer.google.mail.GoogleMailExporter) Exporter(org.datatransferproject.spi.transfer.provider.Exporter) GoogleTasksExporter(org.datatransferproject.datatransfer.google.tasks.GoogleTasksExporter) GooglePlusExporter(org.datatransferproject.datatransfer.google.gplus.GooglePlusExporter) GooglePhotosExporter(org.datatransferproject.datatransfer.google.photos.GooglePhotosExporter) GoogleContactsExporter(org.datatransferproject.datatransfer.google.contacts.GoogleContactsExporter) GoogleContactsExporter(org.datatransferproject.datatransfer.google.contacts.GoogleContactsExporter) Monitor(org.datatransferproject.api.launcher.Monitor) GooglePlusExporter(org.datatransferproject.datatransfer.google.gplus.GooglePlusExporter) GoogleVideosImporter(org.datatransferproject.datatransfer.google.videos.GoogleVideosImporter) GooglePhotosImporter(org.datatransferproject.datatransfer.google.photos.GooglePhotosImporter) GoogleContactsImporter(org.datatransferproject.datatransfer.google.contacts.GoogleContactsImporter) Importer(org.datatransferproject.spi.transfer.provider.Importer) GoogleMailImporter(org.datatransferproject.datatransfer.google.mail.GoogleMailImporter) GoogleCalendarImporter(org.datatransferproject.datatransfer.google.calendar.GoogleCalendarImporter) DriveImporter(org.datatransferproject.datatransfer.google.drive.DriveImporter) GoogleVideosImporter(org.datatransferproject.datatransfer.google.videos.GoogleVideosImporter) GoogleTasksImporter(org.datatransferproject.datatransfer.google.tasks.GoogleTasksImporter) GoogleContactsImporter(org.datatransferproject.datatransfer.google.contacts.GoogleContactsImporter) DriveImporter(org.datatransferproject.datatransfer.google.drive.DriveImporter) JobStore(org.datatransferproject.spi.cloud.storage.JobStore) GoogleVideosExporter(org.datatransferproject.datatransfer.google.videos.GoogleVideosExporter) IOException(java.io.IOException) ImmutableMap(com.google.common.collect.ImmutableMap) GooglePhotosExporter(org.datatransferproject.datatransfer.google.photos.GooglePhotosExporter) HttpTransport(com.google.api.client.http.HttpTransport) GoogleCalendarExporter(org.datatransferproject.datatransfer.google.calendar.GoogleCalendarExporter) GoogleTasksImporter(org.datatransferproject.datatransfer.google.tasks.GoogleTasksImporter) DriveExporter(org.datatransferproject.datatransfer.google.drive.DriveExporter) GoogleMailExporter(org.datatransferproject.datatransfer.google.mail.GoogleMailExporter)

Aggregations

Monitor (org.datatransferproject.api.launcher.Monitor)32 IOException (java.io.IOException)10 AppCredentials (org.datatransferproject.types.transfer.auth.AppCredentials)10 Before (org.junit.Before)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 HttpTransport (com.google.api.client.http.HttpTransport)7 ImmutableMap (com.google.common.collect.ImmutableMap)7 Importer (org.datatransferproject.spi.transfer.provider.Importer)7 TemporaryPerJobDataStore (org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore)6 JsonFactory (com.google.api.client.json.JsonFactory)5 JobStore (org.datatransferproject.spi.cloud.storage.JobStore)5 Exporter (org.datatransferproject.spi.transfer.provider.Exporter)5 TokensAndUrlAuthData (org.datatransferproject.types.transfer.auth.TokensAndUrlAuthData)5 OkHttpClient (okhttp3.OkHttpClient)4 KoofrClientFactory (org.datatransferproject.transfer.koofr.common.KoofrClientFactory)4 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)3 MockWebServer (okhttp3.mockwebserver.MockWebServer)3 GoogleCredentialFactory (org.datatransferproject.datatransfer.google.common.GoogleCredentialFactory)3 KoofrClient (org.datatransferproject.transfer.koofr.common.KoofrClient)3 Optional (java.util.Optional)2