private synchronized void synchronizeListHelper( StoreObject list, GtasksInvoker invoker, boolean manual, SyncExceptionHandler errorHandler, SyncResultCallback callback) { String listId = list.getValue(GtasksList.REMOTE_ID); long lastSyncDate; if (!manual && list.containsNonNullValue(GtasksList.LAST_SYNC)) { lastSyncDate = list.getValue(GtasksList.LAST_SYNC); } else { lastSyncDate = 0; } boolean includeDeletedAndHidden = lastSyncDate != 0; try { Tasks taskList = invoker.getAllGtasksFromListId( listId, includeDeletedAndHidden, includeDeletedAndHidden, lastSyncDate); List<com.google.api.services.tasks.model.Task> tasks = taskList.getItems(); if (tasks != null) { callback.incrementMax(tasks.size() * 10); HashSet<Long> localIds = new HashSet<Long>(tasks.size()); for (com.google.api.services.tasks.model.Task t : tasks) { GtasksTaskContainer container = parseRemoteTask(t, listId); gtasksMetadataService.findLocalMatch(container); container.gtaskMetadata.setValue( GtasksMetadata.GTASKS_ORDER, Long.parseLong(t.getPosition())); container.gtaskMetadata.setValue( GtasksMetadata.PARENT_TASK, gtasksMetadataService.localIdForGtasksId(t.getParent())); container.gtaskMetadata.setValue(GtasksMetadata.LAST_SYNC, DateUtilities.now() + 1000L); write(container); localIds.add(container.task.getId()); callback.incrementProgress(10); } list.setValue(GtasksList.LAST_SYNC, DateUtilities.now()); storeObjectDao.persist(list); if (lastSyncDate == 0) { Long[] localIdArray = localIds.toArray(new Long[localIds.size()]); Criterion delete = Criterion.and( Metadata.KEY.eq(GtasksMetadata.METADATA_KEY), GtasksMetadata.LIST_ID.eq(listId), Criterion.not(Metadata.TASK.in(localIdArray))); taskService.deleteWhere( Task.ID.in(Query.select(Metadata.TASK).from(Metadata.TABLE).where(delete))); metadataService.deleteWhere(delete); } gtasksTaskListUpdater.correctOrderAndIndentForList(listId); } } catch (GoogleTasksException e) { if (errorHandler != null) errorHandler.handleException("gtasks-sync-io", e, e.getType()); // $NON-NLS-1$ } catch (IOException e) { if (errorHandler != null) errorHandler.handleException("gtasks-sync-io", e, e.toString()); // $NON-NLS-1$ } }
/** Fetch all metadata that are unattached to the task */ public TodorooCursor<Metadata> fetchDangling(Property<?>... properties) { Query sql = Query.select(properties) .from(Metadata.TABLE) .join(Join.left(Task.TABLE, Metadata.TASK.eq(Task.ID))) .where(Task.TITLE.isNull()); Cursor cursor = database.rawQuery(sql.toString(), null); return new TodorooCursor<Metadata>(cursor, properties); }
/** * Gets a listing of all alarms that are active * * @param properties * @return todoroo cursor. PLEASE CLOSE THIS CURSOR! */ private TodorooCursor<Metadata> getActiveAlarms() { return PluginServices.getMetadataService() .query( Query.select(AlarmFields.TIME) .join(Join.inner(Task.TABLE, Metadata.TASK.eq(Task.ID))) .where( Criterion.and( TaskCriteria.isActive(), MetadataCriteria.withKey(AlarmFields.METADATA_KEY)))); }
private void titleMatchWithActFm(Task task) { String title = task.getValue(Task.TITLE); TodorooCursor<Task> match = taskService.query( Query.select(Task.ID) .join( Join.left( Metadata.TABLE, Criterion.and( Metadata.KEY.eq(GtasksMetadata.METADATA_KEY), Metadata.TASK.eq(Task.ID)))) .where(Criterion.and(Task.TITLE.eq(title), GtasksMetadata.ID.isNull()))); try { if (match.getCount() > 0) { match.moveToFirst(); task.setId(match.get(Task.ID)); } } finally { match.close(); } }
/** Returns all metadata associated with a given task */ public static Criterion byTask(long taskId) { return Metadata.TASK.eq(taskId); }