use of ezvcard.io.json.JCardReader in project data-transfer-project by google.
the class GoogleContactsExporterTest method exportFirstPage.
@Test
public void exportFirstPage() throws IOException {
setUpSinglePersonResponse();
// Looking at first page, with at least one page after it
listConnectionsResponse.setNextPageToken(NEXT_PAGE_TOKEN);
ExportResult<ContactsModelWrapper> result = contactsService.export(UUID.randomUUID(), null);
// Check that correct methods were called
verify(connections).list(SELF_RESOURCE);
InOrder inOrder = Mockito.inOrder(getBatchGet);
inOrder.verify(getBatchGet).setResourceNames(Collections.singletonList(RESOURCE_NAME));
inOrder.verify(getBatchGet).setPersonFields(PERSON_FIELDS);
inOrder.verify(getBatchGet).execute();
// Check continuation data
ContinuationData continuationData = (ContinuationData) result.getContinuationData();
assertThat(continuationData.getContainerResources()).isEmpty();
StringPaginationToken paginationToken = (StringPaginationToken) ((ContinuationData) result.getContinuationData()).getPaginationData();
assertThat(paginationToken.getToken()).isEqualTo(NEXT_PAGE_TOKEN);
// Check that the right number of VCards was returned
JCardReader reader = new JCardReader(result.getExportedData().getVCards());
List<VCard> vCardList = reader.readAll();
assertThat(vCardList.size()).isEqualTo(connectionsList.size());
}
use of ezvcard.io.json.JCardReader in project data-transfer-project by google.
the class GoogleContactsImporter method importItem.
@Override
public ImportResult importItem(UUID jobId, TokensAndUrlAuthData authData, ContactsModelWrapper data) {
JCardReader reader = new JCardReader(data.getVCards());
try {
// TODO(olsona): address any other problems that might arise in conversion
List<VCard> vCardList = reader.readAll();
for (VCard vCard : vCardList) {
Person person = convert(vCard);
getOrCreatePeopleService(authData).people().createContact(person).execute();
}
return ImportResult.OK;
} catch (IOException e) {
return new ImportResult(ImportResult.ResultType.ERROR, e.getMessage());
}
}
use of ezvcard.io.json.JCardReader 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());
}
}
Aggregations