use of org.dataportabilityproject.types.transfer.models.contacts.ContactsModelWrapper in project data-transfer-project by google.
the class GoogleContactsExporterTest method exportSubsequentPage.
@Test
public void exportSubsequentPage() throws IOException {
setUpSinglePersonResponse();
// Looking at a subsequent page, with no pages after it
PaginationData paginationData = new StringPaginationToken(NEXT_PAGE_TOKEN);
ExportInformation exportInformation = new ExportInformation(paginationData, null);
listConnectionsResponse.setNextPageToken(null);
when(listConnectionsRequest.setPageToken(NEXT_PAGE_TOKEN)).thenReturn(listConnectionsRequest);
// Run test
ExportResult<ContactsModelWrapper> result = contactsService.export(UUID.randomUUID(), null, exportInformation);
// Verify correct calls were made - i.e., token was added before execution
InOrder inOrder = Mockito.inOrder(listConnectionsRequest);
inOrder.verify(listConnectionsRequest).setPageToken(NEXT_PAGE_TOKEN);
inOrder.verify(listConnectionsRequest).execute();
// Check continuation data
ContinuationData continuationData = (ContinuationData) result.getContinuationData();
assertThat(continuationData.getContainerResources()).isEmpty();
assertThat(continuationData.getPaginationData()).isNull();
}
use of org.dataportabilityproject.types.transfer.models.contacts.ContactsModelWrapper in project data-transfer-project by google.
the class LocalImportTestRunner method main.
@SuppressWarnings("unchecked")
public static void main(String... args) throws Exception {
AuthTestDriver authTestDriver = new AuthTestDriver();
MicrosoftTransferExtension serviceProvider = new MicrosoftTransferExtension();
TokenAuthData token = authTestDriver.getOAuthTokenCode();
Importer<TokenAuthData, ContactsModelWrapper> contacts = (Importer<TokenAuthData, ContactsModelWrapper>) serviceProvider.getImporter("contacts");
ContactsModelWrapper wrapper = new ContactsModelWrapper(createCards());
ImportResult result = contacts.importItem(UUID.randomUUID(), token, wrapper);
}
use of org.dataportabilityproject.types.transfer.models.contacts.ContactsModelWrapper in project data-transfer-project by google.
the class MicrosoftContactsExporter method transform.
private ContactsModelWrapper transform(List<Map<String, Object>> rawContacts) {
StringWriter stringWriter = new StringWriter();
try (JCardWriter writer = new JCardWriter(stringWriter)) {
for (Map<String, Object> rawContact : rawContacts) {
TransformResult<VCard> result = transformerService.transform(VCard.class, rawContact);
if (result.hasProblems()) {
// FIXME log problem
continue;
}
writer.write(result.getTransformed());
}
} catch (IOException e) {
// TODO log
e.printStackTrace();
return new ContactsModelWrapper("");
}
return new ContactsModelWrapper(stringWriter.toString());
}
use of org.dataportabilityproject.types.transfer.models.contacts.ContactsModelWrapper 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