Search in sources :

Example 1 with TaskModel

use of org.dataportabilityproject.dataModels.tasks.TaskModel in project data-transfer-project by google.

the class GoogleTaskService method getTasks.

private TaskModelWrapper getTasks(String taskListId, Optional<PaginationInformation> pageInfo) throws IOException {
    com.google.api.services.tasks.model.Tasks result;
    Tasks.TasksOperations.List query = taskClient.tasks().list(taskListId).setMaxResults(PAGE_SIZE);
    if (pageInfo.isPresent()) {
        query.setPageToken(((StringPaginationToken) pageInfo.get()).getId());
    }
    result = query.execute();
    List<TaskModel> newTasks = result.getItems().stream().map(t -> new TaskModel(taskListId, t.getTitle(), t.getNotes())).collect(Collectors.toList());
    PaginationInformation newPageInfo = null;
    if (result.getNextPageToken() != null) {
        newPageInfo = new StringPaginationToken(result.getNextPageToken());
    }
    return new TaskModelWrapper(null, newTasks, new ContinuationInformation(null, newPageInfo));
}
Also used : Importer(org.dataportabilityproject.dataModels.Importer) Resource(org.dataportabilityproject.dataModels.Resource) ExportInformation(org.dataportabilityproject.dataModels.ExportInformation) IOException(java.io.IOException) IdOnlyResource(org.dataportabilityproject.shared.IdOnlyResource) Tasks(com.google.api.services.tasks.Tasks) TaskModel(org.dataportabilityproject.dataModels.tasks.TaskModel) Collectors(java.util.stream.Collectors) TaskModelWrapper(org.dataportabilityproject.dataModels.tasks.TaskModelWrapper) Task(com.google.api.services.tasks.model.Task) ArrayList(java.util.ArrayList) Exporter(org.dataportabilityproject.dataModels.Exporter) List(java.util.List) TaskList(com.google.api.services.tasks.model.TaskList) PaginationInformation(org.dataportabilityproject.dataModels.PaginationInformation) JobDataCache(org.dataportabilityproject.cloud.interfaces.JobDataCache) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) Optional(java.util.Optional) Credential(com.google.api.client.auth.oauth2.Credential) TaskLists(com.google.api.services.tasks.model.TaskLists) GoogleStaticObjects(org.dataportabilityproject.serviceProviders.google.GoogleStaticObjects) TaskListModel(org.dataportabilityproject.dataModels.tasks.TaskListModel) StringPaginationToken(org.dataportabilityproject.shared.StringPaginationToken) TaskModelWrapper(org.dataportabilityproject.dataModels.tasks.TaskModelWrapper) ContinuationInformation(org.dataportabilityproject.dataModels.ContinuationInformation) TaskModel(org.dataportabilityproject.dataModels.tasks.TaskModel) PaginationInformation(org.dataportabilityproject.dataModels.PaginationInformation) StringPaginationToken(org.dataportabilityproject.shared.StringPaginationToken)

Example 2 with TaskModel

use of org.dataportabilityproject.dataModels.tasks.TaskModel in project data-transfer-project by google.

the class RememberTheMilkTaskService method exportTaskList.

private TaskModelWrapper exportTaskList(Resource resource, Optional<PaginationInformation> paginationInformation) throws IOException {
    int oldListId = Integer.parseInt(((IdOnlyResource) resource).getId());
    GetListResponse oldList = getList(oldListId);
    List<TaskList> taskLists = oldList.tasks.list;
    List<TaskModel> tasks = new ArrayList<>();
    for (TaskList taskList : taskLists) {
        if (taskList.taskSeriesList != null) {
            for (TaskSeries taskSeries : taskList.taskSeriesList) {
                tasks.add(new TaskModel(Integer.toString(oldListId), taskSeries.name, taskSeries.notes.toString()));
                for (Task task : taskSeries.tasks) {
                // Do something here with completion date, but its odd there can be more than one.
                }
            }
        }
    }
    return new TaskModelWrapper(null, tasks, null);
}
Also used : GetListResponse(org.dataportabilityproject.serviceProviders.rememberTheMilk.model.GetListResponse) TaskModelWrapper(org.dataportabilityproject.dataModels.tasks.TaskModelWrapper) Task(org.dataportabilityproject.serviceProviders.rememberTheMilk.model.Task) TaskList(org.dataportabilityproject.serviceProviders.rememberTheMilk.model.TaskList) ArrayList(java.util.ArrayList) TaskSeries(org.dataportabilityproject.serviceProviders.rememberTheMilk.model.TaskSeries) TaskModel(org.dataportabilityproject.dataModels.tasks.TaskModel)

Example 3 with TaskModel

use of org.dataportabilityproject.dataModels.tasks.TaskModel in project data-transfer-project by google.

the class RememberTheMilkTaskService method importItem.

@Override
public void importItem(TaskModelWrapper wrapper) throws IOException {
    String timeline = createTimeline();
    for (TaskListModel taskList : wrapper.getLists()) {
        ListInfo listInfo = createTaskList(taskList.getName(), timeline);
        jobDataCache.store(taskList.getId(), listInfo.id);
    }
    for (TaskModel task : wrapper.getTasks()) {
        int newList = jobDataCache.getData(task.getTaskListId(), Integer.class);
        TaskSeries addedTask = createTask(task.getText(), timeline, newList);
    // TODO add note here
    }
}
Also used : ListInfo(org.dataportabilityproject.serviceProviders.rememberTheMilk.model.ListInfo) TaskSeries(org.dataportabilityproject.serviceProviders.rememberTheMilk.model.TaskSeries) TaskListModel(org.dataportabilityproject.dataModels.tasks.TaskListModel) TaskModel(org.dataportabilityproject.dataModels.tasks.TaskModel)

Example 4 with TaskModel

use of org.dataportabilityproject.dataModels.tasks.TaskModel in project data-transfer-project by google.

the class GoogleTaskService method importItem.

@Override
public void importItem(TaskModelWrapper wrapper) throws IOException {
    for (TaskListModel taskList : wrapper.getLists()) {
        TaskList newTaskList = new TaskList().setTitle("Imported copy - " + taskList.getName());
        TaskList insertedTaskList = taskClient.tasklists().insert(newTaskList).execute();
        System.out.println("Storing " + taskList.getId() + " as " + insertedTaskList.getId());
        jobDataCache.store(taskList.getId(), insertedTaskList.getId());
    }
    for (TaskModel oldTask : wrapper.getTasks()) {
        Task newTask = new Task().setTitle(oldTask.getText()).setNotes(oldTask.getNotes());
        String newTaskId = jobDataCache.getData(oldTask.getTaskListId(), String.class);
        taskClient.tasks().insert(newTaskId, newTask).execute();
    }
}
Also used : Task(com.google.api.services.tasks.model.Task) TaskList(com.google.api.services.tasks.model.TaskList) TaskListModel(org.dataportabilityproject.dataModels.tasks.TaskListModel) TaskModel(org.dataportabilityproject.dataModels.tasks.TaskModel)

Aggregations

TaskModel (org.dataportabilityproject.dataModels.tasks.TaskModel)4 TaskListModel (org.dataportabilityproject.dataModels.tasks.TaskListModel)3 Task (com.google.api.services.tasks.model.Task)2 TaskList (com.google.api.services.tasks.model.TaskList)2 ArrayList (java.util.ArrayList)2 TaskModelWrapper (org.dataportabilityproject.dataModels.tasks.TaskModelWrapper)2 TaskSeries (org.dataportabilityproject.serviceProviders.rememberTheMilk.model.TaskSeries)2 Credential (com.google.api.client.auth.oauth2.Credential)1 Tasks (com.google.api.services.tasks.Tasks)1 TaskLists (com.google.api.services.tasks.model.TaskLists)1 IOException (java.io.IOException)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 JobDataCache (org.dataportabilityproject.cloud.interfaces.JobDataCache)1 ContinuationInformation (org.dataportabilityproject.dataModels.ContinuationInformation)1 ExportInformation (org.dataportabilityproject.dataModels.ExportInformation)1 Exporter (org.dataportabilityproject.dataModels.Exporter)1 Importer (org.dataportabilityproject.dataModels.Importer)1 PaginationInformation (org.dataportabilityproject.dataModels.PaginationInformation)1