Search in sources :

Example 1 with TokenAuthData

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

the class AuthTestDriver method getOAuthTokenCode.

/**
 * Performs an OAuth flow using the general AuthDataGenerator, returning a token.
 *
 * @return the token
 */
public TokenAuthData getOAuthTokenCode() throws Exception {
    OkHttpClient client = TestHelper.createTestBuilder(callbackHost).build();
    AuthDataGenerator authDataGenerator = new MicrosoftAuthServiceExtension().getAuthDataGenerator("CONTACTS", AuthMode.EXPORT);
    AuthFlowConfiguration configuration = authDataGenerator.generateConfiguration(callbackBase, "1");
    Desktop desktop = Desktop.getDesktop();
    desktop.browse(new URI(configuration.getAuthUrl()));
    // Execute the request and retrieve the auth code.
    String authCode = retrieveAuthCode(client);
    // get the token
    TokenAuthData tokenData = (TokenAuthData) authDataGenerator.generateAuthData(callbackBase, authCode, "1", configuration.getInitialAuthData(), null);
    // System.out.println("TOKEN: " + tokenData.getToken());
    return tokenData;
}
Also used : MicrosoftAuthServiceExtension(org.datatransferproject.auth.microsoft.MicrosoftAuthServiceExtension) AuthFlowConfiguration(org.datatransferproject.spi.api.types.AuthFlowConfiguration) AuthDataGenerator(org.datatransferproject.spi.api.auth.AuthDataGenerator) OkHttpClient(okhttp3.OkHttpClient) Desktop(java.awt.Desktop) TokenAuthData(org.datatransferproject.types.transfer.auth.TokenAuthData) URI(java.net.URI)

Example 2 with TokenAuthData

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

the class LocalImportTestRunner method main.

@SuppressWarnings("unchecked")
public static void main(String... args) throws Exception {
    AuthTestDriver authTestDriver = new AuthTestDriver();
    MicrosoftTransferExtension serviceProvider = new MicrosoftTransferExtension();
    TokenAuthData token = authTestDriver.getOAuthTokenCode();
    Importer<TokenAuthData, ContactsModelWrapper> contacts = (Importer<TokenAuthData, ContactsModelWrapper>) serviceProvider.getImporter("CONTACTS");
    ContactsModelWrapper wrapper = new ContactsModelWrapper(createCards());
    FakeIdempotentImportExecutor executor = new FakeIdempotentImportExecutor();
    ImportResult result = contacts.importItem(UUID.randomUUID(), executor, token, wrapper);
}
Also used : ImportResult(org.datatransferproject.spi.transfer.provider.ImportResult) TokenAuthData(org.datatransferproject.types.transfer.auth.TokenAuthData) FakeIdempotentImportExecutor(org.datatransferproject.test.types.FakeIdempotentImportExecutor) MicrosoftTransferExtension(org.datatransferproject.transfer.microsoft.MicrosoftTransferExtension) ContactsModelWrapper(org.datatransferproject.types.common.models.contacts.ContactsModelWrapper) AuthTestDriver(org.datatransferproject.auth.microsoft.harness.AuthTestDriver) Importer(org.datatransferproject.spi.transfer.provider.Importer)

Example 3 with TokenAuthData

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

the class MicrosoftContactsImporter method importItem.

@Override
public ImportResult importItem(UUID jobId, IdempotentImportExecutor idempotentImportExecutor, TokenAuthData authData, ContactsModelWrapper wrapper) {
    JCardReader reader = new JCardReader(wrapper.getVCards());
    try {
        List<VCard> cards = reader.readAll();
        List<String> problems = new ArrayList<>();
        int[] id = new int[] { 1 };
        List<Map<String, Object>> requests = cards.stream().map(card -> {
            TransformResult<LinkedHashMap> result = transformerService.transform(LinkedHashMap.class, card);
            problems.addAll(result.getProblems());
            LinkedHashMap contact = result.getTransformed();
            Map<String, Object> request = createRequest(id[0], CONTACTS_URL, contact);
            id[0]++;
            return request;
        }).collect(toList());
        if (!problems.isEmpty()) {
        // TODO log problems
        }
        return batchRequest(authData, requests, baseUrl, client, objectMapper).getResult();
    } catch (IOException e) {
        // TODO log
        e.printStackTrace();
        return new ImportResult(e);
    }
}
Also used : VCard(ezvcard.VCard) IdempotentImportExecutor(org.datatransferproject.spi.transfer.idempotentexecutor.IdempotentImportExecutor) ImportResult(org.datatransferproject.spi.transfer.provider.ImportResult) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) UUID(java.util.UUID) RequestHelper.createRequest(org.datatransferproject.transfer.microsoft.common.RequestHelper.createRequest) TokenAuthData(org.datatransferproject.types.transfer.auth.TokenAuthData) ArrayList(java.util.ArrayList) TransformerService(org.datatransferproject.transfer.microsoft.transformer.TransformerService) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) OkHttpClient(okhttp3.OkHttpClient) TransformResult(org.datatransferproject.transfer.microsoft.transformer.TransformResult) Map(java.util.Map) JCardReader(ezvcard.io.json.JCardReader) ContactsModelWrapper(org.datatransferproject.types.common.models.contacts.ContactsModelWrapper) Importer(org.datatransferproject.spi.transfer.provider.Importer) RequestHelper.batchRequest(org.datatransferproject.transfer.microsoft.common.RequestHelper.batchRequest) TransformResult(org.datatransferproject.transfer.microsoft.transformer.TransformResult) ImportResult(org.datatransferproject.spi.transfer.provider.ImportResult) ArrayList(java.util.ArrayList) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) JCardReader(ezvcard.io.json.JCardReader) VCard(ezvcard.VCard) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 4 with TokenAuthData

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

the class MicrosoftCalendarImportTest method setUp.

@Before
public void setUp() {
    client = new OkHttpClient.Builder().build();
    mapper = new ObjectMapper();
    transformerService = new TransformerServiceImpl();
    token = new TokenAuthData("token456");
    server = new MockWebServer();
}
Also used : TokenAuthData(org.datatransferproject.types.transfer.auth.TokenAuthData) MockWebServer(com.squareup.okhttp.mockwebserver.MockWebServer) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TransformerServiceImpl(org.datatransferproject.transfer.microsoft.transformer.TransformerServiceImpl) Before(org.junit.Before)

Example 5 with TokenAuthData

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

Aggregations

TokenAuthData (org.datatransferproject.types.transfer.auth.TokenAuthData)5 ContactsModelWrapper (org.datatransferproject.types.common.models.contacts.ContactsModelWrapper)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 OkHttpClient (okhttp3.OkHttpClient)2 AuthTestDriver (org.datatransferproject.auth.microsoft.harness.AuthTestDriver)2 ImportResult (org.datatransferproject.spi.transfer.provider.ImportResult)2 Importer (org.datatransferproject.spi.transfer.provider.Importer)2 MicrosoftTransferExtension (org.datatransferproject.transfer.microsoft.MicrosoftTransferExtension)2 MockWebServer (com.squareup.okhttp.mockwebserver.MockWebServer)1 VCard (ezvcard.VCard)1 JCardReader (ezvcard.io.json.JCardReader)1 Desktop (java.awt.Desktop)1 IOException (java.io.IOException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Collectors.toList (java.util.stream.Collectors.toList)1