Refactored some task criteria into the api dao, check for task ownership when syncing

pull/14/head
Sam Bosley 13 years ago
parent 846eb66a9e
commit 0cb3ef8a1c

@ -8,6 +8,7 @@ import com.todoroo.andlib.data.ContentResolverDao;
import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Field;
import com.todoroo.andlib.sql.Functions; import com.todoroo.andlib.sql.Functions;
import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.sql.Query;
import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridApiConstants;
@ -91,6 +92,23 @@ public class TaskApiDao extends ContentResolverDao<Task> {
return Criterion.or(Task.TITLE.isNull(), Task.TITLE.eq("")); 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));
}
} }
/** /**

@ -81,7 +81,7 @@ abstract public class SyncMetadataService<TYPE extends SyncContainer> {
*/ */
public TodorooCursor<Task> getLocallyCreated(Property<?>... properties) { public TodorooCursor<Task> getLocallyCreated(Property<?>... properties) {
TodorooCursor<Task> tasks = taskDao.query(Query.select(Task.ID).where( TodorooCursor<Task> 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); return joinWithMetadata(tasks, false, properties);
} }
@ -97,8 +97,8 @@ abstract public class SyncMetadataService<TYPE extends SyncContainer> {
if(lastSyncDate == 0) if(lastSyncDate == 0)
tasks = taskDao.query(Query.select(Task.ID).where(Criterion.none)); tasks = taskDao.query(Query.select(Task.ID).where(Criterion.none));
else else
tasks = taskDao.query(Query.select(Task.ID).where( tasks = taskDao.query(Query.select(Task.ID).where(Criterion.and(TaskCriteria.ownedByMe(), Task.MODIFICATION_DATE.gt(lastSyncDate)))
Task.MODIFICATION_DATE.gt(lastSyncDate)).orderBy(Order.asc(Task.ID))); .orderBy(Order.asc(Task.ID)));
tasks = filterLocallyUpdated(tasks, lastSyncDate); tasks = filterLocallyUpdated(tasks, lastSyncDate);
return joinWithMetadata(tasks, true, properties); return joinWithMetadata(tasks, true, properties);

@ -20,9 +20,9 @@ import com.todoroo.astrid.api.AstridFilterExposer;
import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.FilterListItem; import com.todoroo.astrid.api.FilterListItem;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria; 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.Metadata;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.TaskApiDao.TaskCriteria;
import com.todoroo.astrid.tags.TagService; import com.todoroo.astrid.tags.TagService;
/** /**

@ -46,8 +46,8 @@ import com.todoroo.astrid.api.MultipleSelectCriterion;
import com.todoroo.astrid.api.PermaSql; import com.todoroo.astrid.api.PermaSql;
import com.todoroo.astrid.api.TextInputCriterion; import com.todoroo.astrid.api.TextInputCriterion;
import com.todoroo.astrid.dao.Database; import com.todoroo.astrid.dao.Database;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.TaskApiDao.TaskCriteria;
import com.todoroo.astrid.service.StatisticsService; import com.todoroo.astrid.service.StatisticsService;
/** /**

@ -31,9 +31,9 @@ import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.FilterListItem; import com.todoroo.astrid.api.FilterListItem;
import com.todoroo.astrid.api.PermaSql; import com.todoroo.astrid.api.PermaSql;
import com.todoroo.astrid.dao.StoreObjectDao; import com.todoroo.astrid.dao.StoreObjectDao;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.data.StoreObject; import com.todoroo.astrid.data.StoreObject;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.TaskApiDao.TaskCriteria;
import com.todoroo.astrid.gtasks.GtasksPreferenceService; import com.todoroo.astrid.gtasks.GtasksPreferenceService;
import com.todoroo.astrid.service.TagDataService; import com.todoroo.astrid.service.TagDataService;
import com.todoroo.astrid.tags.TagService; import com.todoroo.astrid.tags.TagService;

@ -25,6 +25,7 @@ import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.data.TaskApiDao;
import com.todoroo.astrid.utility.Constants; import com.todoroo.astrid.utility.Constants;
@ -483,7 +484,7 @@ public final class ReminderService {
private TodorooCursor<Task> getTasksWithReminders(Property<?>... properties) { private TodorooCursor<Task> getTasksWithReminders(Property<?>... properties) {
return taskDao.query(Query.select(properties).where(Criterion.and( return taskDao.query(Query.select(properties).where(Criterion.and(
TaskCriteria.isActive(), TaskCriteria.isActive(),
TaskCriteria.ownedByMe(), TaskApiDao.TaskCriteria.ownedByMe(),
Criterion.or(Task.REMINDER_FLAGS.gt(0), Task.REMINDER_PERIOD.gt(0))))); Criterion.or(Task.REMINDER_FLAGS.gt(0), Task.REMINDER_PERIOD.gt(0)))));
} }

@ -30,6 +30,7 @@ import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Metadata;
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.TaskApiDao;
import com.todoroo.astrid.data.Update; import com.todoroo.astrid.data.Update;
import com.todoroo.astrid.service.MetadataService; import com.todoroo.astrid.service.MetadataService;
import com.todoroo.astrid.service.TagDataService; import com.todoroo.astrid.service.TagDataService;
@ -145,7 +146,7 @@ public final class TagService {
return new QueryTemplate().where(Criterion.and( return new QueryTemplate().where(Criterion.and(
Criterion.not(Task.ID.in(Query.select(Metadata.TASK).from(Metadata.TABLE).where(MetadataCriteria.withKey(KEY)))), Criterion.not(Task.ID.in(Query.select(Metadata.TASK).from(Metadata.TABLE).where(MetadataCriteria.withKey(KEY)))),
TaskCriteria.isActive(), TaskCriteria.isActive(),
TaskCriteria.ownedByMe(), TaskApiDao.TaskCriteria.ownedByMe(),
TaskCriteria.isVisible())); TaskCriteria.isVisible()));
} }

@ -12,7 +12,6 @@ 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.andlib.sql.Criterion; import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Field;
import com.todoroo.andlib.sql.Functions; import com.todoroo.andlib.sql.Functions;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.Preferences; import com.todoroo.andlib.utility.Preferences;
@ -63,13 +62,6 @@ public class TaskDao extends DatabaseDao<Task> {
return Task.DELETION_DATE.neq(0); 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 */ /** @return tasks that were not deleted */
public static Criterion notDeleted() { public static Criterion notDeleted() {
return Task.DELETION_DATE.eq(0); return Task.DELETION_DATE.eq(0);
@ -82,16 +74,6 @@ public class TaskDao extends DatabaseDao<Task> {
Task.HIDE_UNTIL.lt(Functions.now())); 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 */ /** @return tasks that have not yet been completed or deleted */
public static Criterion isActive() { public static Criterion isActive() {
return Criterion.and(Task.COMPLETION_DATE.eq(0), return Criterion.and(Task.COMPLETION_DATE.eq(0),

Loading…
Cancel
Save