Search in sources :

Example 1 with TaskListModel

use of org.dataportabilityproject.types.transfer.models.tasks.TaskListModel in project data-transfer-project by google.

the class GoogleTasksImporter method importItem.

@Override
public ImportResult importItem(UUID jobId, TokensAndUrlAuthData authData, TaskContainerResource data) {
    Tasks tasksService = getOrCreateTasksService(authData);
    TempTasksData tempTasksData = jobStore.findData(TempTasksData.class, jobId);
    if (tempTasksData == null) {
        tempTasksData = new TempTasksData(jobId.toString());
        jobStore.create(jobId, tempTasksData);
    }
    for (TaskListModel oldTasksList : data.getLists()) {
        // TempTasksData shouldn't be null since we added it.
        tempTasksData = jobStore.findData(TempTasksData.class, jobId);
        TaskList newTaskList = new TaskList().setTitle("Imported copy - " + oldTasksList.getName());
        TaskList insertedTaskList;
        try {
            insertedTaskList = tasksService.tasklists().insert(newTaskList).execute();
        } catch (IOException e) {
            return new ImportResult(ResultType.ERROR, "Error inserting taskList: " + e.getMessage());
        }
        logger.info("Storing {} as {}", oldTasksList.getId(), insertedTaskList.getId());
        tempTasksData.addTaskListId(oldTasksList.getId(), insertedTaskList.getId());
        jobStore.update(jobId, tempTasksData);
    }
    tempTasksData = jobStore.findData(TempTasksData.class, jobId);
    for (TaskModel oldTask : data.getTasks()) {
        Task newTask = new Task().setTitle(oldTask.getText()).setNotes(oldTask.getNotes());
        String newTaskId = tempTasksData.lookupNewTaskListId(newTask.getId());
        try {
            tasksService.tasks().insert(newTaskId, newTask).execute();
        } catch (IOException e) {
            return new ImportResult(ResultType.ERROR, "Error inserting task: " + e.getMessage());
        }
    }
    return new ImportResult(ResultType.OK);
}
Also used : TempTasksData(org.dataportabilityproject.spi.transfer.types.TempTasksData) Task(com.google.api.services.tasks.model.Task) Tasks(com.google.api.services.tasks.Tasks) ImportResult(org.dataportabilityproject.spi.transfer.provider.ImportResult) TaskList(com.google.api.services.tasks.model.TaskList) IOException(java.io.IOException) TaskListModel(org.dataportabilityproject.types.transfer.models.tasks.TaskListModel) TaskModel(org.dataportabilityproject.types.transfer.models.tasks.TaskModel)

Example 2 with TaskListModel

use of org.dataportabilityproject.types.transfer.models.tasks.TaskListModel in project data-transfer-project by google.

the class GoogleTasksExporter method getTasksList.

private ExportResult getTasksList(Tasks tasksSerivce, PaginationData paginationData) throws IOException {
    Tasks.Tasklists.List query = tasksSerivce.tasklists().list().setMaxResults(PAGE_SIZE);
    if (paginationData != null) {
        query.setPageToken(((StringPaginationToken) paginationData).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(resource -> continuationData.addContainerResource(resource));
    return new ExportResult<>(resultType, taskContainerResource, continuationData);
}
Also used : PaginationData(org.dataportabilityproject.spi.transfer.types.PaginationData) ImmutableList(com.google.common.collect.ImmutableList) TaskList(com.google.api.services.tasks.model.TaskList) ContinuationData(org.dataportabilityproject.spi.transfer.types.ContinuationData) ResultType(org.dataportabilityproject.spi.transfer.provider.ExportResult.ResultType) TaskContainerResource(org.dataportabilityproject.types.transfer.models.tasks.TaskContainerResource) IdOnlyContainerResource(org.dataportabilityproject.spi.transfer.types.IdOnlyContainerResource) TaskLists(com.google.api.services.tasks.model.TaskLists) TaskListModel(org.dataportabilityproject.types.transfer.models.tasks.TaskListModel) StringPaginationToken(org.dataportabilityproject.spi.transfer.types.StringPaginationToken) ExportResult(org.dataportabilityproject.spi.transfer.provider.ExportResult)

Aggregations

TaskList (com.google.api.services.tasks.model.TaskList)2 TaskListModel (org.dataportabilityproject.types.transfer.models.tasks.TaskListModel)2 Tasks (com.google.api.services.tasks.Tasks)1 Task (com.google.api.services.tasks.model.Task)1 TaskLists (com.google.api.services.tasks.model.TaskLists)1 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 ExportResult (org.dataportabilityproject.spi.transfer.provider.ExportResult)1 ResultType (org.dataportabilityproject.spi.transfer.provider.ExportResult.ResultType)1 ImportResult (org.dataportabilityproject.spi.transfer.provider.ImportResult)1 ContinuationData (org.dataportabilityproject.spi.transfer.types.ContinuationData)1 IdOnlyContainerResource (org.dataportabilityproject.spi.transfer.types.IdOnlyContainerResource)1 PaginationData (org.dataportabilityproject.spi.transfer.types.PaginationData)1 StringPaginationToken (org.dataportabilityproject.spi.transfer.types.StringPaginationToken)1 TempTasksData (org.dataportabilityproject.spi.transfer.types.TempTasksData)1 TaskContainerResource (org.dataportabilityproject.types.transfer.models.tasks.TaskContainerResource)1 TaskModel (org.dataportabilityproject.types.transfer.models.tasks.TaskModel)1