No more UserData messages, just normal MakeChanges for the users table instead

pull/14/head
Sam Bosley 12 years ago
parent 74f451bffd
commit d7d90cb72e

@ -6,6 +6,7 @@ import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.data.RemoteModel; import com.todoroo.astrid.data.RemoteModel;
import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.User;
@SuppressWarnings("nls") @SuppressWarnings("nls")
public abstract class ServerToClientMessage { public abstract class ServerToClientMessage {
@ -30,8 +31,6 @@ public abstract class ServerToClientMessage {
return instantiateMakeChanges(json, pushedAt); return instantiateMakeChanges(json, pushedAt);
else if (TYPE_ACKNOWLEDGE_CHANGE.equals(type)) else if (TYPE_ACKNOWLEDGE_CHANGE.equals(type))
return new AcknowledgeChange(json); return new AcknowledgeChange(json);
else if (TYPE_USER_DATA.equals(type))
return new UserData(json);
else if (TYPE_DOUBLE_CHECK.equals(json)) else if (TYPE_DOUBLE_CHECK.equals(json))
return new DoubleCheck(json); return new DoubleCheck(json);
else if (TYPE_DEBUG.equals(json)) else if (TYPE_DEBUG.equals(json))
@ -46,6 +45,8 @@ public abstract class ServerToClientMessage {
return new MakeChanges<Task>(json, PluginServices.getTaskDao(), pushedAt); return new MakeChanges<Task>(json, PluginServices.getTaskDao(), pushedAt);
else if (NameMaps.TABLE_ID_TAGS.equals(table)) else if (NameMaps.TABLE_ID_TAGS.equals(table))
return new MakeChanges<TagData>(json, PluginServices.getTagDataDao(), pushedAt); return new MakeChanges<TagData>(json, PluginServices.getTagDataDao(), pushedAt);
else if (NameMaps.TABLE_ID_USERS.equals(table))
return new MakeChanges<User>(json, PluginServices.getUserDao(), pushedAt);
else if (NameMaps.TABLE_ID_PUSHED_AT.equals(table)) else if (NameMaps.TABLE_ID_PUSHED_AT.equals(table))
return new MakeChanges<RemoteModel>(json, null, 0); return new MakeChanges<RemoteModel>(json, null, 0);
else else

@ -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<String> 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$
}
}
}

@ -5,12 +5,11 @@
*/ */
package com.todoroo.astrid.dao; package com.todoroo.astrid.dao;
import com.todoroo.andlib.data.DatabaseDao;
import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.astrid.data.User; import com.todoroo.astrid.data.User;
public class UserDao extends DatabaseDao<User> { public class UserDao extends RemoteModelDao<User> {
@Autowired Database database; @Autowired Database database;
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="UR_UNINIT_READ") @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="UR_UNINIT_READ")

Loading…
Cancel
Save