Search in sources :

Example 11 with IdOnlyContainerResource

use of org.datatransferproject.types.common.models.IdOnlyContainerResource 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 IdOnlyContainerResource

use of org.datatransferproject.types.common.models.IdOnlyContainerResource 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 IdOnlyContainerResource

use of org.datatransferproject.types.common.models.IdOnlyContainerResource 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);
    }
}
Also used : Tasks(com.google.api.services.tasks.Tasks) PaginationData(org.datatransferproject.types.common.PaginationData) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) IOException(java.io.IOException)

Example 14 with IdOnlyContainerResource

use of org.datatransferproject.types.common.models.IdOnlyContainerResource 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 15 with IdOnlyContainerResource

use of org.datatransferproject.types.common.models.IdOnlyContainerResource in project data-transfer-project by google.

the class FacebookPhotosExporterTest method testExportAlbum.

@Test
public void testExportAlbum() throws CopyExceptionWithFailureReason {
    ExportResult<PhotosContainerResource> result = facebookPhotosExporter.export(uuid, new TokensAndUrlAuthData("accessToken", null, null), Optional.empty());
    assertEquals(ExportResult.ResultType.CONTINUE, result.getType());
    PhotosContainerResource exportedData = result.getExportedData();
    assertEquals(1, exportedData.getAlbums().size());
    assertEquals(new PhotoAlbum(ALBUM_ID, ALBUM_NAME, ALBUM_DESCRIPTION), exportedData.getAlbums().toArray()[0]);
    assertNull(result.getContinuationData().getPaginationData());
    assertThat(result.getContinuationData().getContainerResources()).contains(new IdOnlyContainerResource(ALBUM_ID));
}
Also used : PhotosContainerResource(org.datatransferproject.types.common.models.photos.PhotosContainerResource) TokensAndUrlAuthData(org.datatransferproject.types.transfer.auth.TokensAndUrlAuthData) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) PhotoAlbum(org.datatransferproject.types.common.models.photos.PhotoAlbum) Test(org.junit.Test)

Aggregations

IdOnlyContainerResource (org.datatransferproject.types.common.models.IdOnlyContainerResource)43 PhotosContainerResource (org.datatransferproject.types.common.models.photos.PhotosContainerResource)29 ContinuationData (org.datatransferproject.spi.transfer.types.ContinuationData)27 StringPaginationToken (org.datatransferproject.types.common.StringPaginationToken)23 Test (org.junit.Test)21 PhotoAlbum (org.datatransferproject.types.common.models.photos.PhotoAlbum)20 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)18 PaginationData (org.datatransferproject.types.common.PaginationData)17 ArrayList (java.util.ArrayList)12 ExportInformation (org.datatransferproject.types.common.ExportInformation)12 PhotoModel (org.datatransferproject.types.common.models.photos.PhotoModel)12 IOException (java.io.IOException)11 ContainerResource (org.datatransferproject.types.common.models.ContainerResource)10 ImmutableList (com.google.common.collect.ImmutableList)7 List (java.util.List)7 Optional (java.util.Optional)7 UUID (java.util.UUID)7 Collectors (java.util.stream.Collectors)7 ResultType (org.datatransferproject.spi.transfer.provider.ExportResult.ResultType)7 IntPaginationToken (org.datatransferproject.types.common.IntPaginationToken)7