Search in sources :

Example 1 with JCardWriter

use of ezvcard.io.json.JCardWriter in project data-transfer-project by google.

the class GoogleContactsExporter method makeVCardString.

@VisibleForTesting
static String makeVCardString(List<VCard> vCardList) throws IOException {
    StringWriter stringWriter = new StringWriter();
    JCardWriter jCardWriter = new JCardWriter(stringWriter);
    for (VCard vCardProperties : vCardList) {
        // needs to be loop so error can be thrown
        jCardWriter.write(vCardProperties);
    }
    jCardWriter.flush();
    return stringWriter.toString();
}
Also used : StringWriter(java.io.StringWriter) JCardWriter(ezvcard.io.json.JCardWriter) VCard(ezvcard.VCard) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with JCardWriter

use of ezvcard.io.json.JCardWriter in project data-transfer-project by google.

the class LocalImportTestRunner method createCards.

private static String createCards() throws IOException {
    StringWriter stringWriter = new StringWriter();
    JCardWriter writer = new JCardWriter(stringWriter);
    VCard card1 = new VCard();
    StructuredName structuredName1 = new StructuredName();
    structuredName1.setGiven("Test Given Data1");
    structuredName1.setFamily("Test Surname Data1");
    card1.setStructuredName(structuredName1);
    VCard card2 = new VCard();
    StructuredName structuredName2 = new StructuredName();
    structuredName2.setGiven("Test Given Data2");
    structuredName2.setFamily("Test Surname Data2");
    card2.setStructuredName(structuredName2);
    writer.write(card1);
    writer.write(card2);
    writer.close();
    return stringWriter.toString();
}
Also used : StringWriter(java.io.StringWriter) JCardWriter(ezvcard.io.json.JCardWriter) VCard(ezvcard.VCard) StructuredName(ezvcard.property.StructuredName)

Example 3 with JCardWriter

use of ezvcard.io.json.JCardWriter 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());
}
Also used : StringWriter(java.io.StringWriter) JCardWriter(ezvcard.io.json.JCardWriter) IOException(java.io.IOException) ContactsModelWrapper(org.dataportabilityproject.types.transfer.models.contacts.ContactsModelWrapper) VCard(ezvcard.VCard)

Aggregations

VCard (ezvcard.VCard)3 JCardWriter (ezvcard.io.json.JCardWriter)3 StringWriter (java.io.StringWriter)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 StructuredName (ezvcard.property.StructuredName)1 IOException (java.io.IOException)1 ContactsModelWrapper (org.dataportabilityproject.types.transfer.models.contacts.ContactsModelWrapper)1