use of com.google.api.client.util.DateTime in project data-transfer-project by google.
the class GoogleTasksImporter method importItem.
@Override
public ImportResult importItem(UUID jobId, IdempotentImportExecutor idempotentImportExecutor, TokensAndUrlAuthData authData, TaskContainerResource data) throws Exception {
Tasks tasksService = getOrCreateTasksService(authData);
for (TaskListModel oldTasksList : data.getLists()) {
TaskList newTaskList = new TaskList().setTitle("Imported copy - " + oldTasksList.getName());
idempotentImportExecutor.executeAndSwallowIOExceptions(oldTasksList.getId(), oldTasksList.getName(), () -> tasksService.tasklists().insert(newTaskList).execute().getId());
}
for (TaskModel oldTask : data.getTasks()) {
Task newTask = new Task().setTitle(oldTask.getText()).setNotes(oldTask.getNotes());
if (oldTask.getCompletedTime() != null) {
newTask.setCompleted(new DateTime(oldTask.getCompletedTime().toEpochMilli()));
}
if (oldTask.getDueTime() != null) {
newTask.setDue(new DateTime(oldTask.getDueTime().toEpochMilli()));
}
// If its not cached that means the task list create failed.
if (idempotentImportExecutor.isKeyCached(oldTask.getTaskListId())) {
String newTaskListId = idempotentImportExecutor.getCachedValue(oldTask.getTaskListId());
idempotentImportExecutor.executeAndSwallowIOExceptions(oldTask.getTaskListId() + oldTask.getText(), oldTask.getText(), () -> tasksService.tasks().insert(newTaskListId, newTask).execute().getId());
}
}
return new ImportResult(ResultType.OK);
}
Aggregations