From d7d90cb72ec26f3c57f9184fd3b330965d089d49 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Tue, 22 Jan 2013 13:44:32 -0800 Subject: [PATCH] No more UserData messages, just normal MakeChanges for the users table instead --- .../sync/messages/ServerToClientMessage.java | 5 +- .../astrid/actfm/sync/messages/UserData.java | 57 ------------------- .../src/com/todoroo/astrid/dao/UserDao.java | 3 +- 3 files changed, 4 insertions(+), 61 deletions(-) delete mode 100644 astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/UserData.java diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ServerToClientMessage.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ServerToClientMessage.java index a0a3b1f48..b321a91cd 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ServerToClientMessage.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/ServerToClientMessage.java @@ -6,6 +6,7 @@ import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.data.RemoteModel; import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.Task; +import com.todoroo.astrid.data.User; @SuppressWarnings("nls") public abstract class ServerToClientMessage { @@ -30,8 +31,6 @@ public abstract class ServerToClientMessage { return instantiateMakeChanges(json, pushedAt); else if (TYPE_ACKNOWLEDGE_CHANGE.equals(type)) return new AcknowledgeChange(json); - else if (TYPE_USER_DATA.equals(type)) - return new UserData(json); else if (TYPE_DOUBLE_CHECK.equals(json)) return new DoubleCheck(json); else if (TYPE_DEBUG.equals(json)) @@ -46,6 +45,8 @@ public abstract class ServerToClientMessage { return new MakeChanges(json, PluginServices.getTaskDao(), pushedAt); else if (NameMaps.TABLE_ID_TAGS.equals(table)) return new MakeChanges(json, PluginServices.getTagDataDao(), pushedAt); + else if (NameMaps.TABLE_ID_USERS.equals(table)) + return new MakeChanges(json, PluginServices.getUserDao(), pushedAt); else if (NameMaps.TABLE_ID_PUSHED_AT.equals(table)) return new MakeChanges(json, null, 0); else diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/UserData.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/UserData.java deleted file mode 100644 index 252f68ac6..000000000 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/messages/UserData.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.todoroo.astrid.actfm.sync.messages; - -import java.util.Iterator; - -import org.json.JSONException; -import org.json.JSONObject; - -import android.util.Log; - -import com.todoroo.andlib.data.Property; -import com.todoroo.andlib.data.Property.StringProperty; -import com.todoroo.astrid.core.PluginServices; -import com.todoroo.astrid.dao.UserDao; -import com.todoroo.astrid.data.RemoteModel; -import com.todoroo.astrid.data.SyncFlags; -import com.todoroo.astrid.data.User; - -public class UserData extends ServerToClientMessage { - - private static final String ERROR_TAG = "actfm-user-data"; //$NON-NLS-1$ - - public UserData(JSONObject json) { - super(json); - } - - @Override - public void processMessage() { - UserDao userDao = PluginServices.getUserDao(); - try { - String uuid = json.getString("uuid"); //$NON-NLS-1$ - User model = new User(); - JSONChangeToPropertyVisitor visitor = new JSONChangeToPropertyVisitor(model, json); - Iterator keys = json.keys(); - while (keys.hasNext()) { - String column = keys.next(); - Property property = NameMaps.serverColumnNameToLocalProperty(NameMaps.TABLE_ID_USERS, column); - if (property != null) { // Unsupported property - property.accept(visitor, column); - } - } - - StringProperty uuidProperty = (StringProperty) NameMaps.serverColumnNameToLocalProperty(NameMaps.TABLE_ID_USERS, "uuid"); //$NON-NLS-1$ - if (!model.getSetValues().containsKey(uuidProperty.name)) - model.setValue(uuidProperty, uuid); - - if (model.getSetValues().size() > 0) { - if (userDao.update(RemoteModel.UUID_PROPERTY.eq(uuid), model) <= 0) { // If update doesn't update rows. create a new model - model.putTransitory(SyncFlags.ACTFM_SUPPRESS_OUTSTANDING_ENTRIES, true); - userDao.createNew(model); - } - } - } catch (JSONException e) { - Log.e(ERROR_TAG, "Error parsing UserData JSON " + json, e); //$NON-NLS-1$ - } - } - -} diff --git a/astrid/src/com/todoroo/astrid/dao/UserDao.java b/astrid/src/com/todoroo/astrid/dao/UserDao.java index db6ee3443..7276e7e67 100644 --- a/astrid/src/com/todoroo/astrid/dao/UserDao.java +++ b/astrid/src/com/todoroo/astrid/dao/UserDao.java @@ -5,12 +5,11 @@ */ package com.todoroo.astrid.dao; -import com.todoroo.andlib.data.DatabaseDao; import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.astrid.data.User; -public class UserDao extends DatabaseDao { +public class UserDao extends RemoteModelDao { @Autowired Database database; @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="UR_UNINIT_READ")