Search in sources :

Example 11 with Monitor

use of org.datatransferproject.api.launcher.Monitor 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 12 with Monitor

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

the class GoogleMailImporterTest method setUp.

@Before
public void setUp() throws IOException {
    Label label = new Label();
    label.setId(LABEL1);
    label.setName(LABEL1);
    labelsListResponse = new ListLabelsResponse().setLabels(Collections.singletonList(label));
    Monitor monitor = new Monitor() {
    };
    googleMailImporter = new GoogleMailImporter(googleCredentialFactory, gmail, monitor);
    executor = new FakeIdempotentImportExecutor();
    when(gmail.users()).thenReturn(users);
    when(users.messages()).thenReturn(messages);
    when(messages.insert(anyString(), any(Message.class))).thenReturn(insert);
    when(insert.execute()).thenReturn(new Message().setId("fooBar"));
    when(users.labels()).thenReturn(labels);
    when(labels.list(anyString())).thenReturn(labelsList);
    when(labelsList.execute()).thenReturn(labelsListResponse);
    when(labels.create(anyString(), any(Label.class))).thenReturn(labelsCreate);
    when(labelsCreate.execute()).thenReturn(label);
    verifyNoInteractions(googleCredentialFactory);
}
Also used : Monitor(org.datatransferproject.api.launcher.Monitor) Message(com.google.api.services.gmail.model.Message) FakeIdempotentImportExecutor(org.datatransferproject.test.types.FakeIdempotentImportExecutor) Label(com.google.api.services.gmail.model.Label) ListLabelsResponse(com.google.api.services.gmail.model.ListLabelsResponse) Before(org.junit.Before)

Example 13 with Monitor

use of org.datatransferproject.api.launcher.Monitor 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 14 with Monitor

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

the class KoofrVideosExporterTest 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 KoofrVideosExporter(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 15 with Monitor

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

the class KoofrPhotosImporterTest method setUp.

@Before
public void setUp() throws Exception {
    server = new MockWebServer();
    server.start();
    client = mock(KoofrClient.class);
    clientFactory = mock(KoofrClientFactory.class);
    when(clientFactory.create(any())).thenReturn(client);
    monitor = mock(Monitor.class);
    jobStore = mock(JobStore.class);
    importer = new KoofrPhotosImporter(clientFactory, monitor, jobStore);
    executor = mock(IdempotentImportExecutor.class);
    when(executor.executeAndSwallowIOExceptions(any(), any(), any())).then((InvocationOnMock invocation) -> {
        Callable<String> callable = invocation.getArgument(2);
        return callable.call();
    });
    authData = new TokensAndUrlAuthData("acc", "refresh", "");
}
Also used : KoofrClientFactory(org.datatransferproject.transfer.koofr.common.KoofrClientFactory) Monitor(org.datatransferproject.api.launcher.Monitor) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MockWebServer(okhttp3.mockwebserver.MockWebServer) KoofrClient(org.datatransferproject.transfer.koofr.common.KoofrClient) TokensAndUrlAuthData(org.datatransferproject.types.transfer.auth.TokensAndUrlAuthData) JobStore(org.datatransferproject.spi.cloud.storage.JobStore) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) IdempotentImportExecutor(org.datatransferproject.spi.transfer.idempotentexecutor.IdempotentImportExecutor) Before(org.junit.Before)

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