Removed dead code, don't drop rows when synchronizing tag metadata

pull/14/head
Sam Bosley 12 years ago
parent f4f22a43ae
commit ebb3c402e6

@ -5,8 +5,6 @@
*/ */
package com.todoroo.astrid.actfm.sync; package com.todoroo.astrid.actfm.sync;
import java.util.ArrayList;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@ -33,7 +31,6 @@ import com.todoroo.astrid.data.User;
import com.todoroo.astrid.notes.NoteMetadata; import com.todoroo.astrid.notes.NoteMetadata;
import com.todoroo.astrid.service.MetadataService; import com.todoroo.astrid.service.MetadataService;
import com.todoroo.astrid.service.TagDataService; import com.todoroo.astrid.service.TagDataService;
import com.todoroo.astrid.tags.TagMetadata;
import com.todoroo.astrid.tags.TagService; import com.todoroo.astrid.tags.TagService;
public final class ActFmDataService { public final class ActFmDataService {
@ -102,65 +99,6 @@ public final class ActFmDataService {
Task.MODIFICATION_DATE.gt(Task.LAST_SYNC))).groupBy(Task.ID)); Task.MODIFICATION_DATE.gt(Task.LAST_SYNC))).groupBy(Task.ID));
} }
/**
* Searches for a local task with same remote id, updates this task's id
* @param remoteTask
* @return true if found local match
*/
public boolean findLocalMatch(ActFmTaskContainer remoteTask) {
if(remoteTask.task.getId() != Task.NO_ID)
return true;
TodorooCursor<Task> cursor = taskDao.query(Query.select(Task.ID).
where(Task.REMOTE_ID.eq(remoteTask.task.getValue(Task.REMOTE_ID))));
try {
if(cursor.getCount() == 0)
return false;
cursor.moveToFirst();
remoteTask.task.setId(cursor.get(Task.ID));
return true;
} finally {
cursor.close();
}
}
/**
* Saves a task and its metadata
* @param task
*/
public void saveTaskAndMetadata(ActFmTaskContainer task) {
taskDao.save(task.task);
metadataService.synchronizeMetadata(task.task.getId(), task.metadata,
Criterion.or(Criterion.and(MetadataCriteria.withKey(NoteMetadata.METADATA_KEY),
NoteMetadata.EXT_PROVIDER.eq(NOTE_PROVIDER)),
MetadataCriteria.withKey(TagMetadata.KEY)));
}
/**
* Reads a task and its metadata
* @param task
* @return
*/
public ActFmTaskContainer readTaskAndMetadata(TodorooCursor<Task> taskCursor) {
Task task = new Task(taskCursor);
// read tags, notes, etc
ArrayList<Metadata> metadata = new ArrayList<Metadata>();
TodorooCursor<Metadata> metadataCursor = metadataService.query(Query.select(Metadata.PROPERTIES).
where(Criterion.and(MetadataCriteria.byTask(task.getId()),
Criterion.or(MetadataCriteria.withKey(TagMetadata.KEY),
MetadataCriteria.withKey(NoteMetadata.METADATA_KEY)))));
try {
for(metadataCursor.moveToFirst(); !metadataCursor.isAfterLast(); metadataCursor.moveToNext()) {
metadata.add(new Metadata(metadataCursor));
}
} finally {
metadataCursor.close();
}
return new ActFmTaskContainer(task, metadata);
}
/** /**
* Reads task notes out of a task * Reads task notes out of a task
*/ */

@ -818,7 +818,7 @@ public final class ActFmSyncService {
JsonHelper.taskFromJson(result, task, metadata); JsonHelper.taskFromJson(result, task, metadata);
task.putTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC, true); task.putTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC, true);
taskService.save(task); taskService.save(task);
metadataService.synchronizeMetadata(task.getId(), metadata, Metadata.KEY.eq(TagMetadata.KEY)); metadataService.synchronizeMetadata(task.getId(), metadata, Metadata.KEY.eq(TagMetadata.KEY), false);
synchronizeAttachments(result, task); synchronizeAttachments(result, task);
} }
@ -1253,7 +1253,7 @@ public final class ActFmSyncService {
} }
ids.add(remote.getId()); ids.add(remote.getId());
metadataService.synchronizeMetadata(remote.getId(), metadata, MetadataCriteria.withKey(TagMetadata.KEY)); metadataService.synchronizeMetadata(remote.getId(), metadata, MetadataCriteria.withKey(TagMetadata.KEY), false);
synchronizeAttachments(item, remote); synchronizeAttachments(item, remote);
remote.clear(); remote.clear();
} }
@ -1574,10 +1574,7 @@ public final class ActFmSyncService {
String name = tag.getString("name"); String name = tag.getString("name");
if(TextUtils.isEmpty(name)) if(TextUtils.isEmpty(name))
continue; continue;
Metadata tagMetadata = new Metadata(); Metadata tagMetadata = TagMetadata.newTagMetadata(model.getId(), remoteId, name, tag.getLong("id"));
tagMetadata.setValue(Metadata.KEY, TagMetadata.KEY);
tagMetadata.setValue(TagMetadata.TAG_NAME, name);
tagMetadata.setValue(TagMetadata.TAG_UUID, tag.getLong("id"));
metadata.add(tagMetadata); metadata.add(tagMetadata);
} }
} }

@ -1,62 +0,0 @@
/**
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.actfm.sync;
import java.util.ArrayList;
import java.util.Date;
import org.json.JSONObject;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.notes.NoteMetadata;
import com.todoroo.astrid.sync.SyncContainer;
/**
* RTM Task Container
*
* @author Tim Su <tim@todoroo.com>
*
*/
public class ActFmTaskContainer extends SyncContainer {
public ActFmTaskContainer(Task task, ArrayList<Metadata> metadata) {
this.task = task;
this.metadata = metadata;
}
@SuppressWarnings("nls")
public ActFmTaskContainer(Task task, ArrayList<Metadata> metadata, JSONObject remoteTask) {
this(task, metadata);
task.setValue(Task.REMOTE_ID, remoteTask.optLong("id"));
}
/** create note metadata from comment json object */
@SuppressWarnings("nls")
public static Metadata newNoteMetadata(JSONObject comment) {
Metadata metadata = new Metadata();
metadata.setValue(Metadata.KEY, NoteMetadata.METADATA_KEY);
metadata.setValue(NoteMetadata.EXT_ID, comment.optString("id"));
metadata.setValue(NoteMetadata.EXT_PROVIDER,
ActFmDataService.NOTE_PROVIDER);
Date creationDate = new Date(comment.optInt("date") * 1000L);
metadata.setValue(Metadata.CREATION_DATE, creationDate.getTime());
metadata.setValue(NoteMetadata.BODY, comment.optString("message"));
JSONObject owner = comment.optJSONObject("owner");
metadata.setValue(NoteMetadata.THUMBNAIL, owner.optString("picture"));
String title = String.format("%s on %s",
owner.optString("name"),
DateUtilities.getDateString(ContextManager.getContext(), creationDate));
metadata.setValue(NoteMetadata.TITLE, title);
return metadata;
}
}

@ -94,7 +94,7 @@ public class AlarmService {
PendingIntent pendingIntent = pendingIntentForAlarm(m, taskId); PendingIntent pendingIntent = pendingIntentForAlarm(m, taskId);
am.cancel(pendingIntent); am.cancel(pendingIntent);
} }
}); }, true);
if(changed) if(changed)
scheduleAlarms(taskId); scheduleAlarms(taskId);

@ -157,7 +157,7 @@ public final class ProducteevDataService {
// note we don't include note metadata, since we only receive deltas // note we don't include note metadata, since we only receive deltas
metadataService.synchronizeMetadata(task.task.getId(), task.metadata, metadataService.synchronizeMetadata(task.task.getId(), task.metadata,
Criterion.or(MetadataCriteria.withKey(ProducteevTask.METADATA_KEY), Criterion.or(MetadataCriteria.withKey(ProducteevTask.METADATA_KEY),
MetadataCriteria.withKey(TagMetadata.KEY))); MetadataCriteria.withKey(TagMetadata.KEY)), true);
} }
/** /**

@ -40,7 +40,7 @@ public class Astrid44SyncMigrator {
} }
@SuppressWarnings("nls") @SuppressWarnings("nls")
public void migrateTagMetadataToTable() { public void performMigration() {
if (Preferences.getBoolean(PREF_MIGRATED_TASKS_TO_TAGS, false)) if (Preferences.getBoolean(PREF_MIGRATED_TASKS_TO_TAGS, false))
return; return;

@ -60,7 +60,7 @@ public final class TaskRabbitDataService {
task.metadata.add(task.trTask); task.metadata.add(task.trTask);
// note we don't include note metadata, since we only receive deltas // note we don't include note metadata, since we only receive deltas
metadataService.synchronizeMetadata(task.task.getId(), task.metadata, metadataService.synchronizeMetadata(task.task.getId(), task.metadata,
MetadataCriteria.withKey(TaskRabbitMetadata.METADATA_KEY)); MetadataCriteria.withKey(TaskRabbitMetadata.METADATA_KEY), true);
} }
/** /**

@ -106,7 +106,7 @@ public class MetadataService {
* @return true if there were changes * @return true if there were changes
*/ */
public boolean synchronizeMetadata(long taskId, ArrayList<Metadata> metadata, public boolean synchronizeMetadata(long taskId, ArrayList<Metadata> metadata,
Criterion metadataCriterion, SynchronizeMetadataCallback callback) { Criterion metadataCriterion, SynchronizeMetadataCallback callback, boolean hardDelete) {
boolean dirty = false; boolean dirty = false;
HashSet<ContentValues> newMetadataValues = new HashSet<ContentValues>(); HashSet<ContentValues> newMetadataValues = new HashSet<ContentValues>();
for(Metadata metadatum : metadata) { for(Metadata metadatum : metadata) {
@ -142,11 +142,16 @@ public class MetadataService {
} }
// not matched. cut it // not matched. cut it
item.setId(id);
if (callback != null) { if (callback != null) {
item.setId(id);
callback.beforeDeleteMetadata(item); callback.beforeDeleteMetadata(item);
} }
metadataDao.delete(id); if (hardDelete)
metadataDao.delete(id);
else {
item.setValue(Metadata.DELETION_DATE, DateUtilities.now());
metadataDao.persist(item);
}
dirty = true; dirty = true;
} }
} finally { } finally {
@ -166,8 +171,8 @@ public class MetadataService {
} }
public boolean synchronizeMetadata(long taskId, ArrayList<Metadata> metadata, public boolean synchronizeMetadata(long taskId, ArrayList<Metadata> metadata,
Criterion metadataCriterion) { Criterion metadataCriterion, boolean hardDelete) {
return synchronizeMetadata(taskId, metadata, metadataCriterion, null); return synchronizeMetadata(taskId, metadata, metadataCriterion, null, hardDelete);
} }
/** /**

@ -198,7 +198,7 @@ public final class UpgradeService {
new DueDateTimeMigrator().migrateDueTimes(); new DueDateTimeMigrator().migrateDueTimes();
if (from < V4_4_0) if (from < V4_4_0)
new Astrid44SyncMigrator().migrateTagMetadataToTable(); new Astrid44SyncMigrator().performMigration();
} finally { } finally {
DialogUtilities.dismissDialog((Activity)context, dialog); DialogUtilities.dismissDialog((Activity)context, dialog);

Loading…
Cancel
Save