use of org.datatransferproject.types.common.PaginationData 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.PaginationData 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.PaginationData in project data-transfer-project by google.
the class GoogleTasksExporter method export.
@Override
public ExportResult<TaskContainerResource> export(UUID jobId, TokensAndUrlAuthData authData, Optional<ExportInformation> exportInformation) {
// Create a new tasks service for the authorized user
Tasks tasksService = getOrCreateTasksService(authData);
IdOnlyContainerResource resource = exportInformation.isPresent() ? (IdOnlyContainerResource) exportInformation.get().getContainerResource() : null;
PaginationData paginationData = exportInformation.isPresent() ? exportInformation.get().getPaginationData() : null;
try {
if (resource != null) {
return getTasks(tasksService, resource, Optional.ofNullable(paginationData));
} else {
return getTasksList(tasksService, Optional.ofNullable(paginationData));
}
} catch (Exception e) {
monitor.severe(() -> "Error occurred trying to retrieve task", e);
return new ExportResult<>(e);
}
}
use of org.datatransferproject.types.common.PaginationData 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.PaginationData 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();
}
Aggregations