Search in sources :

Example 1 with CreateContact

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();
}
Also used : ContactsModelWrapper(org.dataportabilityproject.types.transfer.models.contacts.ContactsModelWrapper) VCard(ezvcard.VCard) StructuredName(ezvcard.property.StructuredName) Person(com.google.api.services.people.v1.model.Person) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 2 with CreateContact

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);
}
Also used : Connections(com.google.api.services.people.v1.PeopleService.People.Connections) PeopleService(com.google.api.services.people.v1.PeopleService) People(com.google.api.services.people.v1.PeopleService.People) CreateContact(com.google.api.services.people.v1.PeopleService.People.CreateContact) InMemoryJobDataCache(org.dataportabilityproject.cloud.local.InMemoryJobDataCache) LinkedList(java.util.LinkedList) List(java.util.List) GetBatchGet(com.google.api.services.people.v1.PeopleService.People.GetBatchGet) Person(com.google.api.services.people.v1.model.Person) Before(org.junit.Before)

Example 3 with CreateContact

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();
}
Also used : ContactsModelWrapper(org.dataportabilityproject.dataModels.contacts.ContactsModelWrapper) VCard(ezvcard.VCard) StructuredName(ezvcard.property.StructuredName) Person(com.google.api.services.people.v1.model.Person) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 4 with CreateContact

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());
    }
}
Also used : ImportResult(org.dataportabilityproject.spi.transfer.provider.ImportResult) IOException(java.io.IOException) JCardReader(ezvcard.io.json.JCardReader) VCard(ezvcard.VCard) Person(com.google.api.services.people.v1.model.Person)

Example 5 with CreateContact

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);
    }
}
Also used : VCard(ezvcard.VCard) Person(com.google.api.services.people.v1.model.Person)

Aggregations

Person (com.google.api.services.people.v1.model.Person)5 VCard (ezvcard.VCard)4 LinkedList (java.util.LinkedList)3 StructuredName (ezvcard.property.StructuredName)2 Test (org.junit.Test)2 PeopleService (com.google.api.services.people.v1.PeopleService)1 People (com.google.api.services.people.v1.PeopleService.People)1 Connections (com.google.api.services.people.v1.PeopleService.People.Connections)1 CreateContact (com.google.api.services.people.v1.PeopleService.People.CreateContact)1 GetBatchGet (com.google.api.services.people.v1.PeopleService.People.GetBatchGet)1 JCardReader (ezvcard.io.json.JCardReader)1 IOException (java.io.IOException)1 List (java.util.List)1 InMemoryJobDataCache (org.dataportabilityproject.cloud.local.InMemoryJobDataCache)1 ContactsModelWrapper (org.dataportabilityproject.dataModels.contacts.ContactsModelWrapper)1 ImportResult (org.dataportabilityproject.spi.transfer.provider.ImportResult)1 ContactsModelWrapper (org.dataportabilityproject.types.transfer.models.contacts.ContactsModelWrapper)1 Before (org.junit.Before)1