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