diff --git a/astrid/plugin-src/com/todoroo/astrid/taskrabbit/TaskRabbitDataService.java b/astrid/plugin-src/com/todoroo/astrid/taskrabbit/TaskRabbitDataService.java index ca5d72e22..de196c1b2 100644 --- a/astrid/plugin-src/com/todoroo/astrid/taskrabbit/TaskRabbitDataService.java +++ b/astrid/plugin-src/com/todoroo/astrid/taskrabbit/TaskRabbitDataService.java @@ -4,41 +4,23 @@ package com.todoroo.astrid.taskrabbit; import java.util.ArrayList; -import java.util.Random; import android.content.Context; -import com.todoroo.andlib.data.Property; import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.sql.Criterion; -import com.todoroo.andlib.sql.Join; import com.todoroo.andlib.sql.Query; -import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria; -import com.todoroo.astrid.dao.StoreObjectDao; -import com.todoroo.astrid.dao.StoreObjectDao.StoreObjectCriteria; import com.todoroo.astrid.dao.TaskDao; -import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.data.Metadata; -import com.todoroo.astrid.data.StoreObject; import com.todoroo.astrid.data.Task; -import com.todoroo.astrid.notes.NoteMetadata; -import com.todoroo.astrid.producteev.ProducteevUtilities; -import com.todoroo.astrid.producteev.sync.ProducteevDashboard; import com.todoroo.astrid.service.MetadataService; public final class TaskRabbitDataService { - // --- constants - - /** Utility for joining tasks with metadata */ - public static final Join METADATA_JOIN = Join.left(Metadata.TABLE, Task.ID.eq(Metadata.TASK)); - - /** NoteMetadata provider string */ - public static final String NOTE_PROVIDER = "taskrabbit"; //$NON-NLS-1$ // --- singleton @@ -60,13 +42,6 @@ public final class TaskRabbitDataService { @Autowired private MetadataService metadataService; - @Autowired - private StoreObjectDao storeObjectDao; - - private final ProducteevUtilities preferences = ProducteevUtilities.INSTANCE; - - static final Random random = new Random(); - private TaskRabbitDataService(Context context) { this.context = context; DependencyInjectionService.getInstance().inject(this); @@ -74,71 +49,6 @@ public final class TaskRabbitDataService { // --- task and metadata methods - /** - * Clears metadata information. Used when user logs out of service - */ - public void clearMetadata() { - PluginServices.getTaskService().clearDetails(Task.ID.in(Query.select(Metadata.TASK).from(Metadata.TABLE). - where(MetadataCriteria.withKey(TaskRabbitMetadata.METADATA_KEY)))); - metadataService.deleteWhere(Metadata.KEY.eq(TaskRabbitMetadata.METADATA_KEY)); - storeObjectDao.deleteWhere(StoreObject.TYPE.eq(ProducteevDashboard.TYPE)); - } - - /** - * Gets tasks that were created since last sync - * @param properties - * @return - */ - public TodorooCursor getLocallyCreated(Property[] properties) { - return - taskDao.query(Query.select(properties).join(TaskRabbitDataService.METADATA_JOIN).where( - Criterion.and( - Criterion.not(Task.ID.in(Query.select(Metadata.TASK).from(Metadata.TABLE). - where(Criterion.and(MetadataCriteria.withKey(TaskRabbitMetadata.METADATA_KEY), TaskRabbitMetadata.ID.gt(0))))), - TaskCriteria.isActive())). - groupBy(Task.ID)); - } - - /** - * Gets tasks that were modified since last sync - * @param properties - * @return null if never sync'd - */ - public TodorooCursor getLocallyUpdated(Property[] properties) { - long lastSyncDate = preferences.getLastSyncDate(); - if(lastSyncDate == 0) - return taskDao.query(Query.select(Task.ID).where(Criterion.none)); - return - taskDao.query(Query.select(properties).join(TaskRabbitDataService.METADATA_JOIN).where( - Criterion.and( - MetadataCriteria.withKey(TaskRabbitMetadata.METADATA_KEY), - TaskRabbitMetadata.ID.gt(0), - Task.MODIFICATION_DATE.gt(lastSyncDate))). - 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(TaskRabbitTaskContainer remoteTask) { - if(remoteTask.task.getId() != Task.NO_ID) - return true; - TodorooCursor cursor = taskDao.query(Query.select(Task.ID). - join(TaskRabbitDataService.METADATA_JOIN).where(Criterion.and(MetadataCriteria.withKey(TaskRabbitMetadata.METADATA_KEY), - TaskRabbitMetadata.ID.eq(remoteTask.trTask.getValue(TaskRabbitMetadata.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 @@ -175,52 +85,4 @@ public final class TaskRabbitDataService { return new TaskRabbitTaskContainer(task, metadata.get(0)); } - /** - * Reads metadata out of a task - * @return null if no metadata found - */ - public Metadata getTaskMetadata(long taskId) { - TodorooCursor cursor = metadataService.query(Query.select( - Metadata.PROPERTIES).where( - MetadataCriteria.byTaskAndwithKey(taskId, TaskRabbitMetadata.METADATA_KEY))); - try { - if(cursor.getCount() == 0) - return null; - cursor.moveToFirst(); - return new Metadata(cursor); - } finally { - cursor.close(); - } - } - - /** - * Reads task notes out of a task - */ - public TodorooCursor getTaskNotesCursor(long taskId) { - TodorooCursor cursor = metadataService.query(Query.select(Metadata.PROPERTIES). - where(MetadataCriteria.byTaskAndwithKey(taskId, NoteMetadata.METADATA_KEY))); - return cursor; - } - - /** - * Reads store objects. - */ - public StoreObject[] readStoreObjects(String type) { - StoreObject[] ret; - TodorooCursor cursor = storeObjectDao.query(Query.select(StoreObject.PROPERTIES). - where(StoreObjectCriteria.byType(type))); - try { - ret = new StoreObject[cursor.getCount()]; - for(int i = 0; i < ret.length; i++) { - cursor.moveToNext(); - StoreObject dashboard = new StoreObject(cursor); - ret[i] = dashboard; - } - } finally { - cursor.close(); - } - - return ret; - } - }