Search in sources :

Example 1 with Exporter

use of org.datatransferproject.spi.transfer.provider.Exporter in project data-transfer-project by google.

the class BloggerTransferExtension method initialize.

@Override
public void initialize(ExtensionContext context) {
    // times.
    if (initialized) {
        return;
    }
    Monitor monitor = context.getMonitor();
    AppCredentials appCredentials;
    try {
        appCredentials = context.getService(AppCredentialStore.class).getAppCredentials("GOOGLEBLOGGER_KEY", "GOOGLEBLOGGER_SECRET");
    } catch (IOException e) {
        monitor.info(() -> "Unable to retrieve Google AppCredentials. " + "Did you set GOOGLEBLOGGER_KEY and GOOGLEBLOGGER_SECRET?");
        return;
    }
    HttpTransport httpTransport = context.getService(HttpTransport.class);
    JsonFactory jsonFactory = context.getService(JsonFactory.class);
    // 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("SOCIAL-POSTS", new GoogleBloggerImporter(credentialFactory));
    importerMap = importerBuilder.build();
    ImmutableMap.Builder<String, Exporter> exporterBuilder = ImmutableMap.builder();
    exporterMap = exporterBuilder.build();
    initialized = true;
}
Also used : AppCredentials(org.datatransferproject.types.transfer.auth.AppCredentials) JsonFactory(com.google.api.client.json.JsonFactory) IOException(java.io.IOException) GoogleCredentialFactory(org.datatransferproject.datatransfer.google.common.GoogleCredentialFactory) Exporter(org.datatransferproject.spi.transfer.provider.Exporter) ImmutableMap(com.google.common.collect.ImmutableMap) HttpTransport(com.google.api.client.http.HttpTransport) Monitor(org.datatransferproject.api.launcher.Monitor) GoogleBloggerImporter(org.datatransferproject.datatransfer.google.blogger.GoogleBloggerImporter) GoogleBloggerImporter(org.datatransferproject.datatransfer.google.blogger.GoogleBloggerImporter) Importer(org.datatransferproject.spi.transfer.provider.Importer)

Example 2 with Exporter

use of org.datatransferproject.spi.transfer.provider.Exporter 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 3 with Exporter

use of org.datatransferproject.spi.transfer.provider.Exporter 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 4 with Exporter

use of org.datatransferproject.spi.transfer.provider.Exporter in project data-transfer-project by google.

the class LocalExportTestRunner method main.

@SuppressWarnings("unchecked")
public static void main(String... args) throws Exception {
    AuthTestDriver authTestDriver = new AuthTestDriver();
    MicrosoftTransferExtension serviceProvider = new MicrosoftTransferExtension();
    TokenAuthData token = authTestDriver.getOAuthTokenCode();
    Exporter<TokenAuthData, ContactsModelWrapper> contacts = (Exporter<TokenAuthData, ContactsModelWrapper>) serviceProvider.getExporter("CONTACTS");
    ExportResult<ContactsModelWrapper> wrapper = contacts.export(UUID.randomUUID(), token, Optional.empty());
}
Also used : TokenAuthData(org.datatransferproject.types.transfer.auth.TokenAuthData) MicrosoftTransferExtension(org.datatransferproject.transfer.microsoft.MicrosoftTransferExtension) ContactsModelWrapper(org.datatransferproject.types.common.models.contacts.ContactsModelWrapper) AuthTestDriver(org.datatransferproject.auth.microsoft.harness.AuthTestDriver) Exporter(org.datatransferproject.spi.transfer.provider.Exporter)

Example 5 with Exporter

use of org.datatransferproject.spi.transfer.provider.Exporter 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

Exporter (org.datatransferproject.spi.transfer.provider.Exporter)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 IOException (java.io.IOException)5 Monitor (org.datatransferproject.api.launcher.Monitor)5 Importer (org.datatransferproject.spi.transfer.provider.Importer)5 AppCredentials (org.datatransferproject.types.transfer.auth.AppCredentials)5 HttpTransport (com.google.api.client.http.HttpTransport)4 JsonFactory (com.google.api.client.json.JsonFactory)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 OkHttpClient (okhttp3.OkHttpClient)2 GoogleCredentialFactory (org.datatransferproject.datatransfer.google.common.GoogleCredentialFactory)2 JobStore (org.datatransferproject.spi.cloud.storage.JobStore)2 AuthTestDriver (org.datatransferproject.auth.microsoft.harness.AuthTestDriver)1 GoogleBloggerImporter (org.datatransferproject.datatransfer.google.blogger.GoogleBloggerImporter)1 GoogleCalendarExporter (org.datatransferproject.datatransfer.google.calendar.GoogleCalendarExporter)1 GoogleCalendarImporter (org.datatransferproject.datatransfer.google.calendar.GoogleCalendarImporter)1 GoogleContactsExporter (org.datatransferproject.datatransfer.google.contacts.GoogleContactsExporter)1 GoogleContactsImporter (org.datatransferproject.datatransfer.google.contacts.GoogleContactsImporter)1 DriveExporter (org.datatransferproject.datatransfer.google.drive.DriveExporter)1 DriveImporter (org.datatransferproject.datatransfer.google.drive.DriveImporter)1