Fixed several bugs related to constructing outstanding tables after login

pull/14/head
Sam Bosley 13 years ago
parent 9c9dfaf288
commit 3e6c67a3c3

@ -40,7 +40,7 @@ import com.todoroo.astrid.utility.Constants;
public class ActFmInvoker { public class ActFmInvoker {
/** NOTE: these values are development values & will not work on production */ /** NOTE: these values are development values & will not work on production */
private static final String URL = "//192.168.0.160:3000/api/"; private static final String URL = "//192.168.0.100:3000/api/";
private static final String APP_ID = "a4732a32859dbcd3e684331acd36432c"; private static final String APP_ID = "a4732a32859dbcd3e684331acd36432c";
private static final String APP_SECRET = "e389bfc82a0d932332f9a8bd8203735f"; private static final String APP_SECRET = "e389bfc82a0d932332f9a8bd8203735f";

@ -25,7 +25,9 @@ import com.todoroo.astrid.actfm.sync.messages.ChangesHappened;
import com.todoroo.astrid.actfm.sync.messages.ClientToServerMessage; import com.todoroo.astrid.actfm.sync.messages.ClientToServerMessage;
import com.todoroo.astrid.actfm.sync.messages.NameMaps; import com.todoroo.astrid.actfm.sync.messages.NameMaps;
import com.todoroo.astrid.actfm.sync.messages.ReplayOutstandingEntries; import com.todoroo.astrid.actfm.sync.messages.ReplayOutstandingEntries;
import com.todoroo.astrid.actfm.sync.messages.ReplayTaskListMetadataOutstanding;
import com.todoroo.astrid.actfm.sync.messages.ServerToClientMessage; import com.todoroo.astrid.actfm.sync.messages.ServerToClientMessage;
import com.todoroo.astrid.actfm.sync.messages.TaskListMetadataChangesHappened;
import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.dao.OutstandingEntryDao; import com.todoroo.astrid.dao.OutstandingEntryDao;
@ -298,9 +300,9 @@ public class ActFmSyncThread {
// Called after a batch has finished processing // Called after a batch has finished processing
private void replayOutstandingChanges(boolean afterErrors) { private void replayOutstandingChanges(boolean afterErrors) {
syncLog("Replaying outstanding changes"); //$NON-NLS-1$ syncLog("Replaying outstanding changes"); //$NON-NLS-1$
new ReplayOutstandingEntries<Task, TaskOutstanding>(Task.class, NameMaps.TABLE_ID_TASKS, taskDao, taskOutstandingDao, this, afterErrors).execute(); new ReplayOutstandingEntries<Task, TaskOutstanding>(Task.class, NameMaps.TABLE_ID_TASKS, taskDao, taskOutstandingDao, afterErrors).execute();
new ReplayOutstandingEntries<TagData, TagOutstanding>(TagData.class, NameMaps.TABLE_ID_TAGS, tagDataDao, tagOutstandingDao, this, afterErrors).execute(); new ReplayOutstandingEntries<TagData, TagOutstanding>(TagData.class, NameMaps.TABLE_ID_TAGS, tagDataDao, tagOutstandingDao, afterErrors).execute();
new ReplayOutstandingEntries<TaskListMetadata, TaskListMetadataOutstanding>(TaskListMetadata.class, NameMaps.TABLE_ID_TASK_LIST_METADATA, taskListMetadataDao, taskListMetadataOutstandingDao, this, afterErrors).execute(); new ReplayTaskListMetadataOutstanding(taskListMetadataDao, taskListMetadataOutstandingDao, afterErrors).execute();
} }
private boolean timeForBackgroundSync() { private boolean timeForBackgroundSync() {
@ -308,9 +310,11 @@ public class ActFmSyncThread {
} }
public void repopulateQueueFromOutstandingTables() { public void repopulateQueueFromOutstandingTables() {
syncLog("Constructing queue from outstanding tables"); //$NON-NLS-1$
constructChangesHappenedFromOutstandingTable(Task.class, taskDao, taskOutstandingDao); constructChangesHappenedFromOutstandingTable(Task.class, taskDao, taskOutstandingDao);
constructChangesHappenedFromOutstandingTable(TagData.class, tagDataDao, tagOutstandingDao); constructChangesHappenedFromOutstandingTable(TagData.class, tagDataDao, tagOutstandingDao);
constructChangesHappenedFromOutstandingTable(UserActivity.class, userActivityDao, userActivityOutstandingDao); constructChangesHappenedFromOutstandingTable(UserActivity.class, userActivityDao, userActivityOutstandingDao);
constructChangesHappenedForTaskListMetadata(taskListMetadataDao, taskListMetadataOutstandingDao);
} }
private <T extends RemoteModel, OE extends OutstandingEntry<T>> void constructChangesHappenedFromOutstandingTable(Class<T> modelClass, RemoteModelDao<T> modelDao, OutstandingEntryDao<OE> oustandingDao) { private <T extends RemoteModel, OE extends OutstandingEntry<T>> void constructChangesHappenedFromOutstandingTable(Class<T> modelClass, RemoteModelDao<T> modelDao, OutstandingEntryDao<OE> oustandingDao) {
@ -318,8 +322,19 @@ public class ActFmSyncThread {
try { try {
for (outstanding.moveToFirst(); !outstanding.isAfterLast(); outstanding.moveToNext()) { for (outstanding.moveToFirst(); !outstanding.isAfterLast(); outstanding.moveToNext()) {
Long id = outstanding.get(OutstandingEntry.ENTITY_ID_PROPERTY); Long id = outstanding.get(OutstandingEntry.ENTITY_ID_PROPERTY);
ChangesHappened<T, OE> ch = new ChangesHappened<T, OE>(id, modelClass, modelDao, oustandingDao); enqueueMessage(new ChangesHappened<T, OE>(id, modelClass, modelDao, oustandingDao), null);
enqueueMessage(ch, null); }
} finally {
outstanding.close();
}
}
private void constructChangesHappenedForTaskListMetadata(TaskListMetadataDao dao, TaskListMetadataOutstandingDao outstandingDao) {
TodorooCursor<TaskListMetadataOutstanding> outstanding = outstandingDao.query(Query.select(OutstandingEntry.ENTITY_ID_PROPERTY).groupBy(OutstandingEntry.ENTITY_ID_PROPERTY));
try {
for (outstanding.moveToFirst(); !outstanding.isAfterLast(); outstanding.moveToNext()) {
Long id = outstanding.get(OutstandingEntry.ENTITY_ID_PROPERTY);
ActFmSyncWaitingPool.getInstance().enqueueMessage(new TaskListMetadataChangesHappened(id, TaskListMetadata.class, dao, outstandingDao));
} }
} finally { } finally {
outstanding.close(); outstanding.close();

@ -20,22 +20,19 @@ public class ReplayOutstandingEntries<T extends RemoteModel, OE extends Outstand
private static final String ERROR_TAG = "actfm-replay-outstanding"; private static final String ERROR_TAG = "actfm-replay-outstanding";
private final Class<T> modelClass; protected final Class<T> modelClass;
private final Class<OE> outstandingClass; private final Class<OE> outstandingClass;
private final String table; private final String table;
private final RemoteModelDao<T> dao; protected final RemoteModelDao<T> dao;
private final OutstandingEntryDao<OE> outstandingDao; protected final OutstandingEntryDao<OE> outstandingDao;
private final ActFmSyncThread actFmSyncThread;
private final boolean afterErrors; private final boolean afterErrors;
public ReplayOutstandingEntries(Class<T> modelClass, String table, RemoteModelDao<T> dao, OutstandingEntryDao<OE> outstandingDao, public ReplayOutstandingEntries(Class<T> modelClass, String table, RemoteModelDao<T> dao, OutstandingEntryDao<OE> outstandingDao, boolean afterErrors) {
ActFmSyncThread actFmSyncThread, boolean afterErrors) {
this.modelClass = modelClass; this.modelClass = modelClass;
this.outstandingClass = DaoReflectionHelpers.getOutstandingClass(modelClass); this.outstandingClass = DaoReflectionHelpers.getOutstandingClass(modelClass);
this.table = table; this.table = table;
this.dao = dao; this.dao = dao;
this.outstandingDao = outstandingDao; this.outstandingDao = outstandingDao;
this.actFmSyncThread = actFmSyncThread;
this.afterErrors = afterErrors; this.afterErrors = afterErrors;
} }
@ -58,6 +55,10 @@ public class ReplayOutstandingEntries<T extends RemoteModel, OE extends Outstand
} }
} }
protected void enqueueChangesHappenedMessage(long id) {
ActFmSyncThread.getInstance().enqueueMessage(new ChangesHappened<T, OE>(id, modelClass, dao, outstandingDao), null);
}
private void processItem(long id, OE instance, TodorooCursor<OE> outstanding) { private void processItem(long id, OE instance, TodorooCursor<OE> outstanding) {
try { try {
T model = modelClass.newInstance(); T model = modelClass.newInstance();
@ -80,9 +81,8 @@ public class ReplayOutstandingEntries<T extends RemoteModel, OE extends Outstand
model.putTransitory(SyncFlags.ACTFM_SUPPRESS_OUTSTANDING_ENTRIES, true); model.putTransitory(SyncFlags.ACTFM_SUPPRESS_OUTSTANDING_ENTRIES, true);
dao.saveExisting(model); dao.saveExisting(model);
if (count > 0 && !afterErrors && actFmSyncThread != null) { if (count > 0 && !afterErrors) {
ChangesHappened<T, OE> ch = new ChangesHappened<T, OE>(id, modelClass, dao, outstandingDao); enqueueChangesHappenedMessage(id);
actFmSyncThread.enqueueMessage(ch, null);
} }
outstanding.moveToPrevious(); // Move back one to undo the last iteration of the for loop outstanding.moveToPrevious(); // Move back one to undo the last iteration of the for loop

@ -0,0 +1,19 @@
package com.todoroo.astrid.actfm.sync.messages;
import com.todoroo.astrid.dao.TaskListMetadataDao;
import com.todoroo.astrid.dao.TaskListMetadataOutstandingDao;
import com.todoroo.astrid.data.TaskListMetadata;
import com.todoroo.astrid.data.TaskListMetadataOutstanding;
public class ReplayTaskListMetadataOutstanding extends ReplayOutstandingEntries<TaskListMetadata, TaskListMetadataOutstanding> {
public ReplayTaskListMetadataOutstanding(TaskListMetadataDao dao, TaskListMetadataOutstandingDao outstandingDao, boolean afterErrors) {
super(TaskListMetadata.class, NameMaps.TABLE_ID_TASK_LIST_METADATA, dao, outstandingDao, afterErrors);
}
@Override
protected void enqueueChangesHappenedMessage(long id) {
// Do nothing
}
}

@ -32,7 +32,7 @@ public class TaskListMetadataChangesHappened extends ChangesHappened<TaskListMet
} else { } else {
foundOrderChange = true; foundOrderChange = true;
} }
} else if (TaskListMetadata.FILTER.name.equals(column) || TaskListMetadata.TAG_UUID.equals(column)) { } else if (TaskListMetadata.FILTER.name.equals(column) || TaskListMetadata.TAG_UUID.name.equals(column)) {
if (RemoteModel.isUuidEmpty(oe.getValue(TaskListMetadataOutstanding.VALUE_STRING))) { if (RemoteModel.isUuidEmpty(oe.getValue(TaskListMetadataOutstanding.VALUE_STRING))) {
changes.remove(i); changes.remove(i);
removedChanges.add(oe.getId()); removedChanges.add(oe.getId());

Loading…
Cancel
Save