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