Search in sources :

Example 1 with MicrosoftCalendarExporter

use of org.datatransferproject.transfer.microsoft.calendar.MicrosoftCalendarExporter in project data-transfer-project by google.

the class MicrosoftCalendarExportTest method testExport.

@Test
public void testExport() throws Exception {
    server.enqueue(new MockResponse().setBody(CALENDARS_RESPONSE));
    server.enqueue(new MockResponse().setBody(CALENDAR1_EVENTS_RESPONSE));
    server.enqueue(new MockResponse().setBody(CALENDAR2_EVENTS_RESPONSE));
    server.start();
    HttpUrl baseUrl = server.url("");
    MicrosoftCalendarExporter exporter = new MicrosoftCalendarExporter(baseUrl.toString(), client, mapper, transformerService);
    ExportResult<CalendarContainerResource> resource = exporter.export(UUID.randomUUID(), token, Optional.empty());
    CalendarContainerResource calendarResource = resource.getExportedData();
    Assert.assertEquals(2, calendarResource.getCalendars().size());
    Assert.assertFalse(calendarResource.getCalendars().stream().anyMatch(c -> "Calendar1".equals(c.getId()) && "Calendar2".equals(c.getId())));
    Assert.assertEquals(2, calendarResource.getEvents().size());
    Assert.assertFalse(calendarResource.getEvents().stream().anyMatch(e -> "Test Appointment 1".equals(e.getTitle()) && "Test Appointment 2".equals(e.getTitle())));
}
Also used : MicrosoftCalendarExporter(org.datatransferproject.transfer.microsoft.calendar.MicrosoftCalendarExporter) CalendarContainerResource(org.datatransferproject.types.common.models.calendar.CalendarContainerResource) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult) TransformerServiceImpl(org.datatransferproject.transfer.microsoft.transformer.TransformerServiceImpl) MockWebServer(com.squareup.okhttp.mockwebserver.MockWebServer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) Test(org.junit.Test) UUID(java.util.UUID) MicrosoftCalendarExporter(org.datatransferproject.transfer.microsoft.calendar.MicrosoftCalendarExporter) HttpUrl(com.squareup.okhttp.HttpUrl) OkHttpClient(okhttp3.OkHttpClient) TokensAndUrlAuthData(org.datatransferproject.types.transfer.auth.TokensAndUrlAuthData) After(org.junit.After) Optional(java.util.Optional) Assert(org.junit.Assert) Before(org.junit.Before) MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) CalendarContainerResource(org.datatransferproject.types.common.models.calendar.CalendarContainerResource) HttpUrl(com.squareup.okhttp.HttpUrl) Test(org.junit.Test)

Example 2 with MicrosoftCalendarExporter

use of org.datatransferproject.transfer.microsoft.calendar.MicrosoftCalendarExporter 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)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 OkHttpClient (okhttp3.OkHttpClient)2 MicrosoftCalendarExporter (org.datatransferproject.transfer.microsoft.calendar.MicrosoftCalendarExporter)2 TransformerServiceImpl (org.datatransferproject.transfer.microsoft.transformer.TransformerServiceImpl)2 HttpTransport (com.google.api.client.http.HttpTransport)1 JsonFactory (com.google.api.client.json.JsonFactory)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 HttpUrl (com.squareup.okhttp.HttpUrl)1 MockResponse (com.squareup.okhttp.mockwebserver.MockResponse)1 MockWebServer (com.squareup.okhttp.mockwebserver.MockWebServer)1 IOException (java.io.IOException)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 Monitor (org.datatransferproject.api.launcher.Monitor)1 TemporaryPerJobDataStore (org.datatransferproject.spi.cloud.storage.TemporaryPerJobDataStore)1 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)1 Exporter (org.datatransferproject.spi.transfer.provider.Exporter)1 Importer (org.datatransferproject.spi.transfer.provider.Importer)1 MicrosoftCalendarImporter (org.datatransferproject.transfer.microsoft.calendar.MicrosoftCalendarImporter)1 MicrosoftCredentialFactory (org.datatransferproject.transfer.microsoft.common.MicrosoftCredentialFactory)1