Search in sources :

Example 6 with AppCredentials

use of org.datatransferproject.types.transfer.auth.AppCredentials in project data-transfer-project by google.

the class MicrosoftTransferExtension method initialize.

@Override
public void initialize(ExtensionContext context) {
    // times.
    if (initialized)
        return;
    TemporaryPerJobDataStore jobStore = context.getService(TemporaryPerJobDataStore.class);
    HttpTransport httpTransport = context.getService(HttpTransport.class);
    JsonFactory jsonFactory = context.getService(JsonFactory.class);
    TransformerService transformerService = new TransformerServiceImpl();
    OkHttpClient client = new OkHttpClient.Builder().build();
    ObjectMapper mapper = new ObjectMapper();
    AppCredentials appCredentials;
    try {
        appCredentials = context.getService(AppCredentialStore.class).getAppCredentials("MICROSOFT_KEY", "MICROSOFT_SECRET");
    } catch (IOException e) {
        Monitor monitor = context.getMonitor();
        monitor.info(() -> "Unable to retrieve Microsoft AppCredentials. Did you set MICROSOFT_KEY and MICROSOFT_SECRET?");
        return;
    }
    // Create the MicrosoftCredentialFactory with the given {@link AppCredentials}.
    MicrosoftCredentialFactory credentialFactory = new MicrosoftCredentialFactory(httpTransport, jsonFactory, appCredentials);
    Monitor monitor = context.getMonitor();
    ImmutableMap.Builder<String, Importer> importBuilder = ImmutableMap.builder();
    importBuilder.put(CONTACTS, new MicrosoftContactsImporter(BASE_GRAPH_URL, client, mapper, transformerService));
    importBuilder.put(CALENDAR, new MicrosoftCalendarImporter(BASE_GRAPH_URL, client, mapper, transformerService));
    importBuilder.put(PHOTOS, new MicrosoftPhotosImporter(BASE_GRAPH_URL, client, mapper, jobStore, monitor, credentialFactory));
    importerMap = importBuilder.build();
    ImmutableMap.Builder<String, Exporter> exporterBuilder = ImmutableMap.builder();
    exporterBuilder.put(CONTACTS, new MicrosoftContactsExporter(BASE_GRAPH_URL, client, mapper, transformerService));
    exporterBuilder.put(CALENDAR, new MicrosoftCalendarExporter(BASE_GRAPH_URL, client, mapper, transformerService));
    exporterBuilder.put(PHOTOS, new MicrosoftPhotosExporter(credentialFactory, jsonFactory, monitor));
    exporterBuilder.put(OFFLINE_DATA, new MicrosoftOfflineDataExporter(BASE_GRAPH_URL, client, mapper));
    exporterMap = exporterBuilder.build();
    initialized = true;
}
Also used : OkHttpClient(okhttp3.OkHttpClient) MicrosoftCalendarImporter(org.datatransferproject.transfer.microsoft.calendar.MicrosoftCalendarImporter) AppCredentials(org.datatransferproject.types.transfer.auth.AppCredentials) JsonFactory(com.google.api.client.json.JsonFactory) MicrosoftOfflineDataExporter(org.datatransferproject.transfer.microsoft.offline.MicrosoftOfflineDataExporter) MicrosoftPhotosExporter(org.datatransferproject.transfer.microsoft.photos.MicrosoftPhotosExporter) MicrosoftContactsExporter(org.datatransferproject.transfer.microsoft.contacts.MicrosoftContactsExporter) Exporter(org.datatransferproject.spi.transfer.provider.Exporter) MicrosoftCalendarExporter(org.datatransferproject.transfer.microsoft.calendar.MicrosoftCalendarExporter) MicrosoftCalendarExporter(org.datatransferproject.transfer.microsoft.calendar.MicrosoftCalendarExporter) Monitor(org.datatransferproject.api.launcher.Monitor) MicrosoftPhotosExporter(org.datatransferproject.transfer.microsoft.photos.MicrosoftPhotosExporter) TransformerServiceImpl(org.datatransferproject.transfer.microsoft.transformer.TransformerServiceImpl) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Importer(org.datatransferproject.spi.transfer.provider.Importer) MicrosoftPhotosImporter(org.datatransferproject.transfer.microsoft.photos.MicrosoftPhotosImporter) MicrosoftContactsImporter(org.datatransferproject.transfer.microsoft.contacts.MicrosoftContactsImporter) MicrosoftCalendarImporter(org.datatransferproject.transfer.microsoft.calendar.MicrosoftCalendarImporter) TemporaryPerJobDataStore(org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore) MicrosoftContactsImporter(org.datatransferproject.transfer.microsoft.contacts.MicrosoftContactsImporter) MicrosoftOfflineDataExporter(org.datatransferproject.transfer.microsoft.offline.MicrosoftOfflineDataExporter) MicrosoftCredentialFactory(org.datatransferproject.transfer.microsoft.common.MicrosoftCredentialFactory) IOException(java.io.IOException) MicrosoftPhotosImporter(org.datatransferproject.transfer.microsoft.photos.MicrosoftPhotosImporter) ImmutableMap(com.google.common.collect.ImmutableMap) HttpTransport(com.google.api.client.http.HttpTransport) MicrosoftContactsExporter(org.datatransferproject.transfer.microsoft.contacts.MicrosoftContactsExporter) TransformerService(org.datatransferproject.transfer.microsoft.transformer.TransformerService)

Example 7 with AppCredentials

use of org.datatransferproject.types.transfer.auth.AppCredentials in project data-transfer-project by google.

the class KoofrTransferExtension method initialize.

@Override
public void initialize(ExtensionContext context) {
    // rather than throwing if called multiple times.
    if (initialized)
        return;
    JobStore jobStore = context.getService(JobStore.class);
    HttpTransport httpTransport = context.getService(HttpTransport.class);
    JsonFactory jsonFactory = context.getService(JsonFactory.class);
    OkHttpClient client = new OkHttpClient.Builder().build();
    ObjectMapper mapper = new ObjectMapper();
    AppCredentials appCredentials;
    try {
        appCredentials = context.getService(AppCredentialStore.class).getAppCredentials("KOOFR_KEY", "KOOFR_SECRET");
    } catch (IOException e) {
        Monitor monitor = context.getMonitor();
        monitor.info(() -> "Unable to retrieve Koofr AppCredentials. Did you set KOOFR_KEY and KOOFR_SECRET?");
        return;
    }
    // Create the KoofrCredentialFactory with the given {@link AppCredentials}.
    KoofrCredentialFactory credentialFactory = new KoofrCredentialFactory(httpTransport, jsonFactory, appCredentials);
    Monitor monitor = context.getMonitor();
    int fileUploadReadTimeout = context.getSetting("koofrFileUploadReadTimeout", 60000);
    int fileUploadWriteTimeout = context.getSetting("koofrFileUploadWriteTimeout", 60000);
    monitor.info(() -> format("Configuring Koofr HTTP file upload client with read timeout %d ms and write timeout %d ms", fileUploadReadTimeout, fileUploadWriteTimeout));
    OkHttpClient fileUploadClient = client.newBuilder().readTimeout(fileUploadReadTimeout, TimeUnit.MILLISECONDS).writeTimeout(fileUploadReadTimeout, TimeUnit.MILLISECONDS).build();
    KoofrClientFactory koofrClientFactory = new KoofrClientFactory(BASE_API_URL, client, fileUploadClient, mapper, monitor, credentialFactory);
    ImmutableMap.Builder<String, Importer> importBuilder = ImmutableMap.builder();
    importBuilder.put(PHOTOS, new KoofrPhotosImporter(koofrClientFactory, monitor, jobStore));
    importBuilder.put(VIDEOS, new KoofrVideosImporter(koofrClientFactory, monitor));
    importerMap = importBuilder.build();
    ImmutableMap.Builder<String, Exporter> exportBuilder = ImmutableMap.builder();
    exportBuilder.put(PHOTOS, new KoofrPhotosExporter(koofrClientFactory, monitor));
    exportBuilder.put(VIDEOS, new KoofrVideosExporter(koofrClientFactory, monitor));
    exporterMap = exportBuilder.build();
    initialized = true;
}
Also used : KoofrPhotosExporter(org.datatransferproject.transfer.koofr.photos.KoofrPhotosExporter) OkHttpClient(okhttp3.OkHttpClient) KoofrClientFactory(org.datatransferproject.transfer.koofr.common.KoofrClientFactory) AppCredentials(org.datatransferproject.types.transfer.auth.AppCredentials) KoofrCredentialFactory(org.datatransferproject.transfer.koofr.common.KoofrCredentialFactory) JsonFactory(com.google.api.client.json.JsonFactory) JobStore(org.datatransferproject.spi.cloud.storage.JobStore) KoofrVideosImporter(org.datatransferproject.transfer.koofr.videos.KoofrVideosImporter) IOException(java.io.IOException) Exporter(org.datatransferproject.spi.transfer.provider.Exporter) KoofrPhotosExporter(org.datatransferproject.transfer.koofr.photos.KoofrPhotosExporter) KoofrVideosExporter(org.datatransferproject.transfer.koofr.videos.KoofrVideosExporter) ImmutableMap(com.google.common.collect.ImmutableMap) HttpTransport(com.google.api.client.http.HttpTransport) KoofrPhotosImporter(org.datatransferproject.transfer.koofr.photos.KoofrPhotosImporter) Monitor(org.datatransferproject.api.launcher.Monitor) KoofrVideosExporter(org.datatransferproject.transfer.koofr.videos.KoofrVideosExporter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) KoofrVideosImporter(org.datatransferproject.transfer.koofr.videos.KoofrVideosImporter) Importer(org.datatransferproject.spi.transfer.provider.Importer) KoofrPhotosImporter(org.datatransferproject.transfer.koofr.photos.KoofrPhotosImporter)

Example 8 with AppCredentials

use of org.datatransferproject.types.transfer.auth.AppCredentials in project data-transfer-project by google.

the class RememberTheMilkAuthServiceExtension method initialize.

@Override
public void initialize(ExtensionContext context) {
    if (initialized)
        return;
    AppCredentials appCredentials;
    try {
        appCredentials = context.getService(AppCredentialStore.class).getAppCredentials(RTM_KEY, RTM_SECRET);
    } catch (IOException e) {
        Monitor monitor = context.getMonitor();
        monitor.info(() -> format("Unable to retrieve RememberTheMilk AppCredentials. Did you set %s and %s?", RTM_KEY, RTM_SECRET), e);
        return;
    }
    Monitor monitor = context.getMonitor();
    importAuthDataGenerator = new RememberTheMilkAuthDataGenerator(appCredentials, AuthMode.IMPORT, monitor);
    exportAuthDataGenerator = new RememberTheMilkAuthDataGenerator(appCredentials, AuthMode.EXPORT, monitor);
    initialized = true;
}
Also used : Monitor(org.datatransferproject.api.launcher.Monitor) AppCredentials(org.datatransferproject.types.transfer.auth.AppCredentials) IOException(java.io.IOException)

Example 9 with AppCredentials

use of org.datatransferproject.types.transfer.auth.AppCredentials in project data-transfer-project by google.

the class RememberTheMilkTransferExtension method initialize.

@Override
public void initialize(ExtensionContext context) {
    if (initialized)
        return;
    AppCredentials credentials;
    try {
        credentials = context.getService(AppCredentialStore.class).getAppCredentials(RTM_KEY, RTM_SECRET);
    } catch (IOException e) {
        Monitor monitor = context.getMonitor();
        monitor.info(() -> format("Unable to retrieve RememberTheMilk AppCredentials. Did you set %s and %s?", RTM_KEY, RTM_SECRET), e);
        return;
    }
    Monitor monitor = context.getMonitor();
    exporter = new RememberTheMilkTasksExporter(credentials);
    importer = new RememberTheMilkTasksImporter(credentials, monitor);
    initialized = true;
}
Also used : Monitor(org.datatransferproject.api.launcher.Monitor) RememberTheMilkTasksExporter(org.datatransferproject.transfer.rememberthemilk.tasks.RememberTheMilkTasksExporter) RememberTheMilkTasksImporter(org.datatransferproject.transfer.rememberthemilk.tasks.RememberTheMilkTasksImporter) AppCredentials(org.datatransferproject.types.transfer.auth.AppCredentials) IOException(java.io.IOException)

Example 10 with AppCredentials

use of org.datatransferproject.types.transfer.auth.AppCredentials 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)

Aggregations

AppCredentials (org.datatransferproject.types.transfer.auth.AppCredentials)16 IOException (java.io.IOException)12 Monitor (org.datatransferproject.api.launcher.Monitor)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 Exporter (org.datatransferproject.spi.transfer.provider.Exporter)5 Importer (org.datatransferproject.spi.transfer.provider.Importer)5 HttpTransport (com.google.api.client.http.HttpTransport)4 JsonFactory (com.google.api.client.json.JsonFactory)4 PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)3 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2 OkHttpClient (okhttp3.OkHttpClient)2 GoogleCredentialFactory (org.datatransferproject.datatransfer.google.common.GoogleCredentialFactory)2 JobStore (org.datatransferproject.spi.cloud.storage.JobStore)2 TemporaryPerJobDataStore (org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore)2 ImportResult (org.datatransferproject.spi.transfer.provider.ImportResult)2 PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)2 TokenSecretAuthData (org.datatransferproject.types.transfer.auth.TokenSecretAuthData)2 Before (org.junit.Before)2