Remove dead code

pull/189/head
Alex Baker 11 years ago
parent f3139d45bd
commit 74f0ae9233

@ -7,8 +7,6 @@ package com.todoroo.astrid.gtasks;
import android.content.Context;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.service.MetadataService;
@ -53,7 +51,6 @@ public class GtasksMetadataServiceTest extends DatabaseTestCase {
private Task task;
private Metadata metadata;
private TodorooCursor<Task> cursor;
@Override
public void setUp() {
@ -80,82 +77,8 @@ public class GtasksMetadataServiceTest extends DatabaseTestCase {
thenExpectNoMetadataFound();
}
public void disabled_testLocallyCreatedHasItem() {
taskWithMetadata("ok");
givenTask(taskWithoutMetadata());
whenReadLocalCreated();
thenExpectCursorEquals(task);
}
public void disabled_testLocallyCreatedWhenEmptyMetadata() {
givenTask(taskWithMetadata(null));
whenReadLocalCreated();
thenExpectCursorEquals(task);
}
public void disabled_testLocallyCreatedIsEmpty() {
givenTask(taskWithMetadata("ok"));
whenReadLocalCreated();
thenExpectCursorIsEmpty();
}
public void disabled_testLocallyUpdatedHasItem() {
givenSyncDate(DateUtilities.now() - 5000L);
givenTask(taskWithMetadata("ok"));
whenReadLocalUpdated();
thenExpectCursorEquals(task);
}
public void testLocallyUpdatedIsEmptyWhenUpToDate() {
givenTask(taskWithMetadata("ok"));
givenSyncDate(DateUtilities.now());
whenReadLocalUpdated();
thenExpectCursorIsEmpty();
}
public void testLocallyUpdatedIsEmptyWhenNoUpdatedTasks() {
givenTask(taskWithMetadata(null));
whenReadLocalUpdated();
thenExpectCursorIsEmpty();
}
// --- helpers
private void givenSyncDate(long date) {
preferences.setSyncDate(date);
}
private void whenReadLocalUpdated() {
cursor = gtasksMetadataService.getLocallyUpdated(Task.ID);
}
private void thenExpectCursorIsEmpty() {
assertEquals("cursor is empty", 0, cursor.getCount());
}
private void thenExpectCursorEquals(Task expectedTask) {
assertEquals("cursor has one item", 1, cursor.getCount());
cursor.moveToFirst();
Task receivedTask = new Task(cursor);
assertEquals("task equals expected", expectedTask.getId(), receivedTask.getId());
}
private void whenReadLocalCreated() {
cursor = gtasksMetadataService.getLocallyCreated(Task.ID);
}
private void thenExpectNoMetadataFound() {
assertNull(metadata);
}

@ -23,10 +23,8 @@ import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.gtasks.sync.GtasksTaskContainer;
import com.todoroo.astrid.service.MetadataService;
import com.todoroo.astrid.subtasks.OrderedMetadataListUpdater.OrderedListIterator;
import com.todoroo.astrid.sync.SyncProviderUtilities;
import com.todoroo.astrid.utility.SyncMetadataService;
import java.util.HashSet;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
@ -43,13 +41,11 @@ import javax.inject.Singleton;
@Singleton
public final class GtasksMetadataService extends SyncMetadataService<GtasksTaskContainer> {
private final GtasksPreferenceService gtasksPreferenceService;
private MetadataService metadataService;
@Inject
public GtasksMetadataService(GtasksPreferenceService gtasksPreferenceService, TaskDao taskDao, MetadataDao metadataDao, MetadataService metadataService) {
public GtasksMetadataService(TaskDao taskDao, MetadataDao metadataDao, MetadataService metadataService) {
super(taskDao, metadataDao);
this.gtasksPreferenceService = gtasksPreferenceService;
this.metadataService = metadataService;
}
@ -67,16 +63,6 @@ public final class GtasksMetadataService extends SyncMetadataService<GtasksTaskC
return GtasksMetadata.METADATA_KEY;
}
@Override
public SyncProviderUtilities getUtilities() {
return gtasksPreferenceService;
}
@Override
public Criterion getMetadataWithRemoteId() {
return GtasksMetadata.ID.neq(""); //$NON-NLS-1$
}
public synchronized void findLocalMatch(GtasksTaskContainer remoteTask) {
if(remoteTask.task.getId() != Task.NO_ID) {
return;
@ -112,26 +98,8 @@ public final class GtasksMetadataService extends SyncMetadataService<GtasksTaskC
}
}
@Override
protected TodorooCursor<Task> filterLocallyUpdated(TodorooCursor<Task> tasks, long lastSyncDate) {
HashSet<Long> taskIds = new HashSet<>();
for(tasks.moveToFirst(); !tasks.isAfterLast(); tasks.moveToNext()) {
taskIds.add(tasks.get(Task.ID));
}
TodorooCursor<Metadata> metadata = metadataDao.query(Query.select(Metadata.TASK).where(
Criterion.and(MetadataCriteria.withKey(GtasksMetadata.METADATA_KEY),
GtasksMetadata.LAST_SYNC.gt(lastSyncDate))));
for(metadata.moveToFirst(); !metadata.isAfterLast(); metadata.moveToNext()) {
taskIds.remove(metadata.get(Metadata.TASK));
}
return taskDao.query(Query.select(Task.ID).where(Task.ID.in(taskIds)));
}
// --- list iterating helpers
public void iterateThroughList(StoreObject list, OrderedListIterator iterator) {
String listId = list.getValue(GtasksList.REMOTE_ID);
iterateThroughList(listId, iterator, 0, false);
@ -210,5 +178,4 @@ public final class GtasksMetadataService extends SyncMetadataService<GtasksTaskC
this.iterateThroughList(listId, iterator, gtasksMetadata.getValue(GtasksMetadata.ORDER), true);
return sibling.get();
}
}

@ -117,7 +117,6 @@ public class GtasksSyncService {
}
}
public void initialize() {
new OperationPushThread(operationQueue).start();

@ -5,21 +5,14 @@
*/
package com.todoroo.astrid.utility;
import com.todoroo.andlib.data.Property;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Order;
import com.todoroo.andlib.sql.Query;
import com.todoroo.astrid.dao.MetadataDao;
import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.dao.TaskDao.TaskCriteria;
import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.sync.SyncContainer;
import com.todoroo.astrid.sync.SyncProviderUtilities;
import java.util.ArrayList;
abstract public class SyncMetadataService<TYPE extends SyncContainer> {
@ -31,15 +24,9 @@ abstract public class SyncMetadataService<TYPE extends SyncContainer> {
/** @return metadata key identifying this sync provider's metadata */
abstract public String getMetadataKey();
/** @return sync provider utilities */
abstract public SyncProviderUtilities getUtilities();
/** @return criterion for matching all metadata keys that your provider synchronizes */
abstract public Criterion getMetadataCriteria();
/** @return criterion for matching metadata that indicate remote task exists */
abstract public Criterion getMetadataWithRemoteId();
// --- implementation
public SyncMetadataService(TaskDao taskDao, MetadataDao metadataDao) {
@ -54,103 +41,6 @@ abstract public class SyncMetadataService<TYPE extends SyncContainer> {
metadataDao.deleteWhere(Metadata.KEY.eq(getMetadataKey()));
}
/**
* Gets cursor across all task metadata for joining
*
* @return cursor
*/
private TodorooCursor<Metadata> getRemoteTaskMetadata() {
return metadataDao.query(Query.select(Metadata.TASK).where(
Criterion.and(MetadataCriteria.withKey(getMetadataKey()),
getMetadataWithRemoteId())).orderBy(Order.asc(Metadata.TASK)));
}
/**
* Gets tasks that were created since last sync
*/
public TodorooCursor<Task> getLocallyCreated(Property<?>... properties) {
TodorooCursor<Task> tasks = taskDao.query(Query.select(Task.ID).where(
Criterion.and(TaskCriteria.isActive(), TaskCriteria.ownedByMe())).orderBy(Order.asc(Task.ID)));
return joinWithMetadata(tasks, false, properties);
}
/**
* Gets tasks that were modified since last sync
* @return null if never sync'd
*/
public TodorooCursor<Task> getLocallyUpdated(Property<?>... properties) {
TodorooCursor<Task> tasks;
long lastSyncDate = getUtilities().getLastSyncDate();
if(lastSyncDate == 0) {
tasks = taskDao.query(Query.select(Task.ID).where(Criterion.none));
} else {
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);
}
protected TodorooCursor<Task> filterLocallyUpdated(TodorooCursor<Task> tasks, long lastSyncDate) {
// override hook
return tasks;
}
private TodorooCursor<Task> joinWithMetadata(TodorooCursor<Task> tasks,
boolean both, Property<?>... properties) {
try {
TodorooCursor<Metadata> metadata = getRemoteTaskMetadata();
try {
ArrayList<Long> matchingRows = new ArrayList<>();
joinRows(tasks, metadata, matchingRows, both);
return taskDao.query(Query.select(properties).where(Task.ID.in(matchingRows)));
} finally {
metadata.close();
}
} finally {
tasks.close();
}
}
/**
* Join rows from two cursors on the first column, assuming its an id column
* @param both - if false, returns rows no right row exists, if true,
* returns rows where both exist
*/
private static void joinRows(TodorooCursor<?> left,
TodorooCursor<?> right, ArrayList<Long> matchingRows,
boolean both) {
left.moveToPosition(-1);
right.moveToFirst();
while(true) {
left.moveToNext();
if(left.isAfterLast()) {
break;
}
long leftValue = left.getLong(0);
// advance right until it is equal or bigger
while(!right.isAfterLast() && right.getLong(0) < leftValue) {
right.moveToNext();
}
if(right.isAfterLast()) {
if(!both) {
matchingRows.add(leftValue);
}
continue;
}
if((right.getLong(0) == leftValue) == both) {
matchingRows.add(leftValue);
}
}
}
/**
* Saves a task and its metadata
*/
@ -178,5 +68,4 @@ abstract public class SyncMetadataService<TYPE extends SyncContainer> {
cursor.close();
}
}
}

Loading…
Cancel
Save