Fixed a bug with the migration process--if a particular task can't be migrated, reset its remote id so we don't query api with bad ids

pull/14/head
Sam Bosley 14 years ago
parent a2196491bb
commit d07c007317

@ -128,7 +128,8 @@ abstract public class SyncMetadataService<TYPE extends SyncContainer> {
* @param left * @param left
* @param right * @param right
* @param matchingRows * @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, private static void joinRows(TodorooCursor<?> left,
TodorooCursor<?> right, ArrayList<Long> matchingRows, TodorooCursor<?> right, ArrayList<Long> matchingRows,

@ -61,11 +61,13 @@ public class GtasksService {
if (e instanceof HttpResponseException) { if (e instanceof HttpResponseException) {
HttpResponseException h = (HttpResponseException)e; HttpResponseException h = (HttpResponseException)e;
if (h.response.statusCode == 401 || h.response.statusCode == 403) { if (h.response.statusCode == 401 || h.response.statusCode == 403) {
System.err.println("Encountered " + h.response.statusCode + " error");
token = GtasksTokenValidator.validateAuthToken(token); token = GtasksTokenValidator.validateAuthToken(token);
if (token != null) { if (token != null) {
accessProtectedResource.setAccessToken(token); 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 } 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(); final Context context = ContextManager.getContext();
String message = context.getString(R.string.gtasks_error_backend); String message = context.getString(R.string.gtasks_error_backend);
exceptionService.reportError(message, h); 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. * 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-- * 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 { public TaskLists allGtaskLists() throws IOException {
TaskLists toReturn; TaskLists toReturn = null;
try { try {
toReturn = service.tasklists.list().execute(); toReturn = service.tasklists.list().execute();
} catch (IOException e) { } catch (IOException e) {
handleException(e); handleException(e);
toReturn = service.tasklists.list().execute(); toReturn = service.tasklists.list().execute();
} finally {
log("All gtasks lists", toReturn);
} }
return toReturn; return toReturn;
} }
public TaskList getGtaskList(String id) throws IOException { public TaskList getGtaskList(String id) throws IOException {
TaskList toReturn; TaskList toReturn = null;
try { try {
toReturn = service.tasklists.get(id).execute(); toReturn = service.tasklists.get(id).execute();
} catch (IOException e) { } catch (IOException e) {
handleException(e); handleException(e);
toReturn = service.tasklists.get(id).execute(); toReturn = service.tasklists.get(id).execute();
} finally {
log("Get gtask list, id: " + id, toReturn);
} }
return toReturn; return toReturn;
} }
@ -114,23 +124,27 @@ public class GtasksService {
public TaskList createGtaskList(String title) throws IOException { public TaskList createGtaskList(String title) throws IOException {
TaskList newList = new TaskList(); TaskList newList = new TaskList();
newList.title = title; newList.title = title;
TaskList toReturn; TaskList toReturn = null;
try { try {
toReturn = service.tasklists.insert(newList).execute(); toReturn = service.tasklists.insert(newList).execute();
} catch (IOException e) { } catch (IOException e) {
handleException(e); handleException(e);
toReturn = service.tasklists.insert(newList).execute(); toReturn = service.tasklists.insert(newList).execute();
} finally {
log("Create gtask list, title: " + title, toReturn);
} }
return toReturn; return toReturn;
} }
public TaskList updateGtaskList(TaskList list) throws IOException { public TaskList updateGtaskList(TaskList list) throws IOException {
TaskList toReturn; TaskList toReturn = null;
try { try {
toReturn = service.tasklists.update(list.id, list).execute(); toReturn = service.tasklists.update(list.id, list).execute();
} catch (IOException e) { } catch (IOException e) {
handleException(e); handleException(e);
toReturn = service.tasklists.update(list.id, list).execute(); toReturn = service.tasklists.update(list.id, list).execute();
} finally {
log("Update list, id: " + list.id, toReturn);
} }
return toReturn; return toReturn;
} }
@ -141,22 +155,17 @@ public class GtasksService {
} catch (IOException e) { } catch (IOException e) {
handleException(e); handleException(e);
service.tasklists.delete(listId).execute(); 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 { 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; return getAllGtasksFromListId(list.id, includeDeleted);
try {
toReturn = getAllGtasksFromListId(list.id, includeDeleted);
} catch (IOException e) {
handleException(e);
toReturn = getAllGtasksFromListId(list.id, includeDeleted);
}
return toReturn;
} }
public com.google.api.services.tasks.v1.model.Tasks getAllGtasksFromListId(String listId, boolean includeDeleted) throws IOException { 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); List request = service.tasks.list(listId);
request.showDeleted = includeDeleted; request.showDeleted = includeDeleted;
try { try {
@ -164,17 +173,21 @@ public class GtasksService {
} catch (IOException e) { } catch (IOException e) {
handleException(e); handleException(e);
toReturn = request.execute(); toReturn = request.execute();
} finally {
log("Get all tasks, list: " + listId + ", include deleted: " + includeDeleted, toReturn);
} }
return toReturn; return toReturn;
} }
public Task getGtask(String listId, String taskId) throws IOException { public Task getGtask(String listId, String taskId) throws IOException {
Task toReturn; Task toReturn = null;
try { try {
toReturn = service.tasks.get(listId, taskId).execute(); toReturn = service.tasks.get(listId, taskId).execute();
} catch (IOException e) { } catch (IOException e) {
handleException(e); handleException(e);
toReturn = service.tasks.get(listId, taskId).execute(); toReturn = service.tasks.get(listId, taskId).execute();
} finally {
log("Get gtask, id: " + taskId, toReturn);
} }
return toReturn; return toReturn;
} }
@ -197,23 +210,27 @@ public class GtasksService {
insertOp.parent = parent; insertOp.parent = parent;
insertOp.previous = priorSiblingId; insertOp.previous = priorSiblingId;
Task toReturn; Task toReturn = null;
try { try {
toReturn = insertOp.execute(); toReturn = insertOp.execute();
} catch (IOException e) { } catch (IOException e) {
handleException(e); handleException(e);
toReturn = insertOp.execute(); toReturn = insertOp.execute();
} finally {
log("Creating gtask, title: " + task.title, toReturn);
} }
return toReturn; return toReturn;
} }
public Task updateGtask(String listId, Task task) throws IOException { public Task updateGtask(String listId, Task task) throws IOException {
Task toReturn; Task toReturn = null;
try { try {
toReturn = service.tasks.update(listId, task.id, task).execute(); toReturn = service.tasks.update(listId, task.id, task).execute();
} catch (IOException e) { } catch (IOException e) {
handleException(e); handleException(e);
toReturn = service.tasks.update(listId, task.id, task).execute(); toReturn = service.tasks.update(listId, task.id, task).execute();
} finally {
log("Update gtask, title: " + task.title, toReturn);
} }
return toReturn; return toReturn;
} }
@ -223,12 +240,14 @@ public class GtasksService {
move.parent = parentId; move.parent = parentId;
move.previous = previousId; move.previous = previousId;
Task toReturn; Task toReturn = null;
try { try {
toReturn = move.execute(); toReturn = move.execute();
} catch (IOException e) { } catch (IOException e) {
handleException(e); handleException(e);
toReturn = move.execute(); toReturn = move.execute();
} finally {
log("Move task " + taskId + "to parent: " + parentId + ", prior sibling: " + previousId, toReturn);
} }
return toReturn; return toReturn;
} }
@ -239,6 +258,8 @@ public class GtasksService {
} catch (IOException e) { } catch (IOException e) {
handleException(e); handleException(e);
service.tasks.delete(listId, taskId).execute(); service.tasks.delete(listId, taskId).execute();
} finally {
log("Delete task, id: " + taskId, null);
} }
} }
@ -248,6 +269,8 @@ public class GtasksService {
} catch (IOException e) { } catch (IOException e) {
handleException(e); handleException(e);
service.tasks.clear(listId).execute(); service.tasks.clear(listId).execute();
} finally {
log("Clear completed tasks, list id: " + listId, null);
} }
} }
} }

@ -75,10 +75,11 @@ public class GtasksLegacyMigrator {
defaultListId = list.id; defaultListId = list.id;
} }
Tasks allTasks = gtasksService.getAllGtasksFromListId(list.id, true); Tasks allTasks = gtasksService.getAllGtasksFromListId(list.id, false);
if (allTasks.items != null) { if (allTasks.items != null) {
for (com.google.api.services.tasks.v1.model.Task t : allTasks.items) { 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); String key = constructKeyFromTitles(t.title, list.title);
taskAndListTitlesToRemoteTaskIds.put(key, t.id); 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 //For each local task, check to see if its title paired with any list title has a match in the map
while (!allTasksWithGtaskData.isLast()) { for (allTasksWithGtaskData.moveToFirst(); !allTasksWithGtaskData.isAfterLast(); allTasksWithGtaskData.moveToNext()) {
allTasksWithGtaskData.moveToNext();
GtasksTaskContainer container = gtasksMetadataService.readTaskAndMetadata(allTasksWithGtaskData); 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 //Search through lists to see if one of them has match
String taskTitle = container.task.getValue(Task.TITLE); String taskTitle = container.task.getValue(Task.TITLE);
for (com.google.api.services.tasks.v1.model.TaskList list : allLists.items) { for (com.google.api.services.tasks.v1.model.TaskList list : allLists.items) {
String expectedKey = constructKeyFromTitles(taskTitle, list.title); String expectedKey = constructKeyFromTitles(taskTitle, list.title);
if (taskAndListTitlesToRemoteTaskIds.containsKey(expectedKey)) { if (taskAndListTitlesToRemoteTaskIds.containsKey(expectedKey)) {
System.err.println("Found match");
String newRemoteTaskId = taskAndListTitlesToRemoteTaskIds.get(expectedKey); String newRemoteTaskId = taskAndListTitlesToRemoteTaskIds.get(expectedKey);
String newRemoteListId = list.id; String newRemoteListId = list.id;
@ -103,6 +105,13 @@ public class GtasksLegacyMigrator {
container.gtaskMetadata.setValue(GtasksMetadata.LIST_ID, newRemoteListId); container.gtaskMetadata.setValue(GtasksMetadata.LIST_ID, newRemoteListId);
gtasksMetadataService.saveTaskAndMetadata(container); gtasksMetadataService.saveTaskAndMetadata(container);
break; 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;
} }
} }
} }

Loading…
Cancel
Save