If migration fails, stop sync. Also minor cleanup

pull/14/head
Tim Su 15 years ago
parent 0ec2982025
commit e2f8f77fd4

@ -5,10 +5,6 @@ import java.io.IOException;
public class GoogleTasksException extends IOException { public class GoogleTasksException extends IOException {
private static final long serialVersionUID = -5585448790574862510L; private static final long serialVersionUID = -5585448790574862510L;
public GoogleTasksException() {
}
public GoogleTasksException(String message) { public GoogleTasksException(String message) {
super(message); super(message);
} }

@ -23,9 +23,9 @@ import com.google.api.services.tasks.v1.model.TaskLists;
public class GtasksService { public class GtasksService {
private Tasks service; private Tasks service;
private static final String API_KEY = "AIzaSyCIYZTBo6haRHxmiplZsfYdagFEpaiFnAk"; //Dummy private static final String API_KEY = "AIzaSyCIYZTBo6haRHxmiplZsfYdagFEpaiFnAk"; // non-production API key
public static final String AUTH_TOKEN_TYPE = "oauth2:https://www.googleapis.com/auth/tasks"; //$NON-NLS-1$ public static final String AUTH_TOKEN_TYPE = "oauth2:https://www.googleapis.com/auth/tasks";
public GtasksService(String authToken) { public GtasksService(String authToken) {
try { try {

@ -51,7 +51,7 @@ public class GtasksLegacyMigrator {
this.allLists = allLists; this.allLists = allLists;
} }
public boolean checkAndMigrateLegacy() { public void checkAndMigrateLegacy() throws IOException {
if (!Preferences.getBoolean(MIGRATION_HAS_OCCURRED, false)) { if (!Preferences.getBoolean(MIGRATION_HAS_OCCURRED, false)) {
listService.migrateListIds(allLists); listService.migrateListIds(allLists);
@ -65,8 +65,6 @@ public class GtasksLegacyMigrator {
Query.select(Metadata.TASK).from(Metadata.TABLE). Query.select(Metadata.TASK).from(Metadata.TABLE).
where(Metadata.KEY.eq(GtasksMetadata.METADATA_KEY))))); where(Metadata.KEY.eq(GtasksMetadata.METADATA_KEY)))));
try { try {
if (allTasksWithGtaskData.getCount() > 0) { if (allTasksWithGtaskData.getCount() > 0) {
//Fetch all remote tasks from all remote lists (this may be an expensive operation) //Fetch all remote tasks from all remote lists (this may be an expensive operation)
@ -112,14 +110,11 @@ public class GtasksLegacyMigrator {
if (defaultListId == null) defaultListId = "@default"; //$NON-NLS-1$ if (defaultListId == null) defaultListId = "@default"; //$NON-NLS-1$
Preferences.setString(GtasksPreferenceService.PREF_DEFAULT_LIST, defaultListId); Preferences.setString(GtasksPreferenceService.PREF_DEFAULT_LIST, defaultListId);
} }
} catch (IOException e) {
return false;
} finally { } finally {
allTasksWithGtaskData.close(); allTasksWithGtaskData.close();
} }
Preferences.setBoolean(MIGRATION_HAS_OCCURRED, true); //Record successful migration Preferences.setBoolean(MIGRATION_HAS_OCCURRED, true); //Record successful migration
} }
return true;
} }
private String constructKeyFromTitles(String taskTitle, String listTitle) { private String constructKeyFromTitles(String taskTitle, String listTitle) {

@ -165,8 +165,8 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
try { try {
TaskLists allTaskLists = taskService.allGtaskLists(); TaskLists allTaskLists = taskService.allGtaskLists();
//TODO: do something with result of migration check? new GtasksLegacyMigrator(taskService, gtasksListService,
new GtasksLegacyMigrator(taskService, gtasksListService, allTaskLists).checkAndMigrateLegacy(); allTaskLists).checkAndMigrateLegacy();
getActiveList(allTaskLists); getActiveList(allTaskLists);
@ -244,7 +244,7 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
localIdsToRemoteIds.put(task.task.getId(), task.gtaskMetadata.getValue(GtasksMetadata.ID)); localIdsToRemoteIds.put(task.task.getId(), task.gtaskMetadata.getValue(GtasksMetadata.ID));
} }
verifyCreatedOrder(locals, localIdsToRemoteIds); verifyCreatedOrder(localIdsToRemoteIds);
for(GtasksTaskContainer remote : data.remoteUpdated) { for(GtasksTaskContainer remote : data.remoteUpdated) {
if(remote.task.getId() < 1) { if(remote.task.getId() < 1) {
@ -260,8 +260,7 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
super.readRemotelyUpdated(data); super.readRemotelyUpdated(data);
} }
private void verifyCreatedOrder(HashMap<String, GtasksTaskContainer> locals, private void verifyCreatedOrder(HashMap<Long, String> localIdsToRemoteIds) throws IOException {
HashMap<Long, String> localIdsToRemoteIds) throws IOException {
for (GtasksTaskContainer t : createdWithoutParent) { for (GtasksTaskContainer t : createdWithoutParent) {
String toMove = t.gtaskMetadata.getValue(GtasksMetadata.ID); String toMove = t.gtaskMetadata.getValue(GtasksMetadata.ID);
String listId = t.gtaskMetadata.getValue(GtasksMetadata.LIST_ID); String listId = t.gtaskMetadata.getValue(GtasksMetadata.LIST_ID);
@ -280,16 +279,7 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
// all synchronized properties // all synchronized properties
private static final Property<?>[] PROPERTIES = new Property<?>[] { private static final Property<?>[] PROPERTIES = Task.PROPERTIES;
Task.ID,
Task.TITLE,
Task.DUE_DATE,
Task.CREATION_DATE,
Task.COMPLETION_DATE,
Task.DELETION_DATE,
Task.REMINDER_FLAGS,
Task.NOTES,
};
/** /**
* Populate SyncData data structure * Populate SyncData data structure
@ -351,7 +341,6 @@ public class GtasksSyncProvider extends SyncProvider<GtasksTaskContainer> {
if (remoteTasks != null) { if (remoteTasks != null) {
int order = 0; int order = 0;
//HashMap<String, List<String>> children = new HashMap<String, List<String>>();
HashMap<String, com.google.api.services.tasks.v1.model.Task> idsToTasks = new HashMap<String, com.google.api.services.tasks.v1.model.Task>(); HashMap<String, com.google.api.services.tasks.v1.model.Task> idsToTasks = new HashMap<String, com.google.api.services.tasks.v1.model.Task>();
HashMap<String, Integer> indentation = new HashMap<String, Integer>(); HashMap<String, Integer> indentation = new HashMap<String, Integer>();
HashMap<String, String> parentToPriorSiblingMap = new HashMap<String, String>(); HashMap<String, String> parentToPriorSiblingMap = new HashMap<String, String>();

Loading…
Cancel
Save