Search in sources :

Example 1 with ContactsModelWrapper

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()));
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ContactsModelWrapper(org.datatransferproject.types.common.models.contacts.ContactsModelWrapper) VCard(ezvcard.VCard) SolidUtilities(org.datatransferproject.transfer.solid.SolidUtilities) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult)

Example 2 with ContactsModelWrapper

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;
}
Also used : ContactsModelWrapper(org.datatransferproject.types.common.models.contacts.ContactsModelWrapper)

Example 3 with ContactsModelWrapper

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);
}
Also used : ImportResult(org.datatransferproject.spi.transfer.provider.ImportResult) TokenAuthData(org.datatransferproject.types.transfer.auth.TokenAuthData) FakeIdempotentImportExecutor(org.datatransferproject.test.types.FakeIdempotentImportExecutor) MicrosoftTransferExtension(org.datatransferproject.transfer.microsoft.MicrosoftTransferExtension) ContactsModelWrapper(org.datatransferproject.types.common.models.contacts.ContactsModelWrapper) AuthTestDriver(org.datatransferproject.auth.microsoft.harness.AuthTestDriver) Importer(org.datatransferproject.spi.transfer.provider.Importer)

Example 4 with ContactsModelWrapper

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();
}
Also used : ExportInformation(org.datatransferproject.types.common.ExportInformation) PaginationData(org.datatransferproject.types.common.PaginationData) InOrder(org.mockito.InOrder) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) ContactsModelWrapper(org.datatransferproject.types.common.models.contacts.ContactsModelWrapper) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) Test(org.junit.Test)

Example 5 with ContactsModelWrapper

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());
}
Also used : InOrder(org.mockito.InOrder) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) ContactsModelWrapper(org.datatransferproject.types.common.models.contacts.ContactsModelWrapper) JCardReader(ezvcard.io.json.JCardReader) VCard(ezvcard.VCard) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) Test(org.junit.Test)

Aggregations

ContactsModelWrapper (org.datatransferproject.types.common.models.contacts.ContactsModelWrapper)11 VCard (ezvcard.VCard)6 IOException (java.io.IOException)4 List (java.util.List)4 ContinuationData (org.datatransferproject.spi.transfer.types.ContinuationData)4 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)3 Test (org.junit.Test)3 Person (com.google.api.services.people.v1.model.Person)2 JCardReader (ezvcard.io.json.JCardReader)2 JCardWriter (ezvcard.io.json.JCardWriter)2 StructuredName (ezvcard.property.StructuredName)2 StringWriter (java.io.StringWriter)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 UUID (java.util.UUID)2 AuthTestDriver (org.datatransferproject.auth.microsoft.harness.AuthTestDriver)2 Exporter (org.datatransferproject.spi.transfer.provider.Exporter)2 ImportResult (org.datatransferproject.spi.transfer.provider.ImportResult)2 Importer (org.datatransferproject.spi.transfer.provider.Importer)2