use of org.dataportabilityproject.spi.transfer.types.TempTasksData 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);
}
Aggregations