use of sqlite.feature.many2many.case4.model.Person 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 sqlite.feature.many2many.case4.model.Person in project data-transfer-project by google.
the class GoogleContactsExporter method exportContacts.
private ExportResult<ContactsModelWrapper> exportContacts(TokensAndUrlAuthData authData, Optional<PaginationData> pageData) {
try {
// Set up connection
Connections.List connectionsListRequest = getOrCreatePeopleService(authData).people().connections().list(SELF_RESOURCE);
// Get next page, if we have a page token
if (pageData.isPresent()) {
StringPaginationToken paginationToken = (StringPaginationToken) pageData.get();
connectionsListRequest.setPageToken(paginationToken.getToken());
}
// Get list of connections (nb: not a list containing full info of each Person)
ListConnectionsResponse response = connectionsListRequest.setPersonFields(PERSON_FIELDS).execute();
List<Person> peopleList = response.getConnections();
// Get list of resource names, then get list of Persons
List<String> resourceNames = peopleList.stream().map(Person::getResourceName).collect(Collectors.toList());
GetPeopleResponse batchResponse = getOrCreatePeopleService(authData).people().getBatchGet().setResourceNames(resourceNames).setPersonFields(PERSON_FIELDS).execute();
List<PersonResponse> personResponseList = batchResponse.getResponses();
// Convert Persons to VCards
List<VCard> vCards = personResponseList.stream().map(a -> convert(a.getPerson())).collect(Collectors.toList());
// Determine if there's a next page
StringPaginationToken nextPageData = null;
if (response.getNextPageToken() != null) {
nextPageData = new StringPaginationToken(response.getNextPageToken());
}
ContinuationData continuationData = new ContinuationData(nextPageData);
ContactsModelWrapper wrapper = new ContactsModelWrapper(makeVCardString(vCards));
// Get result type
ResultType resultType = ResultType.CONTINUE;
if (nextPageData == null) {
resultType = ResultType.END;
}
return new ExportResult<ContactsModelWrapper>(resultType, wrapper, continuationData);
} catch (IOException e) {
return new ExportResult<ContactsModelWrapper>(ResultType.ERROR, e.getMessage());
}
}
use of sqlite.feature.many2many.case4.model.Person 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 sqlite.feature.many2many.case4.model.Person in project data-transfer-project by google.
the class VCardToGoogleContactConverter method convert.
// TODO(olsona): can we guarantee that <VCARDPROPERTY>.getPref() will always return a value?
@VisibleForTesting
static Person convert(VCard vCard) {
Person person = new Person();
Preconditions.checkArgument(atLeastOneNamePresent(vCard), "At least one name must be present");
person.setNames(Collections.singletonList(getPrimaryGoogleName(vCard.getStructuredNames())));
if (vCard.getAddresses() != null) {
person.setAddresses(vCard.getAddresses().stream().map(VCardToGoogleContactConverter::convertToGoogleAddress).collect(Collectors.toList()));
}
if (vCard.getTelephoneNumbers() != null) {
person.setPhoneNumbers(vCard.getTelephoneNumbers().stream().map(VCardToGoogleContactConverter::convertToGooglePhoneNumber).collect(Collectors.toList()));
}
if (vCard.getEmails() != null) {
person.setEmailAddresses(vCard.getEmails().stream().map(VCardToGoogleContactConverter::convertToGoogleEmail).collect(Collectors.toList()));
}
return person;
}
use of sqlite.feature.many2many.case4.model.Person in project data-transfer-project by google.
the class GoogleContactToVCardConverterTest method testConversionToVCardEmail.
@Test
public void testConversionToVCardEmail() {
// Set up test: person with 1 primary email and 2 secondary emails
String primaryString = "primary@email.com";
String secondaryString1 = "secondary1@email.com";
String secondaryString2 = "secondary2@email.com";
EmailAddress primaryEmail = new EmailAddress().setValue(primaryString).setMetadata(PRIMARY_FIELD_METADATA);
EmailAddress secondaryEmail1 = new EmailAddress().setValue(secondaryString1).setMetadata(SECONDARY_FIELD_METADATA);
EmailAddress secondaryEmail2 = new EmailAddress().setValue(secondaryString2).setMetadata(SECONDARY_FIELD_METADATA);
Person person = DEFAULT_PERSON.setEmailAddresses(Arrays.asList(secondaryEmail1, primaryEmail, // Making sure order isn't a factor
secondaryEmail2));
// Run test - NB, this Person only has emails
VCard vCard = GoogleContactToVCardConverter.convert(person);
// Check results for correct values and preferences
List<Email> resultPrimaryEmailList = getPropertiesWithPreference(vCard, Email.class, VCARD_PRIMARY_PREF);
assertThat(getValuesFromTextProperties(resultPrimaryEmailList)).containsExactly(primaryString);
List<Email> resultSecondaryEmailList = getPropertiesWithPreference(vCard, Email.class, VCARD_PRIMARY_PREF + 1);
assertThat(getValuesFromTextProperties(resultSecondaryEmailList)).containsExactly(secondaryString1, secondaryString2);
}
Aggregations