Search in sources :

Example 1 with SolidUtilities

use of org.datatransferproject.transfer.solid.SolidUtilities in project data-transfer-project by google.

the class SolidContactsImport method importItem.

@Override
public ImportResult importItem(UUID jobId, IdempotentImportExecutor idempotentExecutor, CookiesAndUrlAuthData authData, ContactsModelWrapper data) throws Exception {
    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<VCard> vcards = Ezvcard.parse(data.getVCards()).all();
    createContent(idempotentExecutor, url, vcards, solidUtilities);
    return ImportResult.OK;
}
Also used : VCard(ezvcard.VCard) SolidUtilities(org.datatransferproject.transfer.solid.SolidUtilities)

Example 2 with SolidUtilities

use of org.datatransferproject.transfer.solid.SolidUtilities 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)

Aggregations

VCard (ezvcard.VCard)2 SolidUtilities (org.datatransferproject.transfer.solid.SolidUtilities)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)1 ContactsModelWrapper (org.datatransferproject.types.common.models.contacts.ContactsModelWrapper)1