Search in sources :

Example 11 with StringPaginationToken

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();
}
Also used : ExportInformation(org.datatransferproject.types.common.ExportInformation) PaginationData(org.datatransferproject.types.common.PaginationData) InOrder(org.mockito.InOrder) CalendarContainerResource(org.datatransferproject.types.common.models.calendar.CalendarContainerResource) ContainerResource(org.datatransferproject.types.common.models.ContainerResource) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) CalendarContainerResource(org.datatransferproject.types.common.models.calendar.CalendarContainerResource) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) Test(org.junit.Test)

Example 12 with StringPaginationToken

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));
}
Also used : ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult) GoogleStaticObjects(org.datatransferproject.datatransfer.google.common.GoogleStaticObjects) ExportInformation(org.datatransferproject.types.common.ExportInformation) TaskContainerResource(org.datatransferproject.types.common.models.tasks.TaskContainerResource) ImmutableList(com.google.common.collect.ImmutableList) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) Credential(com.google.api.client.auth.oauth2.Credential) TaskLists(com.google.api.services.tasks.model.TaskLists) GoogleCredentialFactory(org.datatransferproject.datatransfer.google.common.GoogleCredentialFactory) TaskModel(org.datatransferproject.types.common.models.tasks.TaskModel) ResultType(org.datatransferproject.spi.transfer.provider.ExportResult.ResultType) Exporter(org.datatransferproject.spi.transfer.provider.Exporter) IOException(java.io.IOException) Tasks(com.google.api.services.tasks.Tasks) PaginationData(org.datatransferproject.types.common.PaginationData) UUID(java.util.UUID) Instant(java.time.Instant) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) Collectors(java.util.stream.Collectors) TaskListModel(org.datatransferproject.types.common.models.tasks.TaskListModel) List(java.util.List) TaskList(com.google.api.services.tasks.model.TaskList) Monitor(org.datatransferproject.api.launcher.Monitor) TokensAndUrlAuthData(org.datatransferproject.types.transfer.auth.TokensAndUrlAuthData) Optional(java.util.Optional) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) VisibleForTesting(com.google.common.annotations.VisibleForTesting) PaginationData(org.datatransferproject.types.common.PaginationData) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) ResultType(org.datatransferproject.spi.transfer.provider.ExportResult.ResultType) TaskContainerResource(org.datatransferproject.types.common.models.tasks.TaskContainerResource) TaskModel(org.datatransferproject.types.common.models.tasks.TaskModel) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult)

Example 13 with StringPaginationToken

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);
}
Also used : PaginationData(org.datatransferproject.types.common.PaginationData) ImmutableList(com.google.common.collect.ImmutableList) TaskList(com.google.api.services.tasks.model.TaskList) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) ResultType(org.datatransferproject.spi.transfer.provider.ExportResult.ResultType) TaskContainerResource(org.datatransferproject.types.common.models.tasks.TaskContainerResource) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) TaskLists(com.google.api.services.tasks.model.TaskLists) TaskListModel(org.datatransferproject.types.common.models.tasks.TaskListModel) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult)

Example 14 with StringPaginationToken

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();
}
Also used : ExportInformation(org.datatransferproject.types.common.ExportInformation) PaginationData(org.datatransferproject.types.common.PaginationData) InOrder(org.mockito.InOrder) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) ContactsModelWrapper(org.datatransferproject.types.common.models.contacts.ContactsModelWrapper) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) Test(org.junit.Test)

Example 15 with StringPaginationToken

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());
}
Also used : InOrder(org.mockito.InOrder) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) ContactsModelWrapper(org.datatransferproject.types.common.models.contacts.ContactsModelWrapper) JCardReader(ezvcard.io.json.JCardReader) VCard(ezvcard.VCard) StringPaginationToken(org.datatransferproject.types.common.StringPaginationToken) Test(org.junit.Test)

Aggregations

StringPaginationToken (org.datatransferproject.types.common.StringPaginationToken)41 ContinuationData (org.datatransferproject.spi.transfer.types.ContinuationData)36 IdOnlyContainerResource (org.datatransferproject.types.common.models.IdOnlyContainerResource)23 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)22 PaginationData (org.datatransferproject.types.common.PaginationData)20 Test (org.junit.Test)19 PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)18 IOException (java.io.IOException)15 ArrayList (java.util.ArrayList)13 ResultType (org.datatransferproject.spi.transfer.provider.ExportResult.ResultType)12 PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)12 ExportInformation (org.datatransferproject.types.common.ExportInformation)10 ContainerResource (org.datatransferproject.types.common.models.ContainerResource)10 PhotoModel (org.datatransferproject.types.common.models.photos.PhotoModel)10 List (java.util.List)7 Optional (java.util.Optional)7 UUID (java.util.UUID)7 Collectors (java.util.stream.Collectors)7 InOrder (org.mockito.InOrder)7 GoogleMediaItem (org.datatransferproject.datatransfer.google.mediaModels.GoogleMediaItem)6