@Override public Address apply(Map<String, String> addressMap, TransformerContext context) { Address address = new Address(); address.setStreetAddress(addressMap.get("street")); address.setLocality(addressMap.get("city")); address.setCountry(addressMap.get("countryOrRegion")); address.setPostalCode(addressMap.get("postalCode")); address.setRegion(addressMap.get("state")); return address; } }
@SuppressWarnings("unchecked") private void addPhone(String key, Telephone telephone, Map<String, Object> map) { List<String> collection = (List<String>) map.computeIfAbsent(key, k -> new ArrayList<>()); collection.add(telephone.getText()); }
private static PhoneNumber convertToGooglePhoneNumber(Telephone vCardTelephone) { PhoneNumber phoneNumber = new PhoneNumber(); phoneNumber.setValue(vCardTelephone.getText()); if (vCardTelephone.getPref() != null && vCardTelephone.getPref() == VCARD_PRIMARY_PREF) { phoneNumber.setMetadata(PRIMARY_FIELD_METADATA); } else { phoneNumber.setMetadata(SECONDARY_FIELD_METADATA); } return phoneNumber; }
private static StructuredName makeStructuredName( String givenName, String familyName, @Nullable String sourceType) { StructuredName structuredName = new StructuredName(); structuredName.setGiven(givenName); structuredName.setFamily(familyName); if (sourceType != null) { structuredName.setParameter(SOURCE_PARAM_NAME_TYPE, sourceType); } return structuredName; }
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); }
private static ezvcard.property.Address convertToVCardAddress( com.google.api.services.people.v1.model.Address personAddress) { ezvcard.property.Address vCardAddress = new ezvcard.property.Address(); vCardAddress.setCountry(personAddress.getCountry()); vCardAddress.setRegion(personAddress.getRegion()); vCardAddress.setLocality(personAddress.getCity()); vCardAddress.setPostalCode(personAddress.getPostalCode()); vCardAddress.setStreetAddress(personAddress.getStreetAddress()); vCardAddress.setPoBox(personAddress.getPoBox()); vCardAddress.setExtendedAddress(personAddress.getExtendedAddress()); vCardAddress.setPref(getPref(personAddress.getMetadata())); return vCardAddress; }
private static com.google.api.services.people.v1.model.Address convertToGoogleAddress( ezvcard.property.Address vCardAddress) { com.google.api.services.people.v1.model.Address personAddress = new com.google.api.services.people.v1.model.Address(); personAddress.setCountry(vCardAddress.getCountry()); personAddress.setRegion(vCardAddress.getRegion()); personAddress.setCity(vCardAddress.getLocality()); personAddress.setPostalCode(vCardAddress.getPostalCode()); personAddress.setStreetAddress(vCardAddress.getStreetAddress()); personAddress.setPoBox(vCardAddress.getPoBox()); personAddress.setExtendedAddress(vCardAddress.getExtendedAddress()); // check to guard against unboxing of a null value personAddress.setMetadata( vCardAddress.getPref() != null && vCardAddress.getPref() == VCARD_PRIMARY_PREF ? PRIMARY_FIELD_METADATA : SECONDARY_FIELD_METADATA); return personAddress; }
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); }
@Override public Map<String, String> apply(Address address, TransformerContext context) { Map<String, String> physicalAddress = new LinkedHashMap<>(); safeSet("street", address.getStreetAddress(), physicalAddress); safeSet("street", address.getStreetAddress(), physicalAddress); safeSet("city", address.getLocality(), physicalAddress); safeSet("countryOrRegion", address.getCountry(), physicalAddress); safeSet("postalCode", address.getPostalCode(), physicalAddress); safeSet("state", address.getRegion(), physicalAddress); return physicalAddress; } }
@Test public void testFromRDF() { VCard vcard = SolidContactsExport.parsePerson(getPersonResource(TestData.RDF_TEST_DATA1)); assertWithMessage("Formatted Name is correct") .that(vcard.getFormattedName().getValue()) .isEqualTo("Cool Kid 1"); assertWithMessage("Note is correct") .that(vcard.getNotes().get(0).getValue()) .isEqualTo("This is a note for Cool Kid 1"); assertWithMessage("One email found") .that(vcard.getEmails()) .hasSize(1); assertWithMessage("email is correct") .that(vcard.getEmails().get(0).getValue()) .isEqualTo("a@b.com"); }
private static EmailAddress convertToGoogleEmail(Email vCardEmail) { EmailAddress emailAddress = new EmailAddress(); emailAddress.setValue(vCardEmail.getValue()); if (vCardEmail.getPref() != null && vCardEmail.getPref() == VCARD_PRIMARY_PREF) { emailAddress.setMetadata(PRIMARY_FIELD_METADATA); } else { emailAddress.setMetadata(SECONDARY_FIELD_METADATA); } // TODO(olsona): address display name, formatted type, etc return emailAddress; }
private void copyBusinessData(VCard card, Map<String, Object> contact) { for (Title title : card.getTitles()) { if (title.getValue() == null) { continue; } // This can loose data but there are only two title types in MS contacts if (title.getType() != null && title.getType().equalsIgnoreCase("home")) { safeSet("title", card.getTitles(), contact); } else { safeSet("jobTitle", card.getTitles(), contact); } } // This can loose data but there is only one company name in MS contacts for (Organization organization : card.getOrganizations()) { for (String orgName : organization.getValues()) { contact.put("companyName", orgName); } } for (Expertise expertise : card.getExpertise()) { if (expertise.getValue() == null) { continue; } contact.put("profession", expertise.getValue()); // only set first one break; } }
@SuppressWarnings("unchecked") private void addEmail(Email email, Map<String, Object> map) { List<Map<String, String>> collection = (List<Map<String, String>>) map.computeIfAbsent("emailAddresses", k -> new ArrayList<>()); Map<String, String> emailMap = new LinkedHashMap<>(); emailMap.put("address", email.getValue()); collection.add(emailMap); } }
@SuppressWarnings("unchecked") private void copyEmail(Map<String, Object> map, VCard card) { getListMap("emailAddresses", map) .ifPresent( v -> v.forEach( email -> getString("address", email) .ifPresent(addr -> card.addEmail(new Email(addr))))); }
private void copyPersonData(Map<String, Object> map, VCard card, TransformerContext context) { getMap("homeAddress", map).ifPresent(v -> card.addAddress(context.transform(Address.class, v))); copyEmail(map, card); copyPhones("homePhones", TelephoneType.HOME, map, card); getString("mobilePhone", map).ifPresent(v -> card.addTelephoneNumber(v, TelephoneType.CELL)); getString("birthday", map).ifPresent(v -> card.setBirthday(new Birthday(v))); }
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); }
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; }