Search in sources :

Example 26 with StructuredName

use of ezvcard.property.StructuredName in project data-transfer-project by google.

the class GoogleContactToVCardConverter method convertToVCardNameSingle.

private static StructuredName convertToVCardNameSingle(Name personName) {
    StructuredName structuredName = new StructuredName();
    structuredName.setFamily(personName.getFamilyName());
    structuredName.setGiven(personName.getGivenName());
    structuredName.setParameter(SOURCE_PARAM_NAME_TYPE, personName.getMetadata().getSource().getType());
    // TODO(olsona): address formatting, structure, phonetics, suffixes, prefixes
    return structuredName;
}
Also used : StructuredName(ezvcard.property.StructuredName)

Example 27 with StructuredName

use of ezvcard.property.StructuredName in project data-transfer-project by google.

the class GoogleContactsExportConversionTest method testConversionToVCardNames.

@Test
public void testConversionToVCardNames() {
    // Set up Person with a primary name and two secondary names
    String primaryGivenName = "Mark";
    String primaryFamilyName = "Twain";
    Name primaryName = new Name().setGivenName(primaryGivenName).setFamilyName(primaryFamilyName).setMetadata(PRIMARY_FIELD_METADATA);
    String alternateGivenName1 = "Samuel";
    String alternateFamilyName1 = "Clemens";
    String alternateSourceType1 = "PROFILE";
    Name alternateName1 = new Name().setGivenName(alternateGivenName1).setFamilyName(alternateFamilyName1).setMetadata(new FieldMetadata().setPrimary(false).setSource(new Source().setType(alternateSourceType1)));
    String alternateGivenName2 = "Louis";
    String alternateFamilyName2 = "de Conte";
    String alternateSourceType2 = "PEN_NAME";
    Name alternateName2 = new Name().setGivenName(alternateGivenName2).setFamilyName(alternateFamilyName2).setMetadata(new FieldMetadata().setPrimary(false).setSource(new Source().setType(alternateSourceType2)));
    // Order shouldn't matter
    Person person = new Person().setNames(Arrays.asList(alternateName2, alternateName1, primaryName));
    // Run test
    VCard vCard = GoogleContactsExporter.convert(person);
    // Check name conversion correctness
    List<StructuredName> structuredNames = vCard.getStructuredNames();
    assertThat(structuredNames.size()).isEqualTo(3);
    // Check primary (non-alternate) names
    List<StructuredName> actualPrimaryNames = structuredNames.stream().filter(n -> n.getAltId() == null).collect(Collectors.toList());
    List<Pair<String, String>> actualPrimaryNamesValues = actualPrimaryNames.stream().map(GoogleContactsExportConversionTest::getGivenAndFamilyNames).collect(Collectors.toList());
    assertThat(actualPrimaryNamesValues).containsExactly(Pair.of(primaryGivenName, primaryFamilyName));
    List<String> actualPrimarySourceValues = actualPrimaryNames.stream().map(a -> a.getParameter(SOURCE_PARAM_NAME_TYPE)).collect(Collectors.toList());
    assertThat(actualPrimarySourceValues).containsExactly(DEFAULT_SOURCE_TYPE);
    // Check alternate names
    List<StructuredName> actualAlternateNames = structuredNames.stream().filter(n -> n.getAltId() != null).collect(Collectors.toList());
    List<Pair<String, String>> actualAlternateNamesValues = actualAlternateNames.stream().map(GoogleContactsExportConversionTest::getGivenAndFamilyNames).collect(Collectors.toList());
    assertThat(actualAlternateNamesValues).containsExactly(Pair.of(alternateGivenName1, alternateFamilyName1), Pair.of(alternateGivenName2, alternateFamilyName2));
    List<String> actualAlternateSourceValues = actualAlternateNames.stream().map(a -> a.getParameter(SOURCE_PARAM_NAME_TYPE)).collect(Collectors.toList());
    assertThat(actualAlternateSourceValues).containsExactly(alternateSourceType1, alternateSourceType2);
}
Also used : VCard(ezvcard.VCard) Arrays(java.util.Arrays) EmailAddress(com.google.api.services.people.v1.model.EmailAddress) VCardProperty(ezvcard.property.VCardProperty) Telephone(ezvcard.property.Telephone) Test(org.junit.Test) PhoneNumber(com.google.api.services.people.v1.model.PhoneNumber) Truth.assertThat(com.google.common.truth.Truth.assertThat) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Address(ezvcard.property.Address) StructuredName(ezvcard.property.StructuredName) SOURCE_PARAM_NAME_TYPE(org.dataportabilityproject.datatransfer.google.common.GoogleStaticObjects.SOURCE_PARAM_NAME_TYPE) Pair(com.google.gdata.util.common.base.Pair) Person(com.google.api.services.people.v1.model.Person) List(java.util.List) FieldMetadata(com.google.api.services.people.v1.model.FieldMetadata) Source(com.google.api.services.people.v1.model.Source) Email(ezvcard.property.Email) VCardParameters(ezvcard.parameter.VCardParameters) VCARD_PRIMARY_PREF(org.dataportabilityproject.datatransfer.google.common.GoogleStaticObjects.VCARD_PRIMARY_PREF) Name(com.google.api.services.people.v1.model.Name) TextProperty(ezvcard.property.TextProperty) Collections(java.util.Collections) FieldMetadata(com.google.api.services.people.v1.model.FieldMetadata) Person(com.google.api.services.people.v1.model.Person) VCard(ezvcard.VCard) StructuredName(ezvcard.property.StructuredName) Source(com.google.api.services.people.v1.model.Source) StructuredName(ezvcard.property.StructuredName) Name(com.google.api.services.people.v1.model.Name) Pair(com.google.gdata.util.common.base.Pair) Test(org.junit.Test)

Example 28 with StructuredName

use of ezvcard.property.StructuredName 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 29 with StructuredName

use of ezvcard.property.StructuredName in project data-transfer-project by google.

the class ToGraphContactTransformer method copyNames.

private void copyNames(VCard card, Map<String, Object> contact) {
    StructuredName structuredName = card.getStructuredName();
    if (structuredName != null) {
        safeSet("givenName", structuredName.getGiven(), contact);
        safeSet("surname", structuredName.getFamily(), contact);
        // MS contacts only allows one middle name - take the first one
        if (!structuredName.getAdditionalNames().isEmpty()) {
            safeSet("middleName", structuredName.getAdditionalNames().get(0), contact);
        }
        // MS contacts only allows one prefix - take the first one
        if (!structuredName.getPrefixes().isEmpty()) {
            safeSet("title", structuredName.getPrefixes().get(0), contact);
        }
    }
    safeSet("displayName", card.getFormattedName(), contact);
    safeSet("nickName", card.getNickname(), contact);
}
Also used : StructuredName(ezvcard.property.StructuredName)

Example 30 with StructuredName

use of ezvcard.property.StructuredName in project data-transfer-project by google.

the class ToVCardTransformer method copyNames.

private void copyNames(Map<String, Object> map, VCard card) {
    String givenName = (String) map.get("givenName");
    String surname = (String) map.get("surname");
    StructuredName structuredName = new StructuredName();
    structuredName.setFamily(surname);
    structuredName.setGiven(givenName);
    getString("middleName", map).ifPresent(v -> structuredName.getAdditionalNames().add(v));
    getString("title", map).ifPresent(v -> structuredName.getPrefixes().add(v));
    card.setStructuredName(structuredName);
    getString("displayName", map).ifPresent(card::setFormattedName);
    getString("nickName", map).ifPresent(card::setNickname);
}
Also used : TransformerHelper.getString(org.dataportabilityproject.transfer.microsoft.transformer.common.TransformerHelper.getString) StructuredName(ezvcard.property.StructuredName)

Aggregations

StructuredName (ezvcard.property.StructuredName)37 VCard (ezvcard.VCard)17 Telephone (ezvcard.property.Telephone)14 Test (org.junit.Test)13 Address (ezvcard.property.Address)11 Name (com.google.api.services.people.v1.model.Name)10 Email (ezvcard.property.Email)9 Person (com.google.api.services.people.v1.model.Person)8 EmailAddress (com.google.api.services.people.v1.model.EmailAddress)6 FieldMetadata (com.google.api.services.people.v1.model.FieldMetadata)6 PhoneNumber (com.google.api.services.people.v1.model.PhoneNumber)6 Source (com.google.api.services.people.v1.model.Source)6 Timezone (ezvcard.property.Timezone)6 TelUri (ezvcard.util.TelUri)6 UtcOffset (ezvcard.util.UtcOffset)6 Collections (java.util.Collections)6 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 Birthday (ezvcard.property.Birthday)5 Truth.assertThat (com.google.common.truth.Truth.assertThat)4