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