use of sqlite.feature.many2many.case6.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.case6.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.case6.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.case6.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);
}
use of sqlite.feature.many2many.case6.model.Person in project data-transfer-project by google.
the class GoogleContactToVCardConverterTest method testConversionToVCardTelephone.
@Test
public void testConversionToVCardTelephone() {
// Set up test: person with 2 primary phone numbers and 1 secondary phone number
String primaryValue1 = "334-844-4244";
String primaryValue2 = "411";
String secondaryValue = "(555) 867-5309";
PhoneNumber primaryPhone1 = new PhoneNumber().setValue(primaryValue1).setMetadata(PRIMARY_FIELD_METADATA);
PhoneNumber primaryPhone2 = new PhoneNumber().setValue(primaryValue2).setMetadata(PRIMARY_FIELD_METADATA);
PhoneNumber secondaryPhone = new PhoneNumber().setValue(secondaryValue).setMetadata(SECONDARY_FIELD_METADATA);
Person person = DEFAULT_PERSON.setPhoneNumbers(Arrays.asList(secondaryPhone, primaryPhone1, primaryPhone2));
// Run test
VCard vCard = GoogleContactToVCardConverter.convert(person);
// Check results for correct values and preferences
List<Telephone> resultPrimaryPhoneList = getPropertiesWithPreference(vCard, Telephone.class, VCARD_PRIMARY_PREF);
assertThat(getValuesFromProperties(resultPrimaryPhoneList, Telephone::getText)).containsExactly(primaryValue1, primaryValue2);
List<Telephone> resultSecondaryPhoneList = getPropertiesWithPreference(vCard, Telephone.class, VCARD_PRIMARY_PREF + 1);
assertThat(getValuesFromProperties(resultSecondaryPhoneList, Telephone::getText)).containsExactly(secondaryValue);
}
Aggregations