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);
}
}
Aggregations