Search in sources :

Example 11 with Address

use of ezvcard.property.Address in project ez-vcard by mangstadt.

the class XCardDocumentTest method write_rfc6351_example.

@Test
public void write_rfc6351_example() throws Throwable {
    VCard vcard = new VCard();
    vcard.setFormattedName("Simon Perreault");
    StructuredName n = new StructuredName();
    n.setFamily("Perreault");
    n.setGiven("Simon");
    n.getSuffixes().add("ing. jr");
    n.getSuffixes().add("M.Sc.");
    vcard.setStructuredName(n);
    Birthday bday = new Birthday(PartialDate.builder().month(2).date(3).build());
    vcard.setBirthday(bday);
    Anniversary anniversary = new Anniversary(PartialDate.builder().year(2009).month(8).date(8).hour(14).minute(30).offset(new UtcOffset(false, -5, 0)).build());
    vcard.setAnniversary(anniversary);
    vcard.setGender(Gender.male());
    vcard.addLanguage("fr").setPref(1);
    vcard.addLanguage("en").setPref(2);
    vcard.setOrganization("Viagenie").setType("work");
    Address adr = new Address();
    adr.setStreetAddress("2875 boul. Laurier, suite D2-630");
    adr.setLocality("Quebec");
    adr.setRegion("QC");
    adr.setPostalCode("G1V 2M2");
    adr.setCountry("Canada");
    adr.getTypes().add(AddressType.WORK);
    adr.setLabel("Simon Perreault\n2875 boul. Laurier, suite D2-630\nQuebec, QC, Canada\nG1V 2M2");
    vcard.addAddress(adr);
    TelUri telUri = new TelUri.Builder("+1-418-656-9254").extension("102").build();
    Telephone tel = new Telephone(telUri);
    tel.getTypes().add(TelephoneType.WORK);
    tel.getTypes().add(TelephoneType.VOICE);
    vcard.addTelephoneNumber(tel);
    tel = new Telephone(new TelUri.Builder("+1-418-262-6501").build());
    tel.getTypes().add(TelephoneType.WORK);
    tel.getTypes().add(TelephoneType.TEXT);
    tel.getTypes().add(TelephoneType.VOICE);
    tel.getTypes().add(TelephoneType.CELL);
    tel.getTypes().add(TelephoneType.VIDEO);
    vcard.addTelephoneNumber(tel);
    vcard.addEmail("simon.perreault@viagenie.ca", EmailType.WORK);
    Geo geo = new Geo(46.766336, -71.28955);
    geo.setType("work");
    vcard.setGeo(geo);
    Key key = new Key("http://www.viagenie.ca/simon.perreault/simon.asc", null);
    key.setType("work");
    vcard.addKey(key);
    vcard.setTimezone(new Timezone("America/Montreal"));
    vcard.addUrl("http://nomis80.org").setType("home");
    assertValidate(vcard).versions(V4_0).run();
    assertExample(vcard, "rfc6351-example.xml");
}
Also used : Timezone(ezvcard.property.Timezone) Address(ezvcard.property.Address) Telephone(ezvcard.property.Telephone) Anniversary(ezvcard.property.Anniversary) TelUri(ezvcard.util.TelUri) Birthday(ezvcard.property.Birthday) Geo(ezvcard.property.Geo) UtcOffset(ezvcard.util.UtcOffset) VCard(ezvcard.VCard) StructuredName(ezvcard.property.StructuredName) Key(ezvcard.property.Key) Test(org.junit.Test)

Example 12 with Address

use of ezvcard.property.Address in project ez-vcard by mangstadt.

the class XCardWriterTest method write_rfc6351_example.

@Test
public void write_rfc6351_example() throws Exception {
    VCard vcard = new VCard();
    vcard.setFormattedName("Simon Perreault");
    StructuredName n = new StructuredName();
    n.setFamily("Perreault");
    n.setGiven("Simon");
    n.getSuffixes().add("ing. jr");
    n.getSuffixes().add("M.Sc.");
    vcard.setStructuredName(n);
    Birthday bday = new Birthday(PartialDate.builder().month(2).date(3).build());
    vcard.setBirthday(bday);
    Anniversary anniversary = new Anniversary(PartialDate.builder().year(2009).month(8).date(8).hour(14).minute(30).offset(new UtcOffset(false, -5, 0)).build());
    vcard.setAnniversary(anniversary);
    vcard.setGender(Gender.male());
    vcard.addLanguage("fr").setPref(1);
    vcard.addLanguage("en").setPref(2);
    vcard.setOrganization("Viagenie").setType("work");
    Address adr = new Address();
    adr.setStreetAddress("2875 boul. Laurier, suite D2-630");
    adr.setLocality("Quebec");
    adr.setRegion("QC");
    adr.setPostalCode("G1V 2M2");
    adr.setCountry("Canada");
    adr.getTypes().add(AddressType.WORK);
    adr.setLabel("Simon Perreault\n2875 boul. Laurier, suite D2-630\nQuebec, QC, Canada\nG1V 2M2");
    vcard.addAddress(adr);
    TelUri telUri = new TelUri.Builder("+1-418-656-9254").extension("102").build();
    Telephone tel = new Telephone(telUri);
    tel.getTypes().add(TelephoneType.WORK);
    tel.getTypes().add(TelephoneType.VOICE);
    vcard.addTelephoneNumber(tel);
    tel = new Telephone(new TelUri.Builder("+1-418-262-6501").build());
    tel.getTypes().add(TelephoneType.WORK);
    tel.getTypes().add(TelephoneType.TEXT);
    tel.getTypes().add(TelephoneType.VOICE);
    tel.getTypes().add(TelephoneType.CELL);
    tel.getTypes().add(TelephoneType.VIDEO);
    vcard.addTelephoneNumber(tel);
    vcard.addEmail("simon.perreault@viagenie.ca", EmailType.WORK);
    Geo geo = new Geo(46.766336, -71.28955);
    geo.setType("work");
    vcard.setGeo(geo);
    Key key = new Key("http://www.viagenie.ca/simon.perreault/simon.asc", null);
    key.setType("work");
    vcard.addKey(key);
    vcard.setTimezone(new Timezone("America/Montreal"));
    vcard.addUrl("http://nomis80.org").setType("home");
    assertValidate(vcard).versions(V4_0).run();
    assertExample(vcard, "rfc6351-example.xml");
}
Also used : Timezone(ezvcard.property.Timezone) Address(ezvcard.property.Address) Telephone(ezvcard.property.Telephone) Anniversary(ezvcard.property.Anniversary) TelUri(ezvcard.util.TelUri) Birthday(ezvcard.property.Birthday) Geo(ezvcard.property.Geo) UtcOffset(ezvcard.util.UtcOffset) VCard(ezvcard.VCard) StructuredName(ezvcard.property.StructuredName) Key(ezvcard.property.Key) Test(org.junit.Test)

Example 13 with Address

use of ezvcard.property.Address in project android by nextcloud.

the class ContactOperations method convertAddresses.

private void convertAddresses(List<NonEmptyContentValues> contentValues, VCard vcard) {
    for (Address address : vcard.getAddresses()) {
        NonEmptyContentValues cv = new NonEmptyContentValues(ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE);
        String street = address.getStreetAddress();
        cv.put(ContactsContract.CommonDataKinds.StructuredPostal.STREET, street);
        String poBox = address.getPoBox();
        cv.put(ContactsContract.CommonDataKinds.StructuredPostal.POBOX, poBox);
        String city = address.getLocality();
        cv.put(ContactsContract.CommonDataKinds.StructuredPostal.CITY, city);
        String state = address.getRegion();
        cv.put(ContactsContract.CommonDataKinds.StructuredPostal.REGION, state);
        String zipCode = address.getPostalCode();
        cv.put(ContactsContract.CommonDataKinds.StructuredPostal.POSTCODE, zipCode);
        String country = address.getCountry();
        cv.put(ContactsContract.CommonDataKinds.StructuredPostal.COUNTRY, country);
        String label = address.getLabel();
        cv.put(ContactsContract.CommonDataKinds.StructuredPostal.LABEL, label);
        int addressKind = DataMappings.getAddressType(address);
        cv.put(ContactsContract.CommonDataKinds.StructuredPostal.TYPE, addressKind);
        contentValues.add(cv);
    }
}
Also used : Address(ezvcard.property.Address)

Example 14 with Address

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

the class GoogleContactsExportConversionTest method testConversionToVCardAddress.

@Test
public void testConversionToVCardAddress() {
    // Set up test: person with a primary address and a secondary address
    String primaryStreet = "221B Baker St";
    String primaryCity = "London";
    String primaryPostcode = "NW1";
    String primaryCountry = "United Kingdom";
    com.google.api.services.people.v1.model.Address primaryAddress = new com.google.api.services.people.v1.model.Address().setStreetAddress(primaryStreet).setCity(primaryCity).setPostalCode(primaryPostcode).setCountry(primaryCountry).setMetadata(PRIMARY_FIELD_METADATA);
    String altStreet = "42 Wallaby Way";
    String altCity = "Sydney";
    String altRegion = "New South Wales";
    String altCountry = "Australia";
    com.google.api.services.people.v1.model.Address altAddress = new com.google.api.services.people.v1.model.Address().setStreetAddress(altStreet).setCity(altCity).setRegion(altRegion).setCountry(altCountry).setMetadata(SECONDARY_FIELD_METADATA);
    Person person = DEFAULT_PERSON.setAddresses(Arrays.asList(altAddress, primaryAddress));
    // Run test
    VCard vCard = GoogleContactsExporter.convert(person);
    // Check results for correct values and preferences
    List<Address> actualPrimaryAddressList = getPropertiesWithPreference(vCard, Address.class, VCARD_PRIMARY_PREF);
    assertThat(actualPrimaryAddressList.stream().map(Address::getStreetAddress).collect(Collectors.toList())).containsExactly(primaryStreet);
    List<Address> actualAltAddressList = getPropertiesWithPreference(vCard, Address.class, VCARD_PRIMARY_PREF + 1);
    assertThat(actualAltAddressList.stream().map(Address::getRegion).collect(Collectors.toList())).containsExactly(altRegion);
}
Also used : EmailAddress(com.google.api.services.people.v1.model.EmailAddress) Address(ezvcard.property.Address) Person(com.google.api.services.people.v1.model.Person) VCard(ezvcard.VCard) Test(org.junit.Test)

Example 15 with Address

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

the class GoogleContactToVCardConverterTest method testConversionToVCardAddress.

@Test
public void testConversionToVCardAddress() {
    // Set up test: person with a primary address and a secondary address
    String primaryStreet = "221B Baker St";
    String primaryCity = "London";
    String primaryPostcode = "NW1";
    String primaryCountry = "United Kingdom";
    com.google.api.services.people.v1.model.Address primaryAddress = new com.google.api.services.people.v1.model.Address().setStreetAddress(primaryStreet).setCity(primaryCity).setPostalCode(primaryPostcode).setCountry(primaryCountry).setMetadata(PRIMARY_FIELD_METADATA);
    String altStreet = "42 Wallaby Way";
    String altCity = "Sydney";
    String altRegion = "New South Wales";
    String altCountry = "Australia";
    com.google.api.services.people.v1.model.Address altAddress = new com.google.api.services.people.v1.model.Address().setStreetAddress(altStreet).setCity(altCity).setRegion(altRegion).setCountry(altCountry).setMetadata(SECONDARY_FIELD_METADATA);
    Person person = DEFAULT_PERSON.setAddresses(Arrays.asList(altAddress, primaryAddress));
    // Run test
    VCard vCard = GoogleContactToVCardConverter.convert(person);
    // Check results for correct values and preferences
    List<Address> actualPrimaryAddressList = getPropertiesWithPreference(vCard, Address.class, VCARD_PRIMARY_PREF);
    assertThat(actualPrimaryAddressList.stream().map(Address::getStreetAddress).collect(Collectors.toList())).containsExactly(primaryStreet);
    List<Address> actualAltAddressList = getPropertiesWithPreference(vCard, Address.class, VCARD_PRIMARY_PREF + 1);
    assertThat(actualAltAddressList.stream().map(Address::getRegion).collect(Collectors.toList())).containsExactly(altRegion);
}
Also used : EmailAddress(com.google.api.services.people.v1.model.EmailAddress) Address(ezvcard.property.Address) Person(com.google.api.services.people.v1.model.Person) VCard(ezvcard.VCard) Test(org.junit.Test)

Aggregations

Address (ezvcard.property.Address)28 Test (org.junit.Test)14 VCard (ezvcard.VCard)12 StructuredName (ezvcard.property.StructuredName)9 Telephone (ezvcard.property.Telephone)8 Timezone (ezvcard.property.Timezone)6 TelUri (ezvcard.util.TelUri)6 UtcOffset (ezvcard.util.UtcOffset)6 Birthday (ezvcard.property.Birthday)5 Anniversary (ezvcard.property.Anniversary)4 Geo (ezvcard.property.Geo)4 Key (ezvcard.property.Key)4 Label (ezvcard.property.Label)4 VCardVersion (ezvcard.VCardVersion)3 Email (ezvcard.property.Email)3 Photo (ezvcard.property.Photo)3 Sound (ezvcard.property.Sound)3 File (java.io.File)3 EmailAddress (com.google.api.services.people.v1.model.EmailAddress)2 Person (com.google.api.services.people.v1.model.Person)2