Search in sources :

Example 1 with Task

use of org.datatransferproject.transfer.rememberthemilk.model.tasks.Task 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)

Aggregations

IOException (java.io.IOException)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 ExportResult (org.datatransferproject.spi.transfer.provider.ExportResult)1 GetListResponse (org.datatransferproject.transfer.rememberthemilk.model.tasks.GetListResponse)1 Task (org.datatransferproject.transfer.rememberthemilk.model.tasks.Task)1 TaskList (org.datatransferproject.transfer.rememberthemilk.model.tasks.TaskList)1 TaskSeries (org.datatransferproject.transfer.rememberthemilk.model.tasks.TaskSeries)1 TaskContainerResource (org.datatransferproject.types.common.models.tasks.TaskContainerResource)1 TaskModel (org.datatransferproject.types.common.models.tasks.TaskModel)1