diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/BriefMe.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/BriefMe.java index 79ebbaa21..a806dbef2 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/BriefMe.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/BriefMe.java @@ -1,18 +1,15 @@ package com.todoroo.astrid.actfm.sync.messages; +import com.todoroo.astrid.dao.RemoteModelDao; import com.todoroo.astrid.data.RemoteModel; -public class BriefMe implements ClientToServerMessage { +public class BriefMe extends ClientToServerMessage { - private final Class modelClass; - private final String uuid; - private long pushedAt; // TODO: Populate and use - - public BriefMe(TYPE entity) { - this.modelClass = entity.getClass(); - this.uuid = entity.getValue(RemoteModel.UUID_PROPERTY); + public BriefMe(long id, Class modelClass, RemoteModelDao modelDao) { + super(id, modelClass, modelDao); } + @Override public void sendMessage() { // Send message } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ChangesHappened.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ChangesHappened.java index 30f9e6be7..5641a9c7e 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ChangesHappened.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ChangesHappened.java @@ -17,33 +17,23 @@ import com.todoroo.astrid.data.OutstandingEntry; import com.todoroo.astrid.data.RemoteModel; @SuppressWarnings("nls") -public class ChangesHappened> implements ClientToServerMessage { +public class ChangesHappened> extends ClientToServerMessage { - private final Class modelClass; private final Class outstandingClass; - private final long id; - private final String uuid; private final List changes; - private final long pushedAt; public ChangesHappened(long id, Class modelClass, RemoteModelDao modelDao, OutstandingEntryDao outstandingDao) { - this.modelClass = modelClass; + super(id, modelClass, modelDao); + this.outstandingClass = getOutstandingClass(modelClass); - this.id = id; this.changes = new ArrayList(); - TYPE entity = getEntity(id, modelDao); - if (entity == null) { - this.uuid = RemoteModel.NO_UUID; - this.pushedAt = 0; - } else { - this.uuid = entity.getValue(RemoteModel.UUID_PROPERTY); - this.pushedAt = entity.getValue(RemoteModel.PUSHED_AT_PROPERTY); + if (!RemoteModel.NO_UUID.equals(uuid)) populateChanges(outstandingDao); - } } + @Override public void sendMessage() { // Process changes list and send to server } @@ -56,18 +46,6 @@ public class ChangesHappened modelDao) { - return modelDao.fetch(localId, RemoteModel.UUID_PROPERTY, RemoteModel.PUSHED_AT_PROPERTY); - } - private void populateChanges(OutstandingEntryDao outstandingDao) { TodorooCursor cursor = outstandingDao.query(Query.select(getModelProperties(outstandingClass)) .where(OutstandingEntry.ENTITY_ID_PROPERTY.eq(id)).orderBy(Order.asc(OutstandingEntry.CREATED_AT_PROPERTY))); diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ClientToServerMessage.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ClientToServerMessage.java index 5d9d3726f..09e73fa6e 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ClientToServerMessage.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ClientToServerMessage.java @@ -1,7 +1,41 @@ package com.todoroo.astrid.actfm.sync.messages; -public interface ClientToServerMessage { +import com.todoroo.astrid.dao.RemoteModelDao; +import com.todoroo.astrid.data.RemoteModel; - public void sendMessage(); +public abstract class ClientToServerMessage { + + protected final Class modelClass; + protected final long id; + protected final String uuid; + protected final long pushedAt; + + public ClientToServerMessage(long id, Class modelClass, RemoteModelDao modelDao) { + this.id = id; + this.modelClass = modelClass; + + TYPE entity = getEntity(id, modelDao); + if (entity == null) { + this.uuid = RemoteModel.NO_UUID; + this.pushedAt = 0; + } else { + this.uuid = entity.getValue(RemoteModel.UUID_PROPERTY); + this.pushedAt = entity.getValue(RemoteModel.PUSHED_AT_PROPERTY); + } + } + + private TYPE getEntity(long localId, RemoteModelDao modelDao) { + return modelDao.fetch(localId, RemoteModel.UUID_PROPERTY, RemoteModel.PUSHED_AT_PROPERTY); + } + + public final String getUUID() { + return uuid; + } + + public final long getPushedAt() { + return pushedAt; + } + + public abstract void sendMessage(); } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/RequestDoubleCheck.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/RequestDoubleCheck.java index ffcf348e2..b3ce76956 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/RequestDoubleCheck.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/RequestDoubleCheck.java @@ -1,17 +1,15 @@ package com.todoroo.astrid.actfm.sync.messages; +import com.todoroo.astrid.dao.RemoteModelDao; import com.todoroo.astrid.data.RemoteModel; -public class RequestDoubleCheck implements ClientToServerMessage { +public class RequestDoubleCheck extends ClientToServerMessage { - private final Class modelClass; - private final String uuid; - - public RequestDoubleCheck(TYPE entity) { - this.modelClass = entity.getClass(); - this.uuid = entity.getValue(RemoteModel.UUID_PROPERTY); + public RequestDoubleCheck(long id, Class modelClass, RemoteModelDao modelDao) { + super(id, modelClass, modelDao); } + @Override public void sendMessage() { // Send message } diff --git a/tests-sync/src/com/todoroo/astrid/sync/SyncModelTest.java b/tests-sync/src/com/todoroo/astrid/sync/SyncModelTest.java index 973675491..53e6db200 100644 --- a/tests-sync/src/com/todoroo/astrid/sync/SyncModelTest.java +++ b/tests-sync/src/com/todoroo/astrid/sync/SyncModelTest.java @@ -3,31 +3,25 @@ package com.todoroo.astrid.sync; import android.text.TextUtils; import com.todoroo.andlib.data.TodorooCursor; -import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Query; -import com.todoroo.astrid.dao.TagDataDao; -import com.todoroo.astrid.dao.TagOutstandingDao; -import com.todoroo.astrid.dao.TaskDao; -import com.todoroo.astrid.dao.TaskOutstandingDao; import com.todoroo.astrid.data.RemoteModel; import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.TagOutstanding; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.TaskOutstanding; -import com.todoroo.astrid.test.DatabaseTestCase; public class SyncModelTest extends NewSyncTestCase { public void testCreateTaskMakesUuid() { Task task = createTask(); - assertTrue(task.getValue(Task.REMOTE_ID) != 0); + assertFalse(RemoteModel.NO_UUID.equals(task.getValue(Task.UUID))); assertFalse(TextUtils.isEmpty(task.getValue(Task.PROOF_TEXT))); } public void testCreateTagMakesUuid() { TagData tag = createTagData(); - assertTrue(tag.getValue(TagData.REMOTE_ID) != 0); + assertFalse(RemoteModel.NO_UUID.equals(tag.getValue(TagData.UUID))); assertFalse(TextUtils.isEmpty(tag.getValue(TagData.PROOF_TEXT))); }