Search in sources :

Example 21 with StructuredName

use of ezvcard.property.StructuredName in project ez-vcard by mangstadt.

the class VCardTest method validate_vcard.

@Test
public void validate_vcard() {
    VCard vcard = new VCard();
    assertValidate(vcard).versions(VCardVersion.V2_1).prop(null, 0).run();
    assertValidate(vcard).versions(VCardVersion.V3_0).prop(null, 0, 1).run();
    assertValidate(vcard).versions(VCardVersion.V4_0).prop(null, 1).run();
    vcard.setFormattedName("John Doe");
    assertValidate(vcard).versions(VCardVersion.V2_1, VCardVersion.V3_0).prop(null, 0).run();
    assertValidate(vcard).versions(VCardVersion.V4_0).run();
    vcard.setStructuredName(new StructuredName());
    assertValidate(vcard).run();
}
Also used : StructuredName(ezvcard.property.StructuredName) Test(org.junit.Test)

Example 22 with StructuredName

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

the class GoogleContactsExporter 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 23 with StructuredName

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

the class GoogleContactsExporter method convertToVCardNamesAndPopulate.

private static void convertToVCardNamesAndPopulate(VCard vCard, List<Name> personNames) {
    // TODO(olsona): what if there's more than one primary name in a Google Contact?
    StructuredName primaryStructuredName = null;
    LinkedList<StructuredName> alternateStructuredNames = new LinkedList<>();
    for (Name personName : personNames) {
        StructuredName structuredName = convertToVCardNameSingle(personName);
        Boolean isNamePrimary = personName.getMetadata().getPrimary();
        if (isNamePrimary != null && isNamePrimary) {
            // This is the (a?) primary name for the Person, so it should be the primary name in the
            // VCard.
            primaryStructuredName = structuredName;
        } else {
            alternateStructuredNames.add(structuredName);
        }
    }
    if (primaryStructuredName == null) {
        primaryStructuredName = alternateStructuredNames.pop();
    }
    vCard.addProperty(primaryStructuredName);
    vCard.addPropertyAlt(StructuredName.class, alternateStructuredNames);
}
Also used : StructuredName(ezvcard.property.StructuredName) LinkedList(java.util.LinkedList) StructuredName(ezvcard.property.StructuredName) Name(com.google.api.services.people.v1.model.Name)

Example 24 with StructuredName

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

the class GoogleContactsImporter method convertToGoogleName.

private static Name convertToGoogleName(StructuredName vCardName) {
    Name name = new Name();
    name.setFamilyName(vCardName.getFamily());
    name.setGivenName(vCardName.getGiven());
    FieldMetadata fieldMetadata = new FieldMetadata();
    boolean isPrimary = (vCardName.getAltId() == null);
    fieldMetadata.setPrimary(isPrimary);
    String vCardNameSource = vCardName.getParameter(SOURCE_PARAM_NAME_TYPE);
    if (CONTACT_SOURCE_TYPE.equals(vCardNameSource)) {
        Source source = new Source().setType(vCardNameSource);
        fieldMetadata.setSource(source);
    }
    name.setMetadata(fieldMetadata);
    return name;
}
Also used : FieldMetadata(com.google.api.services.people.v1.model.FieldMetadata) Source(com.google.api.services.people.v1.model.Source) StructuredName(ezvcard.property.StructuredName) Name(com.google.api.services.people.v1.model.Name)

Example 25 with StructuredName

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

the class GoogleContactsImporter method getPrimaryGoogleName.

private static Name getPrimaryGoogleName(List<StructuredName> vCardNameList) {
    StructuredName primaryVCardName;
    // first look if there's a primary name (or names)
    // if no primary name exists, simply pick the first "alt" name
    List<StructuredName> primaryNames = vCardNameList.stream().filter(a -> a.getAltId() == null).collect(Collectors.toList());
    if (primaryNames.size() > 0) {
        primaryVCardName = primaryNames.get(0);
    } else {
        primaryVCardName = vCardNameList.get(0);
    }
    return convertToGoogleName(primaryVCardName);
}
Also used : EmailAddress(com.google.api.services.people.v1.model.EmailAddress) LoggerFactory(org.slf4j.LoggerFactory) PhoneNumber(com.google.api.services.people.v1.model.PhoneNumber) StructuredName(ezvcard.property.StructuredName) TokensAndUrlAuthData(org.dataportabilityproject.types.transfer.auth.TokensAndUrlAuthData) Person(com.google.api.services.people.v1.model.Person) CONTACT_SOURCE_TYPE(org.dataportabilityproject.datatransfer.google.common.GoogleStaticObjects.CONTACT_SOURCE_TYPE) JCardReader(ezvcard.io.json.JCardReader) Credential(com.google.api.client.auth.oauth2.Credential) ImportResult(org.dataportabilityproject.spi.transfer.provider.ImportResult) VCARD_PRIMARY_PREF(org.dataportabilityproject.datatransfer.google.common.GoogleStaticObjects.VCARD_PRIMARY_PREF) VCard(ezvcard.VCard) PeopleService(com.google.api.services.people.v1.PeopleService) Logger(org.slf4j.Logger) BearerToken(com.google.api.client.auth.oauth2.BearerToken) Telephone(ezvcard.property.Telephone) IOException(java.io.IOException) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) SOURCE_PARAM_NAME_TYPE(org.dataportabilityproject.datatransfer.google.common.GoogleStaticObjects.SOURCE_PARAM_NAME_TYPE) 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) ContactsModelWrapper(org.dataportabilityproject.types.transfer.models.contacts.ContactsModelWrapper) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Importer(org.dataportabilityproject.spi.transfer.provider.Importer) Name(com.google.api.services.people.v1.model.Name) GoogleStaticObjects(org.dataportabilityproject.datatransfer.google.common.GoogleStaticObjects) Collections(java.util.Collections) 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