Search in sources :

Example 1 with Telephone

use of ezvcard.property.Telephone in project qksms by moezbhatti.

the class ContactOperations method convertPhones.

private void convertPhones(List<NonEmptyContentValues> contentValues, VCard vcard) {
    for (Telephone telephone : vcard.getTelephoneNumbers()) {
        String value = telephone.getText();
        TelUri uri = telephone.getUri();
        if (isEmpty(value)) {
            if (uri == null) {
                continue;
            }
            value = uri.toString();
        }
        int phoneKind = DataMappings.getPhoneType(telephone);
        NonEmptyContentValues cv = new NonEmptyContentValues(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
        cv.put(ContactsContract.CommonDataKinds.Phone.NUMBER, value);
        cv.put(ContactsContract.CommonDataKinds.Phone.TYPE, phoneKind);
        contentValues.add(cv);
    }
}
Also used : Telephone(ezvcard.property.Telephone) TelUri(ezvcard.util.TelUri)

Example 2 with Telephone

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

the class ToGraphContactTransformer method copyPersonData.

private void copyPersonData(VCard card, Map<String, Object> contact, TransformerContext context) {
    // Addresses are lossy: there is no distinction in VCard between business and home addresses
    if (!card.getAddresses().isEmpty()) {
        safeSet("homeAddress", context.transform(LinkedHashMap.class, card.getAddresses().get(0)), contact);
    }
    card.getEmails().stream().filter(v -> v.getValue() != null).forEach(v -> addEmail(v, contact));
    card.getTelephoneNumbers().stream().filter(t -> t.getText() != null).forEach(telephone -> {
        for (TelephoneType telephoneType : telephone.getTypes()) {
            if (TelephoneType.CELL.equals(telephoneType)) {
                // this could overwrite some numbers since MS contacts only have one mobile
                contact.put("mobilePhone", telephone.getText());
            } else if (TelephoneType.WORK.equals(telephoneType)) {
                addPhone("businessPhones", telephone, contact);
            } else {
                addPhone("homePhones", telephone, contact);
            }
        }
    });
    if (card.getBirthday() != null) {
        safeSet("birthday", card.getBirthday().getText(), contact);
    }
}
Also used : VCard(ezvcard.VCard) TelephoneType(ezvcard.parameter.TelephoneType) TransformerContext(org.dataportabilityproject.transfer.microsoft.transformer.TransformerContext) BiFunction(java.util.function.BiFunction) Telephone(ezvcard.property.Telephone) StructuredName(ezvcard.property.StructuredName) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) TransformerHelper.safeSet(org.dataportabilityproject.transfer.microsoft.transformer.common.TransformerHelper.safeSet) Title(ezvcard.property.Title) Map(java.util.Map) Organization(ezvcard.property.Organization) Email(ezvcard.property.Email) Expertise(ezvcard.property.Expertise) TelephoneType(ezvcard.parameter.TelephoneType) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with Telephone

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

the class GoogleContactToVCardConverter method convertToVCardTelephone.

private static Telephone convertToVCardTelephone(PhoneNumber personNumber) {
    Telephone telephone = new Telephone(personNumber.getValue());
    telephone.setPref(getPref(personNumber.getMetadata()));
    return telephone;
}
Also used : Telephone(ezvcard.property.Telephone)

Example 4 with Telephone

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

the class GoogleContactToVCardConverterTest method testConversionToVCardTelephone.

@Test
public void testConversionToVCardTelephone() {
    // Set up test: person with 2 primary phone numbers and 1 secondary phone number
    String primaryValue1 = "334-844-4244";
    String primaryValue2 = "411";
    String secondaryValue = "(555) 867-5309";
    PhoneNumber primaryPhone1 = new PhoneNumber().setValue(primaryValue1).setMetadata(PRIMARY_FIELD_METADATA);
    PhoneNumber primaryPhone2 = new PhoneNumber().setValue(primaryValue2).setMetadata(PRIMARY_FIELD_METADATA);
    PhoneNumber secondaryPhone = new PhoneNumber().setValue(secondaryValue).setMetadata(SECONDARY_FIELD_METADATA);
    Person person = DEFAULT_PERSON.setPhoneNumbers(Arrays.asList(secondaryPhone, primaryPhone1, primaryPhone2));
    // Run test
    VCard vCard = GoogleContactToVCardConverter.convert(person);
    // Check results for correct values and preferences
    List<Telephone> resultPrimaryPhoneList = getPropertiesWithPreference(vCard, Telephone.class, VCARD_PRIMARY_PREF);
    assertThat(getValuesFromProperties(resultPrimaryPhoneList, Telephone::getText)).containsExactly(primaryValue1, primaryValue2);
    List<Telephone> resultSecondaryPhoneList = getPropertiesWithPreference(vCard, Telephone.class, VCARD_PRIMARY_PREF + 1);
    assertThat(getValuesFromProperties(resultSecondaryPhoneList, Telephone::getText)).containsExactly(secondaryValue);
}
Also used : Telephone(ezvcard.property.Telephone) PhoneNumber(com.google.api.services.people.v1.model.PhoneNumber) Person(com.google.api.services.people.v1.model.Person) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 5 with Telephone

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

the class VCardToGoogleContactConverterTest method testConversionToGooglePhones.

@Test
public void testConversionToGooglePhones() {
    // Set up test: vCard with 2 primary phone numbers and 1 secondary phone number
    String primaryValue1 = "334-844-4244";
    String primaryValue2 = "411";
    String secondaryValue = "(555) 867-5309";
    Telephone primaryTelephone1 = new Telephone(primaryValue1);
    primaryTelephone1.setPref(VCARD_PRIMARY_PREF);
    Telephone primaryTelephone2 = new Telephone(primaryValue2);
    primaryTelephone2.setPref(VCARD_PRIMARY_PREF);
    Telephone secondaryTelephone = new Telephone(secondaryValue);
    secondaryTelephone.setPref(VCARD_PRIMARY_PREF + 1);
    // Add numbers to vCard.  Order shouldn't matter.
    VCard vCard = defaultVCard;
    vCard.addTelephoneNumber(secondaryTelephone);
    vCard.addTelephoneNumber(primaryTelephone1);
    vCard.addTelephoneNumber(primaryTelephone2);
    // Run test
    Person person = VCardToGoogleContactConverter.convert(vCard);
    // Check results
    // Correct number of phone numbers
    assertThat(person.getPhoneNumbers().size()).isEqualTo(3);
    // Check primary phone numbers
    List<PhoneNumber> actualPrimaryNumbers = person.getPhoneNumbers().stream().filter(a -> a.getMetadata().getPrimary()).collect(Collectors.toList());
    List<String> actualPrimaryNumberStrings = getValuesFromFields(actualPrimaryNumbers, PhoneNumber::getValue);
    assertThat(actualPrimaryNumberStrings).containsExactly(primaryValue1, primaryValue2);
    // Check secondary phone numbers
    List<PhoneNumber> actualSecondaryNumbers = person.getPhoneNumbers().stream().filter(a -> !a.getMetadata().getPrimary()).collect(Collectors.toList());
    List<String> actualSecondaryNumberStrings = getValuesFromFields(actualSecondaryNumbers, PhoneNumber::getValue);
    assertThat(actualSecondaryNumberStrings).containsExactly(secondaryValue);
}
Also used : VCard(ezvcard.VCard) VCARD_PRIMARY_PREF(org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.VCARD_PRIMARY_PREF) EmailAddress(com.google.api.services.people.v1.model.EmailAddress) 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) 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) CONTACT_SOURCE_TYPE(org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.CONTACT_SOURCE_TYPE) Nullable(com.google.gdata.util.common.base.Nullable) Address(com.google.api.services.people.v1.model.Address) Email(ezvcard.property.Email) Name(com.google.api.services.people.v1.model.Name) Collections(java.util.Collections) Before(org.junit.Before) Telephone(ezvcard.property.Telephone) PhoneNumber(com.google.api.services.people.v1.model.PhoneNumber) VCard(ezvcard.VCard) Person(com.google.api.services.people.v1.model.Person) Test(org.junit.Test)

Aggregations

Telephone (ezvcard.property.Telephone)22 VCard (ezvcard.VCard)12 StructuredName (ezvcard.property.StructuredName)11 Test (org.junit.Test)10 Address (ezvcard.property.Address)8 TelUri (ezvcard.util.TelUri)8 Email (ezvcard.property.Email)6 Birthday (ezvcard.property.Birthday)5 Timezone (ezvcard.property.Timezone)5 UtcOffset (ezvcard.util.UtcOffset)5 Person (com.google.api.services.people.v1.model.Person)4 PhoneNumber (com.google.api.services.people.v1.model.PhoneNumber)4 Anniversary (ezvcard.property.Anniversary)4 Geo (ezvcard.property.Geo)4 Key (ezvcard.property.Key)4 List (java.util.List)3 Address (com.google.api.services.people.v1.model.Address)2 EmailAddress (com.google.api.services.people.v1.model.EmailAddress)2 Name (com.google.api.services.people.v1.model.Name)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)2