Search in sources :

Example 1 with TaskContainerResource

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

the class RememberTheMilkTasksExporter method exportTask.

private ExportResult exportTask(RememberTheMilkService service, IdOnlyContainerResource resource) {
    String oldListId = resource.getId();
    GetListResponse oldList = null;
    try {
        oldList = service.getList(oldListId);
    } catch (IOException e) {
        return new ExportResult(e);
    }
    List<TaskList> taskLists = oldList.tasks.list;
    List<TaskModel> tasks = new ArrayList<>();
    for (TaskList taskList : taskLists) {
        if (taskList.taskseries != null) {
            for (TaskSeries taskSeries : taskList.taskseries) {
                // TODO: figure out what to do with notes
                String notesStr = taskSeries.notes == null ? "" : taskSeries.notes.toString();
                for (Task task : taskSeries.tasks) {
                    // TODO: How to handle case with multiple tasks in a series?  Is this good enough?
                    Instant completedTime = null;
                    Instant dueTime = null;
                    if (task.completed != null && !Strings.isNullOrEmpty(task.completed)) {
                        completedTime = Instant.parse(task.completed);
                    }
                    if (task.due != null && !Strings.isNullOrEmpty(task.due)) {
                        dueTime = Instant.parse(task.due);
                    }
                    tasks.add(new TaskModel(oldListId, taskSeries.name, notesStr, completedTime, dueTime));
                }
            }
        }
    }
    TaskContainerResource taskContainerResource = new TaskContainerResource(null, tasks);
    // TODO: what do we do with pagination data?
    return new ExportResult(ResultType.CONTINUE, taskContainerResource, null);
}
Also used : GetListResponse(org.datatransferproject.transfer.rememberthemilk.model.tasks.GetListResponse) Task(org.datatransferproject.transfer.rememberthemilk.model.tasks.Task) TaskList(org.datatransferproject.transfer.rememberthemilk.model.tasks.TaskList) Instant(java.time.Instant) ArrayList(java.util.ArrayList) IOException(java.io.IOException) TaskContainerResource(org.datatransferproject.types.common.models.tasks.TaskContainerResource) TaskSeries(org.datatransferproject.transfer.rememberthemilk.model.tasks.TaskSeries) TaskModel(org.datatransferproject.types.common.models.tasks.TaskModel) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult)

Example 2 with TaskContainerResource

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

the class RememberTheMilkTasksExporter method exportTaskList.

private ExportResult exportTaskList(RememberTheMilkService service) {
    List<TaskListModel> lists = new ArrayList<>();
    List<IdOnlyContainerResource> subResources = new ArrayList<>();
    List<ListInfo> listInfoList;
    try {
        listInfoList = service.getLists().lists;
    } catch (IOException e) {
        return new ExportResult(e);
    }
    for (ListInfo oldListInfo : listInfoList) {
        if (oldListInfo.name.equals("All Tasks")) {
            // All Tasks is a special list that contains everything, don't copy that over
            continue;
        }
        lists.add(new TaskListModel(Integer.toString(oldListInfo.id), oldListInfo.name));
        subResources.add(new IdOnlyContainerResource(Integer.toString(oldListInfo.id)));
    }
    TaskContainerResource taskContainerResource = new TaskContainerResource(lists, null);
    ContinuationData continuationData = new ContinuationData(null);
    subResources.forEach(continuationData::addContainerResource);
    // TODO: what do we do with pagination data?
    return new ExportResult(ResultType.CONTINUE, taskContainerResource, continuationData);
}
Also used : ListInfo(org.datatransferproject.transfer.rememberthemilk.model.tasks.ListInfo) ArrayList(java.util.ArrayList) IdOnlyContainerResource(org.datatransferproject.types.common.models.IdOnlyContainerResource) ContinuationData(org.datatransferproject.spi.transfer.types.ContinuationData) IOException(java.io.IOException) TaskContainerResource(org.datatransferproject.types.common.models.tasks.TaskContainerResource) TaskListModel(org.datatransferproject.types.common.models.tasks.TaskListModel) ExportResult(org.datatransferproject.spi.transfer.provider.ExportResult)

Example 3 with TaskContainerResource

use of org.datatransferproject.types.common.models.tasks.TaskContainerResource 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 4 with TaskContainerResource

use of org.datatransferproject.types.common.models.tasks.TaskContainerResource 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 5 with TaskContainerResource

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

the class TaskContainerResourceTest method verifySerializeDeserialize.

@Test
public void verifySerializeDeserialize() throws Exception {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.registerModule(new JavaTimeModule());
    objectMapper.registerSubtypes(TaskContainerResource.class);
    List<TaskListModel> taskLists = ImmutableList.of(new TaskListModel("id1", "List 1"));
    List<TaskModel> tasks = ImmutableList.of(new TaskModel("id1", "Write Better tests", "Do this soon", null, null), new TaskModel("id2", "Liberate all the data", "do this in stages", null, null));
    ContainerResource data = new TaskContainerResource(taskLists, tasks);
    String serialized = objectMapper.writeValueAsString(data);
    ContainerResource deserializedModel = objectMapper.readValue(serialized, ContainerResource.class);
    Truth.assertThat(deserializedModel).isNotNull();
    Truth.assertThat(deserializedModel).isInstanceOf(TaskContainerResource.class);
    TaskContainerResource deserialized = (TaskContainerResource) deserializedModel;
    Truth.assertThat(deserialized.getLists()).hasSize(1);
    Truth.assertThat(deserialized.getTasks()).hasSize(2);
    Truth.assertThat(deserialized).isEqualTo(data);
}
Also used : TaskContainerResource(org.datatransferproject.types.common.models.tasks.TaskContainerResource) ContainerResource(org.datatransferproject.types.common.models.ContainerResource) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) TaskContainerResource(org.datatransferproject.types.common.models.tasks.TaskContainerResource) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TaskListModel(org.datatransferproject.types.common.models.tasks.TaskListModel) TaskModel(org.datatransferproject.types.common.models.tasks.TaskModel) Test(org.junit.Test)

Aggregations

TaskContainerResource (org.datatransferproject.types.common.models.tasks.TaskContainerResource)5 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)4 TaskListModel (org.datatransferproject.types.common.models.tasks.TaskListModel)4 IOException (java.io.IOException)3 ContinuationData (org.datatransferproject.spi.transfer.types.ContinuationData)3 IdOnlyContainerResource (org.datatransferproject.types.common.models.IdOnlyContainerResource)3 TaskModel (org.datatransferproject.types.common.models.tasks.TaskModel)3 TaskList (com.google.api.services.tasks.model.TaskList)2 TaskLists (com.google.api.services.tasks.model.TaskLists)2 ImmutableList (com.google.common.collect.ImmutableList)2 Instant (java.time.Instant)2 ArrayList (java.util.ArrayList)2 ResultType (org.datatransferproject.spi.transfer.provider.ExportResult.ResultType)2 PaginationData (org.datatransferproject.types.common.PaginationData)2 StringPaginationToken (org.datatransferproject.types.common.StringPaginationToken)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)1 Credential (com.google.api.client.auth.oauth2.Credential)1 Tasks (com.google.api.services.tasks.Tasks)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1