use of com.google.api.services.people.v1.model.GetPeopleResponse 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 com.google.api.services.people.v1.model.GetPeopleResponse in project data-transfer-project by google.
the class GoogleContactsServiceTest method setUpSinglePersonResponse.
private void setUpSinglePersonResponse() throws IOException {
connectionsList = Collections.singletonList(PERSON);
listConnectionsResponse = new ListConnectionsResponse();
listConnectionsResponse.setConnections(connectionsList);
PersonResponse personResponse = new PersonResponse().setPerson(PERSON);
GetPeopleResponse batchResponse = new GetPeopleResponse().setResponses(Collections.singletonList(personResponse));
// This can't go in setup()
when(listConnectionsRequest.setPersonFields(PERSON_FIELDS)).thenReturn(listConnectionsRequest);
when(listConnectionsRequest.execute()).thenReturn(listConnectionsResponse);
// This is specific to returning a single Person
when(connections.list(SELF_RESOURCE)).thenReturn(listConnectionsRequest);
when(getBatchGet.setResourceNames(Collections.singletonList(RESOURCE_NAME))).thenReturn(getBatchGet);
when(getBatchGet.execute()).thenReturn(batchResponse);
}
use of com.google.api.services.people.v1.model.GetPeopleResponse 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 com.google.api.services.people.v1.model.GetPeopleResponse in project data-transfer-project by google.
the class GoogleContactsExporterTest method setUpSinglePersonResponse.
private void setUpSinglePersonResponse() throws IOException {
connectionsList = Collections.singletonList(PERSON);
listConnectionsResponse = new ListConnectionsResponse();
listConnectionsResponse.setConnections(connectionsList);
PersonResponse personResponse = new PersonResponse().setPerson(PERSON);
GetPeopleResponse batchResponse = new GetPeopleResponse().setResponses(Collections.singletonList(personResponse));
// This can't go in setup()
when(listConnectionsRequest.setPersonFields(PERSON_FIELDS)).thenReturn(listConnectionsRequest);
when(listConnectionsRequest.execute()).thenReturn(listConnectionsResponse);
// This is specific to returning a single Person
when(connections.list(SELF_RESOURCE)).thenReturn(listConnectionsRequest);
when(getBatchGet.setResourceNames(Collections.singletonList(RESOURCE_NAME))).thenReturn(getBatchGet);
when(getBatchGet.execute()).thenReturn(batchResponse);
}
Aggregations