use of com.google.api.services.people.v1.PeopleService.People.CreateContact in project data-transfer-project by google.
the class GoogleContactsImporterTest method importFirstResources.
@Test
public void importFirstResources() throws IOException {
// Set up: small number of VCards to be imported
int numberOfVCards = 5;
List<VCard> vCardList = new LinkedList<>();
for (int i = 0; i < numberOfVCards; i++) {
StructuredName structuredName = new StructuredName();
structuredName.setFamily("Family" + i);
structuredName.setParameter(SOURCE_PARAM_NAME_TYPE, CONTACT_SOURCE_TYPE);
VCard vCard = new VCard();
vCard.setStructuredName(structuredName);
vCardList.add(vCard);
}
String vCardString = GoogleContactsExporter.makeVCardString(vCardList);
ContactsModelWrapper wrapper = new ContactsModelWrapper(vCardString);
// Run test
contactsService.importItem(UUID.randomUUID(), null, wrapper);
// Check that the right methods were called
verify(people, times(numberOfVCards)).createContact(any(Person.class));
verify(createContact, times(numberOfVCards)).execute();
}
use of com.google.api.services.people.v1.PeopleService.People.CreateContact in project data-transfer-project by google.
the class GoogleContactsServiceTest method setup.
@Before
public void setup() throws IOException {
connections = mock(Connections.class);
getBatchGet = mock(GetBatchGet.class);
people = mock(People.class);
peopleService = mock(PeopleService.class);
listConnectionsRequest = mock(Connections.List.class);
createContact = mock(CreateContact.class);
jobDataCache = new InMemoryJobDataCache();
contactsService = new GoogleContactsService(peopleService, jobDataCache);
when(getBatchGet.setPersonFields(PERSON_FIELDS)).thenReturn(getBatchGet);
when(people.connections()).thenReturn(connections);
when(people.getBatchGet()).thenReturn(getBatchGet);
when(people.createContact(any(Person.class))).thenReturn(createContact);
when(peopleService.people()).thenReturn(people);
}
use of com.google.api.services.people.v1.PeopleService.People.CreateContact in project data-transfer-project by google.
the class GoogleContactsServiceTest method importFirstResources.
@Test
public void importFirstResources() throws IOException {
// Set up: small number of VCards to be imported
int numberOfVCards = 5;
List<VCard> vCardList = new LinkedList<>();
for (int i = 0; i < numberOfVCards; i++) {
StructuredName structuredName = new StructuredName();
structuredName.setFamily("Family" + i);
structuredName.setParameter(SOURCE_PARAM_NAME_TYPE, CONTACT_SOURCE_TYPE);
VCard vCard = new VCard();
vCard.setStructuredName(structuredName);
vCardList.add(vCard);
}
ContactsModelWrapper wrapper = new ContactsModelWrapper(vCardList, null);
// Run test
contactsService.importItem(wrapper);
// Check that the right methods were called
verify(people, times(numberOfVCards)).createContact(any(Person.class));
verify(createContact, times(numberOfVCards)).execute();
}
use of com.google.api.services.people.v1.PeopleService.People.CreateContact in project data-transfer-project by google.
the class GoogleContactsImporter method importItem.
@Override
public ImportResult importItem(UUID jobId, TokensAndUrlAuthData authData, ContactsModelWrapper data) {
JCardReader reader = new JCardReader(data.getVCards());
try {
// TODO(olsona): address any other problems that might arise in conversion
List<VCard> vCardList = reader.readAll();
for (VCard vCard : vCardList) {
Person person = convert(vCard);
getOrCreatePeopleService(authData).people().createContact(person).execute();
}
return ImportResult.OK;
} catch (IOException e) {
return new ImportResult(ImportResult.ResultType.ERROR, e.getMessage());
}
}
use of com.google.api.services.people.v1.PeopleService.People.CreateContact 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);
}
}
Aggregations