use of sqlite.feature.many2many.case5.model.Person in project data-transfer-project by google.
the class GoogleContactsService method importItem.
@Override
public void importItem(ContactsModelWrapper wrapper) throws IOException {
// TODO(olsona): continuation information
// First, assume no ContinuationInformation
Collection<VCard> vCardCollection = wrapper.getVCards();
for (VCard vCard : vCardCollection) {
Person person = VCardToGoogleContactConverter.convert(vCard);
peopleService.people().createContact(person).execute();
logger.debug("Imported {}", person);
}
}
use of sqlite.feature.many2many.case5.model.Person in project data-transfer-project by google.
the class GoogleContactsService method export.
public ContactsModelWrapper export(ExportInformation continuationInformation) throws IOException {
// Set up connection
Connections.List connectionsList = peopleService.people().connections().list(GoogleContactsConstants.SELF_RESOURCE);
// Get next page, if we have a page token
if (continuationInformation.getPaginationInformation().isPresent()) {
String pageToken = ((StringPaginationToken) continuationInformation.getPaginationInformation().get()).getId();
connectionsList.setPageToken(pageToken);
}
// Get list of connections (nb: not a list containing full info of each Person)
ListConnectionsResponse response = connectionsList.setPersonFields(GoogleContactsConstants.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 = peopleService.people().getBatchGet().setResourceNames(resourceNames).setPersonFields(GoogleContactsConstants.PERSON_FIELDS).execute();
List<PersonResponse> personResponseList = batchResponse.getResponses();
// Convert Persons to VCards
List<VCard> vCards = personResponseList.stream().map(a -> GoogleContactToVCardConverter.convert(a.getPerson())).collect(Collectors.toList());
// Determine if there's a next page
StringPaginationToken newPage = null;
if (response.getNextPageToken() != null) {
newPage = new StringPaginationToken(response.getNextPageToken());
}
ContinuationInformation newContinuationInformation = null;
if (newPage != null) {
newContinuationInformation = new ContinuationInformation(null, newPage);
}
return new ContactsModelWrapper(vCards, newContinuationInformation);
}
use of sqlite.feature.many2many.case5.model.Person 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);
}
use of sqlite.feature.many2many.case5.model.Person in project data-transfer-project by google.
the class GoogleContactsExportConversionTest 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 = GoogleContactsExporter.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.case5.model.Person in project data-transfer-project by google.
the class GoogleContactsExportConversionTest method testConversionToVCardNames.
@Test
public void testConversionToVCardNames() {
// Set up Person with a primary name and two secondary names
String primaryGivenName = "Mark";
String primaryFamilyName = "Twain";
Name primaryName = new Name().setGivenName(primaryGivenName).setFamilyName(primaryFamilyName).setMetadata(PRIMARY_FIELD_METADATA);
String alternateGivenName1 = "Samuel";
String alternateFamilyName1 = "Clemens";
String alternateSourceType1 = "PROFILE";
Name alternateName1 = new Name().setGivenName(alternateGivenName1).setFamilyName(alternateFamilyName1).setMetadata(new FieldMetadata().setPrimary(false).setSource(new Source().setType(alternateSourceType1)));
String alternateGivenName2 = "Louis";
String alternateFamilyName2 = "de Conte";
String alternateSourceType2 = "PEN_NAME";
Name alternateName2 = new Name().setGivenName(alternateGivenName2).setFamilyName(alternateFamilyName2).setMetadata(new FieldMetadata().setPrimary(false).setSource(new Source().setType(alternateSourceType2)));
// Order shouldn't matter
Person person = new Person().setNames(Arrays.asList(alternateName2, alternateName1, primaryName));
// Run test
VCard vCard = GoogleContactsExporter.convert(person);
// Check name conversion correctness
List<StructuredName> structuredNames = vCard.getStructuredNames();
assertThat(structuredNames.size()).isEqualTo(3);
// Check primary (non-alternate) names
List<StructuredName> actualPrimaryNames = structuredNames.stream().filter(n -> n.getAltId() == null).collect(Collectors.toList());
List<Pair<String, String>> actualPrimaryNamesValues = actualPrimaryNames.stream().map(GoogleContactsExportConversionTest::getGivenAndFamilyNames).collect(Collectors.toList());
assertThat(actualPrimaryNamesValues).containsExactly(Pair.of(primaryGivenName, primaryFamilyName));
List<String> actualPrimarySourceValues = actualPrimaryNames.stream().map(a -> a.getParameter(SOURCE_PARAM_NAME_TYPE)).collect(Collectors.toList());
assertThat(actualPrimarySourceValues).containsExactly(DEFAULT_SOURCE_TYPE);
// Check alternate names
List<StructuredName> actualAlternateNames = structuredNames.stream().filter(n -> n.getAltId() != null).collect(Collectors.toList());
List<Pair<String, String>> actualAlternateNamesValues = actualAlternateNames.stream().map(GoogleContactsExportConversionTest::getGivenAndFamilyNames).collect(Collectors.toList());
assertThat(actualAlternateNamesValues).containsExactly(Pair.of(alternateGivenName1, alternateFamilyName1), Pair.of(alternateGivenName2, alternateFamilyName2));
List<String> actualAlternateSourceValues = actualAlternateNames.stream().map(a -> a.getParameter(SOURCE_PARAM_NAME_TYPE)).collect(Collectors.toList());
assertThat(actualAlternateSourceValues).containsExactly(alternateSourceType1, alternateSourceType2);
}
Aggregations