Search in sources :

Example 1 with Source

use of com.google.api.services.people.v1.model.Source in project data-transfer-project by google.

the class VCardToGoogleContactConverter 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 2 with Source

use of com.google.api.services.people.v1.model.Source in project data-transfer-project by google.

the class GoogleContactToVCardConverterTest 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 = GoogleContactToVCardConverter.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(GoogleContactToVCardConverterTest::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(GoogleContactToVCardConverterTest::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) VCARD_PRIMARY_PREF(org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.VCARD_PRIMARY_PREF) EmailAddress(com.google.api.services.people.v1.model.EmailAddress) VCardProperty(ezvcard.property.VCardProperty) Telephone(ezvcard.property.Telephone) SOURCE_PARAM_NAME_TYPE(org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.SOURCE_PARAM_NAME_TYPE) 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) 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) 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 3 with Source

use of com.google.api.services.people.v1.model.Source in project metacat by Netflix.

the class S3ConnectorInfoConverter method fromDatabaseInfo.

@Override
public Database fromDatabaseInfo(final DatabaseInfo databaseInfo) {
    final Database result = new Database();
    final QualifiedName databaseName = databaseInfo.getName();
    result.setName(databaseName.getDatabaseName());
    final Source source = new Source();
    source.setName(databaseName.getCatalogName());
    result.setSource(source);
    return result;
}
Also used : QualifiedName(com.netflix.metacat.common.QualifiedName) Database(com.netflix.metacat.connector.s3.model.Database) Source(com.netflix.metacat.connector.s3.model.Source)

Example 4 with Source

use of com.google.api.services.people.v1.model.Source 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 5 with Source

use of com.google.api.services.people.v1.model.Source 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)

Aggregations

FieldMetadata (com.google.api.services.people.v1.model.FieldMetadata)4 Name (com.google.api.services.people.v1.model.Name)4 Source (com.google.api.services.people.v1.model.Source)4 StructuredName (ezvcard.property.StructuredName)4 EmailAddress (com.google.api.services.people.v1.model.EmailAddress)2 Person (com.google.api.services.people.v1.model.Person)2 PhoneNumber (com.google.api.services.people.v1.model.PhoneNumber)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 Pair (com.google.gdata.util.common.base.Pair)2 VCard (ezvcard.VCard)2 VCardParameters (ezvcard.parameter.VCardParameters)2 Address (ezvcard.property.Address)2 Email (ezvcard.property.Email)2 Telephone (ezvcard.property.Telephone)2 TextProperty (ezvcard.property.TextProperty)2 VCardProperty (ezvcard.property.VCardProperty)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 List (java.util.List)2 Function (java.util.function.Function)2