From 0cb3ef8a1ca483b01ba408226b0ae353ea9c1b95 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Wed, 4 Jan 2012 19:43:57 -0800 Subject: [PATCH] Refactored some task criteria into the api dao, check for task ownership when syncing --- .../com/todoroo/astrid/data/TaskApiDao.java | 18 ++++++++++++++++++ .../astrid/sync/SyncMetadataService.java | 6 +++--- .../todoroo/astrid/core/CoreFilterExposer.java | 2 +- .../astrid/core/CustomFilterActivity.java | 2 +- .../astrid/core/CustomFilterExposer.java | 2 +- .../astrid/reminders/ReminderService.java | 3 ++- .../com/todoroo/astrid/tags/TagService.java | 3 ++- astrid/src/com/todoroo/astrid/dao/TaskDao.java | 18 ------------------ 8 files changed, 28 insertions(+), 26 deletions(-) diff --git a/api/src/com/todoroo/astrid/data/TaskApiDao.java b/api/src/com/todoroo/astrid/data/TaskApiDao.java index a00b4c19f..c09237eb5 100644 --- a/api/src/com/todoroo/astrid/data/TaskApiDao.java +++ b/api/src/com/todoroo/astrid/data/TaskApiDao.java @@ -8,6 +8,7 @@ import com.todoroo.andlib.data.ContentResolverDao; import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.sql.Criterion; +import com.todoroo.andlib.sql.Field; import com.todoroo.andlib.sql.Functions; import com.todoroo.andlib.sql.Query; import com.todoroo.astrid.api.AstridApiConstants; @@ -91,6 +92,23 @@ public class TaskApiDao extends ContentResolverDao { return Criterion.or(Task.TITLE.isNull(), Task.TITLE.eq("")); } + /** @return tasks that have not yet been completed or deleted */ + public static Criterion activeVisibleMine() { + return Criterion.and(Task.COMPLETION_DATE.eq(0), + Task.DELETION_DATE.eq(0), + Task.HIDE_UNTIL.lt(Functions.now()), + Field.field(Task.FLAGS.name + " & " + //$NON-NLS-1$ + Task.FLAG_IS_READONLY).eq(0), + Task.USER_ID.eq(0)); + } + + /** Check if a given task belongs to someone else & is read-only */ + public static Criterion ownedByMe() { + return Criterion.and(Field.field(Task.FLAGS.name+ " & " + //$NON-NLS-1$ + Task.FLAG_IS_READONLY).eq(0), + Task.USER_ID.eq(0)); + } + } /** diff --git a/api/src/com/todoroo/astrid/sync/SyncMetadataService.java b/api/src/com/todoroo/astrid/sync/SyncMetadataService.java index 6bfda336a..bef3a3b4c 100644 --- a/api/src/com/todoroo/astrid/sync/SyncMetadataService.java +++ b/api/src/com/todoroo/astrid/sync/SyncMetadataService.java @@ -81,7 +81,7 @@ abstract public class SyncMetadataService { */ public TodorooCursor getLocallyCreated(Property... properties) { TodorooCursor tasks = taskDao.query(Query.select(Task.ID).where( - TaskCriteria.isActive()).orderBy(Order.asc(Task.ID))); + Criterion.and(TaskCriteria.isActive(), TaskCriteria.ownedByMe())).orderBy(Order.asc(Task.ID))); return joinWithMetadata(tasks, false, properties); } @@ -97,8 +97,8 @@ abstract public class SyncMetadataService { if(lastSyncDate == 0) tasks = taskDao.query(Query.select(Task.ID).where(Criterion.none)); else - tasks = taskDao.query(Query.select(Task.ID).where( - Task.MODIFICATION_DATE.gt(lastSyncDate)).orderBy(Order.asc(Task.ID))); + tasks = taskDao.query(Query.select(Task.ID).where(Criterion.and(TaskCriteria.ownedByMe(), Task.MODIFICATION_DATE.gt(lastSyncDate))) + .orderBy(Order.asc(Task.ID))); tasks = filterLocallyUpdated(tasks, lastSyncDate); return joinWithMetadata(tasks, true, properties); diff --git a/astrid/plugin-src/com/todoroo/astrid/core/CoreFilterExposer.java b/astrid/plugin-src/com/todoroo/astrid/core/CoreFilterExposer.java index 78a7209a9..703a792ba 100644 --- a/astrid/plugin-src/com/todoroo/astrid/core/CoreFilterExposer.java +++ b/astrid/plugin-src/com/todoroo/astrid/core/CoreFilterExposer.java @@ -20,9 +20,9 @@ import com.todoroo.astrid.api.AstridFilterExposer; import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.FilterListItem; import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria; -import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Task; +import com.todoroo.astrid.data.TaskApiDao.TaskCriteria; import com.todoroo.astrid.tags.TagService; /** diff --git a/astrid/plugin-src/com/todoroo/astrid/core/CustomFilterActivity.java b/astrid/plugin-src/com/todoroo/astrid/core/CustomFilterActivity.java index 0f9e48230..46cf6bf83 100644 --- a/astrid/plugin-src/com/todoroo/astrid/core/CustomFilterActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/core/CustomFilterActivity.java @@ -46,8 +46,8 @@ import com.todoroo.astrid.api.MultipleSelectCriterion; import com.todoroo.astrid.api.PermaSql; import com.todoroo.astrid.api.TextInputCriterion; import com.todoroo.astrid.dao.Database; -import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.data.Task; +import com.todoroo.astrid.data.TaskApiDao.TaskCriteria; import com.todoroo.astrid.service.StatisticsService; /** diff --git a/astrid/plugin-src/com/todoroo/astrid/core/CustomFilterExposer.java b/astrid/plugin-src/com/todoroo/astrid/core/CustomFilterExposer.java index 74eb3af26..ea2f2498b 100644 --- a/astrid/plugin-src/com/todoroo/astrid/core/CustomFilterExposer.java +++ b/astrid/plugin-src/com/todoroo/astrid/core/CustomFilterExposer.java @@ -31,9 +31,9 @@ import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.FilterListItem; import com.todoroo.astrid.api.PermaSql; import com.todoroo.astrid.dao.StoreObjectDao; -import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.data.StoreObject; import com.todoroo.astrid.data.Task; +import com.todoroo.astrid.data.TaskApiDao.TaskCriteria; import com.todoroo.astrid.gtasks.GtasksPreferenceService; import com.todoroo.astrid.service.TagDataService; import com.todoroo.astrid.tags.TagService; diff --git a/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderService.java b/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderService.java index 6975e4b35..b6f65fae3 100644 --- a/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderService.java +++ b/astrid/plugin-src/com/todoroo/astrid/reminders/ReminderService.java @@ -25,6 +25,7 @@ import com.todoroo.andlib.utility.Preferences; import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.data.Task; +import com.todoroo.astrid.data.TaskApiDao; import com.todoroo.astrid.utility.Constants; @@ -483,7 +484,7 @@ public final class ReminderService { private TodorooCursor getTasksWithReminders(Property... properties) { return taskDao.query(Query.select(properties).where(Criterion.and( TaskCriteria.isActive(), - TaskCriteria.ownedByMe(), + TaskApiDao.TaskCriteria.ownedByMe(), Criterion.or(Task.REMINDER_FLAGS.gt(0), Task.REMINDER_PERIOD.gt(0))))); } diff --git a/astrid/plugin-src/com/todoroo/astrid/tags/TagService.java b/astrid/plugin-src/com/todoroo/astrid/tags/TagService.java index 85cfbce82..1140edb74 100644 --- a/astrid/plugin-src/com/todoroo/astrid/tags/TagService.java +++ b/astrid/plugin-src/com/todoroo/astrid/tags/TagService.java @@ -30,6 +30,7 @@ import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.Task; +import com.todoroo.astrid.data.TaskApiDao; import com.todoroo.astrid.data.Update; import com.todoroo.astrid.service.MetadataService; import com.todoroo.astrid.service.TagDataService; @@ -145,7 +146,7 @@ public final class TagService { return new QueryTemplate().where(Criterion.and( Criterion.not(Task.ID.in(Query.select(Metadata.TASK).from(Metadata.TABLE).where(MetadataCriteria.withKey(KEY)))), TaskCriteria.isActive(), - TaskCriteria.ownedByMe(), + TaskApiDao.TaskCriteria.ownedByMe(), TaskCriteria.isVisible())); } diff --git a/astrid/src/com/todoroo/astrid/dao/TaskDao.java b/astrid/src/com/todoroo/astrid/dao/TaskDao.java index d5eef5647..b6faa8b43 100644 --- a/astrid/src/com/todoroo/astrid/dao/TaskDao.java +++ b/astrid/src/com/todoroo/astrid/dao/TaskDao.java @@ -12,7 +12,6 @@ import com.todoroo.andlib.data.DatabaseDao; import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.sql.Criterion; -import com.todoroo.andlib.sql.Field; import com.todoroo.andlib.sql.Functions; import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.Preferences; @@ -63,13 +62,6 @@ public class TaskDao extends DatabaseDao { return Task.DELETION_DATE.neq(0); } - /** Check if a given task belongs to someone else & is read-only */ - public static Criterion ownedByMe() { - return Criterion.and(Field.field(Task.FLAGS.name+ " & " + //$NON-NLS-1$ - Task.FLAG_IS_READONLY).eq(0), - Task.USER_ID.eq(0)); - } - /** @return tasks that were not deleted */ public static Criterion notDeleted() { return Task.DELETION_DATE.eq(0); @@ -82,16 +74,6 @@ public class TaskDao extends DatabaseDao { Task.HIDE_UNTIL.lt(Functions.now())); } - /** @return tasks that have not yet been completed or deleted */ - public static Criterion activeVisibleMine() { - return Criterion.and(Task.COMPLETION_DATE.eq(0), - Task.DELETION_DATE.eq(0), - Task.HIDE_UNTIL.lt(Functions.now()), - Field.field(Task.FLAGS.name + " & " + //$NON-NLS-1$ - Task.FLAG_IS_READONLY).eq(0), - Task.USER_ID.eq(0)); - } - /** @return tasks that have not yet been completed or deleted */ public static Criterion isActive() { return Criterion.and(Task.COMPLETION_DATE.eq(0),