Search in sources :

Example 1 with MicrosoftCalendarExporter

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

the class MicrosoftTransferExtension method getExporter.

@Override
public Exporter<?, ?> getExporter(String transferDataType) {
    // TODO consider memoizing w/ Supplier but we will only use once and pass to worker.
    // This could allow us to refactor these params into supplier.
    OkHttpClient client = new OkHttpClient.Builder().build();
    ObjectMapper mapper = new ObjectMapper();
    TransformerService transformerService = new TransformerServiceImpl();
    if (transferDataType.equals(CONTACTS)) {
        return new MicrosoftContactsExporter(BASE_GRAPH_URL, client, mapper, transformerService);
    }
    if (transferDataType.equals(CALENDAR)) {
        return new MicrosoftCalendarExporter(BASE_GRAPH_URL, client, mapper, transformerService);
    }
    return null;
}
Also used : MicrosoftCalendarExporter(org.dataportabilityproject.transfer.microsoft.calendar.MicrosoftCalendarExporter) MicrosoftContactsExporter(org.dataportabilityproject.transfer.microsoft.contacts.MicrosoftContactsExporter) OkHttpClient(okhttp3.OkHttpClient) TransformerService(org.dataportabilityproject.transfer.microsoft.transformer.TransformerService) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TransformerServiceImpl(org.dataportabilityproject.transfer.microsoft.transformer.TransformerServiceImpl)

Example 2 with MicrosoftCalendarExporter

use of org.dataportabilityproject.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);
    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.dataportabilityproject.transfer.microsoft.calendar.MicrosoftCalendarExporter) MockWebServer(com.squareup.okhttp.mockwebserver.MockWebServer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) ExportResult(org.dataportabilityproject.spi.transfer.provider.ExportResult) TokenAuthData(org.dataportabilityproject.types.transfer.auth.TokenAuthData) Test(org.junit.Test) UUID(java.util.UUID) MicrosoftCalendarExporter(org.dataportabilityproject.transfer.microsoft.calendar.MicrosoftCalendarExporter) HttpUrl(com.squareup.okhttp.HttpUrl) CalendarContainerResource(org.dataportabilityproject.types.transfer.models.calendar.CalendarContainerResource) TransformerServiceImpl(org.dataportabilityproject.transfer.microsoft.transformer.TransformerServiceImpl) OkHttpClient(okhttp3.OkHttpClient) After(org.junit.After) Assert(org.junit.Assert) Before(org.junit.Before) MockResponse(com.squareup.okhttp.mockwebserver.MockResponse) CalendarContainerResource(org.dataportabilityproject.types.transfer.models.calendar.CalendarContainerResource) HttpUrl(com.squareup.okhttp.HttpUrl) Test(org.junit.Test)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 OkHttpClient (okhttp3.OkHttpClient)2 MicrosoftCalendarExporter (org.dataportabilityproject.transfer.microsoft.calendar.MicrosoftCalendarExporter)2 TransformerServiceImpl (org.dataportabilityproject.transfer.microsoft.transformer.TransformerServiceImpl)2 HttpUrl (com.squareup.okhttp.HttpUrl)1 MockResponse (com.squareup.okhttp.mockwebserver.MockResponse)1 MockWebServer (com.squareup.okhttp.mockwebserver.MockWebServer)1 UUID (java.util.UUID)1 ExportResult (org.dataportabilityproject.spi.transfer.provider.ExportResult)1 MicrosoftContactsExporter (org.dataportabilityproject.transfer.microsoft.contacts.MicrosoftContactsExporter)1 TransformerService (org.dataportabilityproject.transfer.microsoft.transformer.TransformerService)1 TokenAuthData (org.dataportabilityproject.types.transfer.auth.TokenAuthData)1 CalendarContainerResource (org.dataportabilityproject.types.transfer.models.calendar.CalendarContainerResource)1 After (org.junit.After)1 Assert (org.junit.Assert)1 Before (org.junit.Before)1 Test (org.junit.Test)1