use of org.datatransferproject.types.common.models.contacts.ContactsModelWrapper in project data-transfer-project by google.
the class SolidContactsExport method export.
@Override
public ExportResult<ContactsModelWrapper> export(UUID jobId, CookiesAndUrlAuthData authData, Optional<ExportInformation> exportInformation) throws Exception {
if (exportInformation.isPresent()) {
throw new IllegalStateException("Currently solid doesn't support paged exports");
}
checkState(authData.getCookies().size() == 1, "Exactly 1 cookie expected: %s", authData.getCookies());
SolidUtilities solidUtilities = new SolidUtilities(authData.getCookies().get(0));
String url = authData.getUrl();
List<List<VCard>> vCards = explore(url, solidUtilities);
// TODO: This flattens all the address books together, which isn't perfect.
List<VCard> allCards = new ArrayList<>();
vCards.forEach(allCards::addAll);
return new ExportResult<>(ResultType.END, new ContactsModelWrapper(Ezvcard.write(allCards).go()));
}
use of org.datatransferproject.types.common.models.contacts.ContactsModelWrapper in project data-transfer-project by google.
the class ManualTest method manualImport.
ManualTest manualImport() throws Exception {
SolidContactsImport importer = new SolidContactsImport();
importer.importItem(UUID.randomUUID(), executor, this.authData, new ContactsModelWrapper(TestData.VCARD_TEXT));
return this;
}
use of org.datatransferproject.types.common.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());
FakeIdempotentImportExecutor executor = new FakeIdempotentImportExecutor();
ImportResult result = contacts.importItem(UUID.randomUUID(), executor, token, wrapper);
}
use of org.datatransferproject.types.common.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, Optional.of(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.datatransferproject.types.common.models.contacts.ContactsModelWrapper 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, Optional.empty());
// 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());
}
Aggregations