Search in sources :

Example 1 with Name

use of com.google.api.services.people.v1.model.Name in project BachelorPraktikum by lucasbuschlinger.

the class GooglePlaces method fetchOwnAddresses.

// /**
// * Setter for the query keyword search params.
// * @param keywordSearchParams valid search params that will be appended to the query
// */
// public void setKeywordSearchParams(final String[] keywordSearchParams) {
// for (String param : keywordSearchParams) {
// keywordSearch = keywordSearch + " OR (" + param.toLowerCase() + ")";
// }
// }
// 
// /**
// * Searches the context with the previously set keyword search params
// * and the given location (latitude, longitude) and radius (accuracy).
// * @param latitude a valid latitude
// * @param longitude a valid longitude
// * @param accuracy a radius in meters
// * @return The name of the result if there was a place found with the given query params, otherwise "AWAY"
// */
// public String keywordSearch(final double latitude, final double longitude, final int accuracy) {
// try {
// PlacesSearchResult[] results = PlacesApi
// .nearbySearchQuery(context, new LatLng(latitude, longitude))
// .radius(accuracy)
// .keyword(keywordSearch)
// .await().results;
// if (results.length == 1) {
// return results[0].name;
// } else {
// for (PlacesSearchResult sr : results) {
// boolean isPolitical = false;
// for (String st : sr.types) {
// if (st.equals("political")) {
// isPolitical = true;
// }
// }
// 
// if (!isPolitical) {
// return sr.name;
// }
// }
// }
// } catch (ApiException | InterruptedException | IOException e) {
// e.printStackTrace();
// }
// 
// return "AWAY";
// }
/**
 * Retrieves the own addresses of the current user.
 */
public void fetchOwnAddresses() {
    if (context != null) {
        Person me = GooglePeople.getInstance().getProfile();
        if (me.getAddresses() != null) {
            for (Address res : me.getAddresses()) {
                String name = res.getFormattedType();
                List<Address> address = Arrays.asList(res);
                ownAddresses.add(new Contact(name, address));
            }
        }
    }
}
Also used : Address(com.google.api.services.people.v1.model.Address) Person(com.google.api.services.people.v1.model.Person) Contact(de.opendiabetes.vault.plugin.importer.googlecrawler.models.Contact)

Example 2 with Name

use of com.google.api.services.people.v1.model.Name in project data-transfer-project by google.

the class GoogleContactsImportConversionTest method testConversionToGoogleNames.

@Test
public void testConversionToGoogleNames() {
    // Set up vCard with a primary name and one secondary name
    String primaryGivenName = "Mark";
    String primaryFamilyName = "Twain";
    String primarySourceType = "CONTACT";
    StructuredName primaryName = makeStructuredName(primaryGivenName, primaryFamilyName, primarySourceType);
    String altGivenName = "Samuel";
    String altFamilyName = "Clemens";
    String altSourceType = "PROFILE";
    StructuredName altName = makeStructuredName(altGivenName, altFamilyName, altSourceType);
    VCard vCard = new VCard();
    vCard.addProperty(primaryName);
    vCard.addPropertyAlt(StructuredName.class, Collections.singleton(altName));
    // Run test
    Person person = GoogleContactsImporter.convert(vCard);
    // Check results
    // Correct number of names
    assertThat(person.getNames().size()).isEqualTo(1);
    // Check primary names
    List<Name> actualPrimaryNames = person.getNames().stream().filter(a -> a.getMetadata().getPrimary()).collect(Collectors.toList());
    List<Pair<String, String>> actualPrimaryNameValues = actualPrimaryNames.stream().map(GoogleContactsImportConversionTest::getGivenAndFamilyValues).collect(Collectors.toList());
    assertThat(actualPrimaryNameValues).containsExactly(Pair.of(primaryGivenName, primaryFamilyName));
    List<String> actualPrimaryNameSourceValues = actualPrimaryNames.stream().map(a -> a.getMetadata().getSource().getType()).collect(Collectors.toList());
    assertThat(actualPrimaryNameSourceValues).containsExactly(primarySourceType);
    // Check secondary names - there shouldn't be any
    List<Name> actualSecondaryNames = person.getNames().stream().filter(a -> !a.getMetadata().getPrimary()).collect(Collectors.toList());
    assertThat(actualSecondaryNames).isEmpty();
}
Also used : VCard(ezvcard.VCard) EmailAddress(com.google.api.services.people.v1.model.EmailAddress) Telephone(ezvcard.property.Telephone) Test(org.junit.Test) PhoneNumber(com.google.api.services.people.v1.model.PhoneNumber) Truth.assertThat(com.google.common.truth.Truth.assertThat) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) StructuredName(ezvcard.property.StructuredName) SOURCE_PARAM_NAME_TYPE(org.dataportabilityproject.datatransfer.google.common.GoogleStaticObjects.SOURCE_PARAM_NAME_TYPE) Pair(com.google.gdata.util.common.base.Pair) Person(com.google.api.services.people.v1.model.Person) List(java.util.List) CONTACT_SOURCE_TYPE(org.dataportabilityproject.datatransfer.google.common.GoogleStaticObjects.CONTACT_SOURCE_TYPE) Nullable(com.google.gdata.util.common.base.Nullable) Address(com.google.api.services.people.v1.model.Address) Email(ezvcard.property.Email) VCARD_PRIMARY_PREF(org.dataportabilityproject.datatransfer.google.common.GoogleStaticObjects.VCARD_PRIMARY_PREF) Name(com.google.api.services.people.v1.model.Name) Collections(java.util.Collections) Before(org.junit.Before) StructuredName(ezvcard.property.StructuredName) VCard(ezvcard.VCard) Person(com.google.api.services.people.v1.model.Person) StructuredName(ezvcard.property.StructuredName) Name(com.google.api.services.people.v1.model.Name) Pair(com.google.gdata.util.common.base.Pair) Test(org.junit.Test)

Example 3 with Name

use of com.google.api.services.people.v1.model.Name in project data-transfer-project by google.

the class GoogleContactToVCardConverter 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);
}
Also used : StructuredName(ezvcard.property.StructuredName) LinkedList(java.util.LinkedList) StructuredName(ezvcard.property.StructuredName) Name(com.google.api.services.people.v1.model.Name)

Example 4 with Name

use of com.google.api.services.people.v1.model.Name in project data-transfer-project by google.

the class VCardToGoogleContactConverter 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);
}
Also used : VCard(ezvcard.VCard) Logger(org.slf4j.Logger) VCARD_PRIMARY_PREF(org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.VCARD_PRIMARY_PREF) EmailAddress(com.google.api.services.people.v1.model.EmailAddress) Telephone(ezvcard.property.Telephone) LoggerFactory(org.slf4j.LoggerFactory) SOURCE_PARAM_NAME_TYPE(org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.SOURCE_PARAM_NAME_TYPE) PhoneNumber(com.google.api.services.people.v1.model.PhoneNumber) Collectors(java.util.stream.Collectors) StructuredName(ezvcard.property.StructuredName) Person(com.google.api.services.people.v1.model.Person) List(java.util.List) FieldMetadata(com.google.api.services.people.v1.model.FieldMetadata) Source(com.google.api.services.people.v1.model.Source) CONTACT_SOURCE_TYPE(org.dataportabilityproject.serviceProviders.google.contacts.GoogleContactsConstants.CONTACT_SOURCE_TYPE) Email(ezvcard.property.Email) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Name(com.google.api.services.people.v1.model.Name) Collections(java.util.Collections) StructuredName(ezvcard.property.StructuredName)

Example 5 with Name

use of com.google.api.services.people.v1.model.Name in project data-transfer-project by google.

the class VCardToGoogleContactConverter 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;
}
Also used : FieldMetadata(com.google.api.services.people.v1.model.FieldMetadata) Source(com.google.api.services.people.v1.model.Source) StructuredName(ezvcard.property.StructuredName) Name(com.google.api.services.people.v1.model.Name)

Aggregations

Name (com.google.api.services.people.v1.model.Name)10 StructuredName (ezvcard.property.StructuredName)10 Person (com.google.api.services.people.v1.model.Person)9 EmailAddress (com.google.api.services.people.v1.model.EmailAddress)6 FieldMetadata (com.google.api.services.people.v1.model.FieldMetadata)6 PhoneNumber (com.google.api.services.people.v1.model.PhoneNumber)6 Source (com.google.api.services.people.v1.model.Source)6 VCard (ezvcard.VCard)6 Email (ezvcard.property.Email)6 Telephone (ezvcard.property.Telephone)6 Collections (java.util.Collections)6 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 Truth.assertThat (com.google.common.truth.Truth.assertThat)4 Pair (com.google.gdata.util.common.base.Pair)4 Function (java.util.function.Function)4 Test (org.junit.Test)4 Address (com.google.api.services.people.v1.model.Address)3 SOURCE_PARAM_NAME_TYPE (org.dataportabilityproject.datatransfer.google.common.GoogleStaticObjects.SOURCE_PARAM_NAME_TYPE)3