Search in sources :

Example 1 with TransformResult

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

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 ImportResult (org.dataportabilityproject.spi.transfer.provider.ImportResult)1 Importer (org.dataportabilityproject.spi.transfer.provider.Importer)1 RequestHelper.batchRequest (org.dataportabilityproject.transfer.microsoft.common.RequestHelper.batchRequest)1 RequestHelper.createRequest (org.dataportabilityproject.transfer.microsoft.common.RequestHelper.createRequest)1 TransformResult (org.dataportabilityproject.transfer.microsoft.transformer.TransformResult)1 TransformerService (org.dataportabilityproject.transfer.microsoft.transformer.TransformerService)1 TokenAuthData (org.dataportabilityproject.types.transfer.auth.TokenAuthData)1 ContactsModelWrapper (org.dataportabilityproject.types.transfer.models.contacts.ContactsModelWrapper)1