diff --git a/api/src/com/todoroo/astrid/sync/SyncMetadataService.java b/api/src/com/todoroo/astrid/sync/SyncMetadataService.java index d270efb2a..265481e0f 100644 --- a/api/src/com/todoroo/astrid/sync/SyncMetadataService.java +++ b/api/src/com/todoroo/astrid/sync/SyncMetadataService.java @@ -128,7 +128,8 @@ abstract public class SyncMetadataService { * @param left * @param right * @param matchingRows - * @param both - if false, returns left join, if true, returns both join + * @param both - if false, returns rows no right row exists, if true, + * returns rows where both exist */ private static void joinRows(TodorooCursor left, TodorooCursor right, ArrayList matchingRows, diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/api/GtasksService.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/api/GtasksService.java index e8c1195d4..b5cdd8ea5 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/api/GtasksService.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/api/GtasksService.java @@ -61,11 +61,13 @@ public class GtasksService { if (e instanceof HttpResponseException) { HttpResponseException h = (HttpResponseException)e; if (h.response.statusCode == 401 || h.response.statusCode == 403) { + System.err.println("Encountered " + h.response.statusCode + " error"); token = GtasksTokenValidator.validateAuthToken(token); if (token != null) { accessProtectedResource.setAccessToken(token); } } else if (h.response.statusCode == 503) { // 503 errors are generally either 1) quota limit reached or 2) problems on Google's end + System.err.println("Encountered 503 error"); final Context context = ContextManager.getContext(); String message = context.getString(R.string.gtasks_error_backend); exceptionService.reportError(message, h); @@ -79,6 +81,10 @@ public class GtasksService { } } + private static void log(String method, Object result) { + System.err.println("QUERY: " + method + ", RESULT: " + result); + } + /** * A simple service query that will throw an exception if anything goes wrong. * Useful for checking if token needs revalidating or if there are network problems-- @@ -90,23 +96,27 @@ public class GtasksService { } public TaskLists allGtaskLists() throws IOException { - TaskLists toReturn; + TaskLists toReturn = null; try { toReturn = service.tasklists.list().execute(); } catch (IOException e) { handleException(e); toReturn = service.tasklists.list().execute(); + } finally { + log("All gtasks lists", toReturn); } return toReturn; } public TaskList getGtaskList(String id) throws IOException { - TaskList toReturn; + TaskList toReturn = null; try { toReturn = service.tasklists.get(id).execute(); } catch (IOException e) { handleException(e); toReturn = service.tasklists.get(id).execute(); + } finally { + log("Get gtask list, id: " + id, toReturn); } return toReturn; } @@ -114,23 +124,27 @@ public class GtasksService { public TaskList createGtaskList(String title) throws IOException { TaskList newList = new TaskList(); newList.title = title; - TaskList toReturn; + TaskList toReturn = null; try { toReturn = service.tasklists.insert(newList).execute(); } catch (IOException e) { handleException(e); toReturn = service.tasklists.insert(newList).execute(); + } finally { + log("Create gtask list, title: " + title, toReturn); } return toReturn; } public TaskList updateGtaskList(TaskList list) throws IOException { - TaskList toReturn; + TaskList toReturn = null; try { toReturn = service.tasklists.update(list.id, list).execute(); } catch (IOException e) { handleException(e); toReturn = service.tasklists.update(list.id, list).execute(); + } finally { + log("Update list, id: " + list.id, toReturn); } return toReturn; } @@ -141,22 +155,17 @@ public class GtasksService { } catch (IOException e) { handleException(e); service.tasklists.delete(listId).execute(); + } finally { + log("Delete list, id: " + listId, null); } } public com.google.api.services.tasks.v1.model.Tasks getAllGtasksFromTaskList(TaskList list, boolean includeDeleted) throws IOException { - com.google.api.services.tasks.v1.model.Tasks toReturn; - try { - toReturn = getAllGtasksFromListId(list.id, includeDeleted); - } catch (IOException e) { - handleException(e); - toReturn = getAllGtasksFromListId(list.id, includeDeleted); - } - return toReturn; + return getAllGtasksFromListId(list.id, includeDeleted); } public com.google.api.services.tasks.v1.model.Tasks getAllGtasksFromListId(String listId, boolean includeDeleted) throws IOException { - com.google.api.services.tasks.v1.model.Tasks toReturn; + com.google.api.services.tasks.v1.model.Tasks toReturn = null; List request = service.tasks.list(listId); request.showDeleted = includeDeleted; try { @@ -164,17 +173,21 @@ public class GtasksService { } catch (IOException e) { handleException(e); toReturn = request.execute(); + } finally { + log("Get all tasks, list: " + listId + ", include deleted: " + includeDeleted, toReturn); } return toReturn; } public Task getGtask(String listId, String taskId) throws IOException { - Task toReturn; + Task toReturn = null; try { toReturn = service.tasks.get(listId, taskId).execute(); } catch (IOException e) { handleException(e); toReturn = service.tasks.get(listId, taskId).execute(); + } finally { + log("Get gtask, id: " + taskId, toReturn); } return toReturn; } @@ -197,23 +210,27 @@ public class GtasksService { insertOp.parent = parent; insertOp.previous = priorSiblingId; - Task toReturn; + Task toReturn = null; try { toReturn = insertOp.execute(); } catch (IOException e) { handleException(e); toReturn = insertOp.execute(); + } finally { + log("Creating gtask, title: " + task.title, toReturn); } return toReturn; } public Task updateGtask(String listId, Task task) throws IOException { - Task toReturn; + Task toReturn = null; try { toReturn = service.tasks.update(listId, task.id, task).execute(); } catch (IOException e) { handleException(e); toReturn = service.tasks.update(listId, task.id, task).execute(); + } finally { + log("Update gtask, title: " + task.title, toReturn); } return toReturn; } @@ -223,12 +240,14 @@ public class GtasksService { move.parent = parentId; move.previous = previousId; - Task toReturn; + Task toReturn = null; try { toReturn = move.execute(); } catch (IOException e) { handleException(e); toReturn = move.execute(); + } finally { + log("Move task " + taskId + "to parent: " + parentId + ", prior sibling: " + previousId, toReturn); } return toReturn; } @@ -239,6 +258,8 @@ public class GtasksService { } catch (IOException e) { handleException(e); service.tasks.delete(listId, taskId).execute(); + } finally { + log("Delete task, id: " + taskId, null); } } @@ -248,6 +269,8 @@ public class GtasksService { } catch (IOException e) { handleException(e); service.tasks.clear(listId).execute(); + } finally { + log("Clear completed tasks, list id: " + listId, null); } } } diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksLegacyMigrator.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksLegacyMigrator.java index fe1ba2141..b21510615 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksLegacyMigrator.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksLegacyMigrator.java @@ -75,10 +75,11 @@ public class GtasksLegacyMigrator { defaultListId = list.id; } - Tasks allTasks = gtasksService.getAllGtasksFromListId(list.id, true); + Tasks allTasks = gtasksService.getAllGtasksFromListId(list.id, false); if (allTasks.items != null) { for (com.google.api.services.tasks.v1.model.Task t : allTasks.items) { + System.err.println("Constructing key with title: " + t.title); String key = constructKeyFromTitles(t.title, list.title); taskAndListTitlesToRemoteTaskIds.put(key, t.id); } @@ -86,16 +87,17 @@ public class GtasksLegacyMigrator { } //For each local task, check to see if its title paired with any list title has a match in the map - while (!allTasksWithGtaskData.isLast()) { - allTasksWithGtaskData.moveToNext(); + for (allTasksWithGtaskData.moveToFirst(); !allTasksWithGtaskData.isAfterLast(); allTasksWithGtaskData.moveToNext()) { GtasksTaskContainer container = gtasksMetadataService.readTaskAndMetadata(allTasksWithGtaskData); - + System.err.println("Migrating task with title: " + container.task.getValue(Task.TITLE) + + ", remote id: " + container.gtaskMetadata.getValue(GtasksMetadata.ID)); //Search through lists to see if one of them has match String taskTitle = container.task.getValue(Task.TITLE); for (com.google.api.services.tasks.v1.model.TaskList list : allLists.items) { String expectedKey = constructKeyFromTitles(taskTitle, list.title); if (taskAndListTitlesToRemoteTaskIds.containsKey(expectedKey)) { + System.err.println("Found match"); String newRemoteTaskId = taskAndListTitlesToRemoteTaskIds.get(expectedKey); String newRemoteListId = list.id; @@ -103,6 +105,13 @@ public class GtasksLegacyMigrator { container.gtaskMetadata.setValue(GtasksMetadata.LIST_ID, newRemoteListId); gtasksMetadataService.saveTaskAndMetadata(container); break; + } else { + System.err.println("Resetting metadata"); + //For non-matches, make the task look newly created + container.gtaskMetadata.setValue(GtasksMetadata.ID, ""); //$NON-NLS-1$ + container.gtaskMetadata.setValue(GtasksMetadata.LIST_ID, list.id); + gtasksMetadataService.saveTaskAndMetadata(container); + break; } } }