use of org.datatransferproject.types.common.models.tasks.TaskModel 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);
}
use of org.datatransferproject.types.common.models.tasks.TaskModel in project data-transfer-project by google.
the class GoogleTasksExporter method getTasks.
private ExportResult<TaskContainerResource> getTasks(Tasks tasksService, IdOnlyContainerResource resource, Optional<PaginationData> paginationData) throws IOException {
Tasks.TasksOperations.List query = tasksService.tasks().list(resource.getId()).setMaxResults(PAGE_SIZE);
if (paginationData.isPresent()) {
query.setPageToken(((StringPaginationToken) paginationData.get()).getToken());
}
com.google.api.services.tasks.model.Tasks result = query.execute();
List<TaskModel> newTasks = result.getItems().stream().map(t -> new TaskModel(resource.getId(), t.getTitle(), t.getNotes(), t.getCompleted() != null ? Instant.ofEpochMilli(t.getCompleted().getValue()) : null, t.getDue() != null ? Instant.ofEpochMilli(t.getDue().getValue()) : null)).collect(Collectors.toList());
PaginationData newPage = null;
ResultType resultType = ResultType.END;
if (result.getNextPageToken() != null) {
newPage = new StringPaginationToken(result.getNextPageToken());
resultType = ResultType.CONTINUE;
}
TaskContainerResource taskContainerResource = new TaskContainerResource(null, newTasks);
return new ExportResult<>(resultType, taskContainerResource, new ContinuationData(newPage));
}
use of org.datatransferproject.types.common.models.tasks.TaskModel in project data-transfer-project by google.
the class TaskContainerResourceTest method verifySerializeDeserialize.
@Test
public void verifySerializeDeserialize() throws Exception {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
objectMapper.registerSubtypes(TaskContainerResource.class);
List<TaskListModel> taskLists = ImmutableList.of(new TaskListModel("id1", "List 1"));
List<TaskModel> tasks = ImmutableList.of(new TaskModel("id1", "Write Better tests", "Do this soon", null, null), new TaskModel("id2", "Liberate all the data", "do this in stages", null, null));
ContainerResource data = new TaskContainerResource(taskLists, tasks);
String serialized = objectMapper.writeValueAsString(data);
ContainerResource deserializedModel = objectMapper.readValue(serialized, ContainerResource.class);
Truth.assertThat(deserializedModel).isNotNull();
Truth.assertThat(deserializedModel).isInstanceOf(TaskContainerResource.class);
TaskContainerResource deserialized = (TaskContainerResource) deserializedModel;
Truth.assertThat(deserialized.getLists()).hasSize(1);
Truth.assertThat(deserialized.getTasks()).hasSize(2);
Truth.assertThat(deserialized).isEqualTo(data);
}
use of org.datatransferproject.types.common.models.tasks.TaskModel in project data-transfer-project by google.
the class RememberTheMilkTasksImporter method importItem.
@Override
public ImportResult importItem(UUID jobId, IdempotentImportExecutor idempotentExecutor, AuthData authData, TaskContainerResource data) {
String timeline;
try {
RememberTheMilkService service = getOrCreateService(authData);
timeline = service.createTimeline();
for (TaskListModel taskList : data.getLists()) {
idempotentExecutor.executeAndSwallowIOExceptions(taskList.getId(), taskList.getName(), () -> service.createTaskList(taskList.getName(), timeline).id);
}
for (TaskModel task : data.getTasks()) {
// Empty or blank tasks aren't valid in RTM
if (!Strings.isNullOrEmpty(task.getText())) {
idempotentExecutor.executeAndSwallowIOExceptions(Integer.toString(task.hashCode()), task.getText(), () -> {
String newList = idempotentExecutor.getCachedValue(task.getTaskListId());
return insertTask(task, newList, timeline);
});
}
}
} catch (Exception e) {
monitor.severe(() -> "Error importing item", e);
return new ImportResult(e);
}
return new ImportResult(ImportResult.ResultType.OK);
}
use of org.datatransferproject.types.common.models.tasks.TaskModel 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