use of org.dataportabilityproject.shared.StringPaginationToken in project data-transfer-project by google.
the class GoogleCalendarService method exportCalendars.
private CalendarModelWrapper exportCalendars(Optional<PaginationInformation> pageInfo) throws IOException {
Calendar.CalendarList.List listRequest = calendarClient.calendarList().list();
if (pageInfo.isPresent()) {
listRequest.setPageToken(((StringPaginationToken) pageInfo.get()).getId());
}
CalendarList listResult = listRequest.execute();
List<CalendarModel> calendarModels = new ArrayList<>(listResult.getItems().size());
List<Resource> resources = new ArrayList<>(listResult.getItems().size());
for (CalendarListEntry calendarData : listResult.getItems()) {
CalendarModel model = GoogleCalendarToModelConverter.convertToCalendarModel(calendarData);
resources.add(new IdOnlyResource(calendarData.getId()));
calendarModels.add(model);
}
PaginationInformation newPageInfo = null;
if (listResult.getNextPageToken() != null) {
newPageInfo = new StringPaginationToken(listResult.getNextPageToken());
}
return new CalendarModelWrapper(calendarModels, null, new ContinuationInformation(resources, newPageInfo));
}
use of org.dataportabilityproject.shared.StringPaginationToken in project data-transfer-project by google.
the class GoogleMailService method export.
// This currently exports each message with associated labels
@Override
public MailModelWrapper export(ExportInformation exportInformation) throws IOException {
Messages.List request = gmail.users().messages().list(USER).setMaxResults(MAX_RESULTS_PER_REQUEST);
if (exportInformation.getPaginationInformation().isPresent()) {
request.setPageToken(((StringPaginationToken) exportInformation.getPaginationInformation().get()).getId());
}
ListMessagesResponse response = request.execute();
List<MailMessageModel> results = new ArrayList<>(response.getMessages().size());
// as we can't store all the mail messagess in memory at once.
for (Message listMessage : response.getMessages()) {
Message getResponse = gmail.users().messages().get(USER, listMessage.getId()).setFormat("raw").execute();
// TODO: note this doesn't transfer things like labels
results.add(new MailMessageModel(getResponse.getRaw(), getResponse.getLabelIds()));
}
PaginationInformation pageInfo = null;
if (response.getNextPageToken() != null) {
pageInfo = new StringPaginationToken(response.getNextPageToken());
}
// TODO: export by label or by message?
return new MailModelWrapper(null, results, new ContinuationInformation(null, pageInfo));
}
use of org.dataportabilityproject.shared.StringPaginationToken in project data-transfer-project by google.
the class GoogleTaskService method getTasks.
private TaskModelWrapper getTasks(String taskListId, Optional<PaginationInformation> pageInfo) throws IOException {
com.google.api.services.tasks.model.Tasks result;
Tasks.TasksOperations.List query = taskClient.tasks().list(taskListId).setMaxResults(PAGE_SIZE);
if (pageInfo.isPresent()) {
query.setPageToken(((StringPaginationToken) pageInfo.get()).getId());
}
result = query.execute();
List<TaskModel> newTasks = result.getItems().stream().map(t -> new TaskModel(taskListId, t.getTitle(), t.getNotes())).collect(Collectors.toList());
PaginationInformation newPageInfo = null;
if (result.getNextPageToken() != null) {
newPageInfo = new StringPaginationToken(result.getNextPageToken());
}
return new TaskModelWrapper(null, newTasks, new ContinuationInformation(null, newPageInfo));
}
use of org.dataportabilityproject.shared.StringPaginationToken in project data-transfer-project by google.
the class GoogleCalendarServiceTest method testExportCalendarFirstSet.
@Test
public void testExportCalendarFirstSet() throws IOException {
setUpSingleCalendarResponse();
// Looking at first page, with at least one page after it
ExportInformation emptyExportInformation = new ExportInformation(Optional.empty(), Optional.empty());
calendarListResponse.setNextPageToken(NEXT_TOKEN);
// Run test
CalendarModelWrapper wrapper = calendarService.export(emptyExportInformation);
// Check results
// Verify correct methods were called
verify(calendarClient).calendarList();
verify(calendarCalendarList).list();
verify(calendarListRequest).execute();
// Check pagination token
StringPaginationToken paginationToken = (StringPaginationToken) wrapper.getContinuationInformation().getPaginationInformation();
assertThat(paginationToken.getId()).isEqualTo(NEXT_TOKEN);
// Check calendars
Collection<CalendarModel> calendars = wrapper.getCalendars();
assertThat(calendars.stream().map(CalendarModel::getId).collect(Collectors.toList())).containsExactly(CALENDAR_ID);
// Check events (should be empty, even though there is an event in the calendar)
Collection<CalendarEventModel> events = wrapper.getEvents();
assertThat(events).isEmpty();
// Should be one event in the resource list
Collection<? extends Resource> subResources = wrapper.getContinuationInformation().getSubResources();
assertThat(subResources.stream().map(a -> ((IdOnlyResource) a).getId()).collect(Collectors.toList())).containsExactly(CALENDAR_ID);
}
use of org.dataportabilityproject.shared.StringPaginationToken in project data-transfer-project by google.
the class GoogleContactsServiceTest method exportSubsequentPage.
@Test
public void exportSubsequentPage() throws IOException {
setUpSinglePersonResponse();
// Looking at a subsequent page, with no pages after it
ExportInformation nextPageExportInformation = new ExportInformation(Optional.empty(), Optional.of(new StringPaginationToken(NEXT_PAGE_TOKEN)));
listConnectionsResponse.setNextPageToken(null);
when(listConnectionsRequest.setPageToken(NEXT_PAGE_TOKEN)).thenReturn(listConnectionsRequest);
// Run test
ContactsModelWrapper wrapper = contactsService.export(nextPageExportInformation);
// Verify correct calls were made - i.e., token was added before execution
InOrder inOrder = Mockito.inOrder(listConnectionsRequest);
inOrder.verify(listConnectionsRequest).setPageToken(NEXT_PAGE_TOKEN);
inOrder.verify(listConnectionsRequest).execute();
// Check continuation information
assertThat(wrapper.getContinuationInformation()).isNull();
}
Aggregations