Search in sources :

Example 6 with TokenAuthData

use of org.dataportabilityproject.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();
    jobStore = new MockJobStore();
}
Also used : TokenAuthData(org.dataportabilityproject.types.transfer.auth.TokenAuthData) MockWebServer(com.squareup.okhttp.mockwebserver.MockWebServer) MockJobStore(org.dataportabilityproject.transfer.microsoft.helper.MockJobStore) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TransformerServiceImpl(org.dataportabilityproject.transfer.microsoft.transformer.TransformerServiceImpl) Before(org.junit.Before)

Example 7 with TokenAuthData

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

the class MicrosoftContactsImporter method importItem.

@Override
public ImportResult importItem(UUID jobId, 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(ImportResult.ResultType.ERROR, "Error deserializing contacts: " + e.getMessage());
    }
}
Also used : VCard(ezvcard.VCard) RequestHelper.createRequest(org.dataportabilityproject.transfer.microsoft.common.RequestHelper.createRequest) RequestHelper.batchRequest(org.dataportabilityproject.transfer.microsoft.common.RequestHelper.batchRequest) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TokenAuthData(org.dataportabilityproject.types.transfer.auth.TokenAuthData) IOException(java.io.IOException) UUID(java.util.UUID) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) TransformResult(org.dataportabilityproject.transfer.microsoft.transformer.TransformResult) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) OkHttpClient(okhttp3.OkHttpClient) Map(java.util.Map) JCardReader(ezvcard.io.json.JCardReader) TransformerService(org.dataportabilityproject.transfer.microsoft.transformer.TransformerService) ContactsModelWrapper(org.dataportabilityproject.types.transfer.models.contacts.ContactsModelWrapper) ImportResult(org.dataportabilityproject.spi.transfer.provider.ImportResult) Importer(org.dataportabilityproject.spi.transfer.provider.Importer) TransformResult(org.dataportabilityproject.transfer.microsoft.transformer.TransformResult) ImportResult(org.dataportabilityproject.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)

Aggregations

TokenAuthData (org.dataportabilityproject.types.transfer.auth.TokenAuthData)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 ContactsModelWrapper (org.dataportabilityproject.types.transfer.models.contacts.ContactsModelWrapper)3 MockWebServer (com.squareup.okhttp.mockwebserver.MockWebServer)2 IOException (java.io.IOException)2 Map (java.util.Map)2 OkHttpClient (okhttp3.OkHttpClient)2 AuthTestDriver (org.dataportabilityproject.auth.microsoft.harness.AuthTestDriver)2 ImportResult (org.dataportabilityproject.spi.transfer.provider.ImportResult)2 Importer (org.dataportabilityproject.spi.transfer.provider.Importer)2 MicrosoftTransferExtension (org.dataportabilityproject.transfer.microsoft.MicrosoftTransferExtension)2 TransformerServiceImpl (org.dataportabilityproject.transfer.microsoft.transformer.TransformerServiceImpl)2 Before (org.junit.Before)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 VCard (ezvcard.VCard)1 JCardReader (ezvcard.io.json.JCardReader)1 Desktop (java.awt.Desktop)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1