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);
}
}
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);
}
}
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;
}
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);
}
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);
}
Aggregations