Search in sources :

Example 1 with TransformResult

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

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 VCard (ezvcard.VCard)1 JCardReader (ezvcard.io.json.JCardReader)1 IOException (java.io.IOException)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 OkHttpClient (okhttp3.OkHttpClient)1 IdempotentImportExecutor (org.datatransferproject.spi.transfer.idempotentexecutor.IdempotentImportExecutor)1 ImportResult (org.datatransferproject.spi.transfer.provider.ImportResult)1 Importer (org.datatransferproject.spi.transfer.provider.Importer)1 RequestHelper.batchRequest (org.datatransferproject.transfer.microsoft.common.RequestHelper.batchRequest)1 RequestHelper.createRequest (org.datatransferproject.transfer.microsoft.common.RequestHelper.createRequest)1 TransformResult (org.datatransferproject.transfer.microsoft.transformer.TransformResult)1 TransformerService (org.datatransferproject.transfer.microsoft.transformer.TransformerService)1 ContactsModelWrapper (org.datatransferproject.types.common.models.contacts.ContactsModelWrapper)1 TokenAuthData (org.datatransferproject.types.transfer.auth.TokenAuthData)1