If migration fails, stop sync. Also minor cleanup

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

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

@ -23,9 +23,9 @@ import com.google.api.services.tasks.v1.model.TaskLists;
public class GtasksService {
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) {
try {

@ -51,7 +51,7 @@ public class GtasksLegacyMigrator {
this.allLists = allLists;
}
public boolean checkAndMigrateLegacy() {
public void checkAndMigrateLegacy() throws IOException {
if (!Preferences.getBoolean(MIGRATION_HAS_OCCURRED, false)) {
listService.migrateListIds(allLists);
@ -65,8 +65,6 @@ public class GtasksLegacyMigrator {
Query.select(Metadata.TASK).from(Metadata.TABLE).
where(Metadata.KEY.eq(GtasksMetadata.METADATA_KEY)))));
try {
if (allTasksWithGtaskData.getCount() > 0) {
//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$
Preferences.setString(GtasksPreferenceService.PREF_DEFAULT_LIST, defaultListId);
}
} catch (IOException e) {
return false;
} finally {
allTasksWithGtaskData.close();
}
Preferences.setBoolean(MIGRATION_HAS_OCCURRED, true); //Record successful migration
}
return true;
}
private String constructKeyFromTitles(String taskTitle, String listTitle) {

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

Loading…
Cancel
Save