use of org.datatransferproject.types.common.StringPaginationToken in project data-transfer-project by google.
the class GoogleCalendarExporterTest method exportEventSubsequentSet.
@Test
public void exportEventSubsequentSet() throws IOException {
setUpSingleEventResponse();
// Looking at subsequent page, with no pages after it
ContainerResource containerResource = new IdOnlyContainerResource(CALENDAR_ID);
PaginationData paginationData = new StringPaginationToken(EVENT_TOKEN_PREFIX + NEXT_TOKEN);
ExportInformation exportInformation = new ExportInformation(paginationData, containerResource);
eventListResponse.setNextPageToken(null);
// Run test
ExportResult<CalendarContainerResource> result = googleCalendarExporter.export(UUID.randomUUID(), null, Optional.of(exportInformation));
// Check results
// Verify correct methods were called in order
InOrder inOrder = Mockito.inOrder(eventListRequest);
inOrder.verify(eventListRequest).setPageToken(NEXT_TOKEN);
inOrder.verify(eventListRequest).execute();
// Check pagination token
ContinuationData continuationData = (ContinuationData) result.getContinuationData();
StringPaginationToken paginationToken = (StringPaginationToken) continuationData.getPaginationData();
assertThat(paginationToken).isNull();
}
use of org.datatransferproject.types.common.StringPaginationToken in project data-transfer-project by google.
the class GoogleTasksExporter method getTasks.
private ExportResult<TaskContainerResource> getTasks(Tasks tasksService, IdOnlyContainerResource resource, Optional<PaginationData> paginationData) throws IOException {
Tasks.TasksOperations.List query = tasksService.tasks().list(resource.getId()).setMaxResults(PAGE_SIZE);
if (paginationData.isPresent()) {
query.setPageToken(((StringPaginationToken) paginationData.get()).getToken());
}
com.google.api.services.tasks.model.Tasks result = query.execute();
List<TaskModel> newTasks = result.getItems().stream().map(t -> new TaskModel(resource.getId(), t.getTitle(), t.getNotes(), t.getCompleted() != null ? Instant.ofEpochMilli(t.getCompleted().getValue()) : null, t.getDue() != null ? Instant.ofEpochMilli(t.getDue().getValue()) : null)).collect(Collectors.toList());
PaginationData newPage = null;
ResultType resultType = ResultType.END;
if (result.getNextPageToken() != null) {
newPage = new StringPaginationToken(result.getNextPageToken());
resultType = ResultType.CONTINUE;
}
TaskContainerResource taskContainerResource = new TaskContainerResource(null, newTasks);
return new ExportResult<>(resultType, taskContainerResource, new ContinuationData(newPage));
}
use of org.datatransferproject.types.common.StringPaginationToken in project data-transfer-project by google.
the class GoogleTasksExporter method getTasksList.
private ExportResult<TaskContainerResource> getTasksList(Tasks tasksService, Optional<PaginationData> paginationData) throws IOException {
Tasks.Tasklists.List query = tasksService.tasklists().list().setMaxResults(PAGE_SIZE);
if (paginationData.isPresent()) {
query.setPageToken(((StringPaginationToken) paginationData.get()).getToken());
}
TaskLists result = query.execute();
ImmutableList.Builder<TaskListModel> newTaskListsBuilder = ImmutableList.builder();
ImmutableList.Builder<IdOnlyContainerResource> newResourcesBuilder = ImmutableList.builder();
for (TaskList taskList : result.getItems()) {
newTaskListsBuilder.add(new TaskListModel(taskList.getId(), taskList.getTitle()));
newResourcesBuilder.add(new IdOnlyContainerResource(taskList.getId()));
}
PaginationData newPage = null;
ResultType resultType = ResultType.END;
if (result.getNextPageToken() != null) {
newPage = new StringPaginationToken(result.getNextPageToken());
resultType = ResultType.CONTINUE;
}
List<IdOnlyContainerResource> newResources = newResourcesBuilder.build();
if (!newResources.isEmpty()) {
resultType = ResultType.CONTINUE;
}
TaskContainerResource taskContainerResource = new TaskContainerResource(newTaskListsBuilder.build(), null);
ContinuationData continuationData = new ContinuationData(newPage);
newResourcesBuilder.build().forEach(continuationData::addContainerResource);
return new ExportResult<>(resultType, taskContainerResource, continuationData);
}
use of org.datatransferproject.types.common.StringPaginationToken in project data-transfer-project by google.
the class GoogleContactsExporterTest method exportSubsequentPage.
@Test
public void exportSubsequentPage() throws IOException {
setUpSinglePersonResponse();
// Looking at a subsequent page, with no pages after it
PaginationData paginationData = new StringPaginationToken(NEXT_PAGE_TOKEN);
ExportInformation exportInformation = new ExportInformation(paginationData, null);
listConnectionsResponse.setNextPageToken(null);
when(listConnectionsRequest.setPageToken(NEXT_PAGE_TOKEN)).thenReturn(listConnectionsRequest);
// Run test
ExportResult<ContactsModelWrapper> result = contactsService.export(UUID.randomUUID(), null, Optional.of(exportInformation));
// 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 data
ContinuationData continuationData = (ContinuationData) result.getContinuationData();
assertThat(continuationData.getContainerResources()).isEmpty();
assertThat(continuationData.getPaginationData()).isNull();
}
use of org.datatransferproject.types.common.StringPaginationToken in project data-transfer-project by google.
the class GoogleContactsExporterTest method exportFirstPage.
@Test
public void exportFirstPage() throws IOException {
setUpSinglePersonResponse();
// Looking at first page, with at least one page after it
listConnectionsResponse.setNextPageToken(NEXT_PAGE_TOKEN);
ExportResult<ContactsModelWrapper> result = contactsService.export(UUID.randomUUID(), null, Optional.empty());
// Check that correct methods were called
verify(connections).list(SELF_RESOURCE);
InOrder inOrder = Mockito.inOrder(getBatchGet);
inOrder.verify(getBatchGet).setResourceNames(Collections.singletonList(RESOURCE_NAME));
inOrder.verify(getBatchGet).setPersonFields(PERSON_FIELDS);
inOrder.verify(getBatchGet).execute();
// Check continuation data
ContinuationData continuationData = (ContinuationData) result.getContinuationData();
assertThat(continuationData.getContainerResources()).isEmpty();
StringPaginationToken paginationToken = (StringPaginationToken) ((ContinuationData) result.getContinuationData()).getPaginationData();
assertThat(paginationToken.getToken()).isEqualTo(NEXT_PAGE_TOKEN);
// Check that the right number of VCards was returned
JCardReader reader = new JCardReader(result.getExportedData().getVCards());
List<VCard> vCardList = reader.readAll();
assertThat(vCardList.size()).isEqualTo(connectionsList.size());
}
Aggregations