use of sqlite.feature.many2many.case6.model.Person in project data-transfer-project by google.
the class GoogleContactToVCardConverterTest 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 = GoogleContactToVCardConverter.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(GoogleContactToVCardConverterTest::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(GoogleContactToVCardConverterTest::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);
}
use of sqlite.feature.many2many.case6.model.Person in project data-transfer-project by google.
the class VCardToGoogleContactConverterTest method testConversionToGooglePhones.
@Test
public void testConversionToGooglePhones() {
// Set up test: vCard with 2 primary phone numbers and 1 secondary phone number
String primaryValue1 = "334-844-4244";
String primaryValue2 = "411";
String secondaryValue = "(555) 867-5309";
Telephone primaryTelephone1 = new Telephone(primaryValue1);
primaryTelephone1.setPref(VCARD_PRIMARY_PREF);
Telephone primaryTelephone2 = new Telephone(primaryValue2);
primaryTelephone2.setPref(VCARD_PRIMARY_PREF);
Telephone secondaryTelephone = new Telephone(secondaryValue);
secondaryTelephone.setPref(VCARD_PRIMARY_PREF + 1);
// Add numbers to vCard. Order shouldn't matter.
VCard vCard = defaultVCard;
vCard.addTelephoneNumber(secondaryTelephone);
vCard.addTelephoneNumber(primaryTelephone1);
vCard.addTelephoneNumber(primaryTelephone2);
// Run test
Person person = VCardToGoogleContactConverter.convert(vCard);
// Check results
// Correct number of phone numbers
assertThat(person.getPhoneNumbers().size()).isEqualTo(3);
// Check primary phone numbers
List<PhoneNumber> actualPrimaryNumbers = person.getPhoneNumbers().stream().filter(a -> a.getMetadata().getPrimary()).collect(Collectors.toList());
List<String> actualPrimaryNumberStrings = getValuesFromFields(actualPrimaryNumbers, PhoneNumber::getValue);
assertThat(actualPrimaryNumberStrings).containsExactly(primaryValue1, primaryValue2);
// Check secondary phone numbers
List<PhoneNumber> actualSecondaryNumbers = person.getPhoneNumbers().stream().filter(a -> !a.getMetadata().getPrimary()).collect(Collectors.toList());
List<String> actualSecondaryNumberStrings = getValuesFromFields(actualSecondaryNumbers, PhoneNumber::getValue);
assertThat(actualSecondaryNumberStrings).containsExactly(secondaryValue);
}
use of sqlite.feature.many2many.case6.model.Person in project data-transfer-project by google.
the class VCardToGoogleContactConverterTest method testConversionToGoogleAddresses.
@Test
public void testConversionToGoogleAddresses() {
// Set up vCard with a primary address and a secondary address
String primaryStreet = "221B Baker St";
String primaryLocality = "London";
ezvcard.property.Address primaryAddress = new ezvcard.property.Address();
primaryAddress.setStreetAddress(primaryStreet);
primaryAddress.setLocality(primaryLocality);
primaryAddress.setPref(VCARD_PRIMARY_PREF);
String altStreet = "42 Wallaby Way";
String altLocality = "Sydney";
ezvcard.property.Address altAddress = new ezvcard.property.Address();
altAddress.setStreetAddress(altStreet);
altAddress.setLocality(altLocality);
altAddress.setPref(VCARD_PRIMARY_PREF + 1);
// Add addresses to vCard. Order shouldn't matter.
VCard vCard = defaultVCard;
vCard.addAddress(primaryAddress);
vCard.addAddress(altAddress);
// Run test
Person person = VCardToGoogleContactConverter.convert(vCard);
// Check results
// Check correct number of addresses
assertThat(person.getAddresses().size()).isEqualTo(2);
// Check primary address
List<Address> actualPrimaryAddresses = person.getAddresses().stream().filter(a -> a.getMetadata().getPrimary()).collect(Collectors.toList());
List<String> actualPrimaryAddressStreets = getValuesFromFields(actualPrimaryAddresses, Address::getStreetAddress);
assertThat(actualPrimaryAddressStreets).containsExactly(primaryStreet);
// Check secondary address
List<Address> actualSecondaryAddresses = person.getAddresses().stream().filter(a -> !a.getMetadata().getPrimary()).collect(Collectors.toList());
List<String> actualSecondaryAddressStreets = getValuesFromFields(actualSecondaryAddresses, Address::getStreetAddress);
assertThat(actualSecondaryAddressStreets).containsExactly(altStreet);
}
use of sqlite.feature.many2many.case6.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.case6.model.Person in project compss by bsc-wdc.
the class External method testMergeReduceTarget.
public static void testMergeReduceTarget() {
// Init
Person[] people = new Person[4];
for (int i = 0; i < people.length; ++i) {
String id = "person_" + UUID.randomUUID().toString();
System.out.println("[LOG][PSCO_MR_TARGET] Person " + i + " BeginId = " + id);
people[i] = new Person("PName" + i, i, i);
people[i].makePersistent(id);
}
// Map
for (int i = 0; i < people.length; ++i) {
people[i].taskMap("NewName" + i);
}
// Reduce
LinkedList<Integer> q = new LinkedList<Integer>();
for (int i = 0; i < people.length; i++) {
q.add(i);
}
int x = 0;
while (!q.isEmpty()) {
x = q.poll();
int y;
if (!q.isEmpty()) {
y = q.poll();
people[x].taskReduce(people[y]);
q.add(x);
}
}
// Get (sync) and write result
Person p1 = people[0];
String name = p1.getName();
int age = p1.getAge();
int numC = p1.getNumComputers();
System.out.println("[LOG][PSCO_MR_TARGET] Person " + name + " with age " + age + " has " + numC + " computers");
System.out.println("[LOG][PSCO_MR_TARGET] EndId = " + p1.getID());
}
Aggregations