예제 #1
0
 private synchronized void pushUpdated(GtasksInvoker invoker, SyncResultCallback callback) {
   TodorooCursor<Task> queued =
       taskService.query(
           Query.select(Task.PROPERTIES)
               .join(
                   Join.left(
                       Metadata.TABLE,
                       Criterion.and(
                           MetadataCriteria.withKey(GtasksMetadata.METADATA_KEY),
                           Task.ID.eq(Metadata.TASK))))
               .where(
                   Criterion.or(
                       Task.MODIFICATION_DATE.gt(GtasksMetadata.LAST_SYNC),
                       Criterion.and(
                           Task.USER_ID.neq(Task.USER_ID_SELF), GtasksMetadata.ID.isNotNull()),
                       Metadata.KEY.isNull())));
   callback.incrementMax(queued.getCount() * 10);
   try {
     Task task = new Task();
     for (queued.moveToFirst(); !queued.isAfterLast(); queued.moveToNext()) {
       task.readFromCursor(queued);
       try {
         gtasksSyncService.pushTaskOnSave(task, task.getMergedValues(), invoker, false);
       } catch (GoogleTasksException e) {
         handler.handleException("gtasks-sync-io", e, e.getType()); // $NON-NLS-1$
       } catch (IOException e) {
         handler.handleException("gtasks-sync-io", e, e.toString()); // $NON-NLS-1$
       } finally {
         callback.incrementProgress(10);
       }
     }
   } finally {
     queued.close();
   }
 }
예제 #2
0
 public static Filter getAssignedByMeFilter(Resources r) {
   int themeFlags = ThemeService.getFilterThemeFlags();
   Filter f =
       new Filter(
           r.getString(R.string.BFE_Assigned),
           r.getString(R.string.BFE_Assigned),
           new QueryTemplate()
               .join(
                   Join.left(
                       Metadata.TABLE,
                       Criterion.and(
                           Metadata.KEY.eq(TaskRabbitMetadata.METADATA_KEY),
                           Task.ID.eq(Metadata.TASK))))
               .where(
                   Criterion.and(
                       TaskCriteria.isActive(),
                       Criterion.or(
                           Task.CREATOR_ID.eq(0),
                           Task.CREATOR_ID.eq(ActFmPreferenceService.userId())),
                       Criterion.or(Task.USER_ID.neq(0), TaskRabbitMetadata.ID.gt(0)))),
           null);
   f.listingIcon =
       ((BitmapDrawable)
               r.getDrawable(ThemeService.getDrawable(R.drawable.filter_assigned, themeFlags)))
           .getBitmap();
   return f;
 }
예제 #3
0
  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$
    }
  }
예제 #4
0
  /**
   * Save the given array of alarms into the database
   *
   * @param taskId
   * @param tags
   * @return true if data was changed
   */
  public boolean synchronizeAlarms(long taskId, LinkedHashSet<Long> alarms) {
    MetadataService service = PluginServices.getMetadataService();

    ArrayList<Metadata> metadata = new ArrayList<Metadata>();
    for (Long alarm : alarms) {
      Metadata item = new Metadata();
      item.setValue(Metadata.KEY, AlarmFields.METADATA_KEY);
      item.setValue(AlarmFields.TIME, alarm);
      item.setValue(AlarmFields.TYPE, AlarmFields.TYPE_SINGLE);
      metadata.add(item);
    }

    boolean changed =
        service.synchronizeMetadata(taskId, metadata, Metadata.KEY.eq(AlarmFields.METADATA_KEY))
            > 0;
    if (changed) scheduleAlarms(taskId);
    return changed;
  }
예제 #5
0
 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();
   }
 }
예제 #6
0
 /** Returns all metadata associated with a given key */
 public static Criterion withKey(String key) {
   return Metadata.KEY.eq(key);
 }
예제 #7
0
  /** Fixes task filter missing tasks bug, migrate PDV/RTM notes */
  @SuppressWarnings("nls")
  private void upgrade3To3_7() {
    TodorooCursor<Task> t =
        taskService.query(Query.select(Task.ID, Task.DUE_DATE).where(Task.DUE_DATE.gt(0)));
    Task task = new Task();
    for (t.moveToFirst(); !t.isAfterLast(); t.moveToNext()) {
      task.readFromCursor(t);
      if (task.hasDueDate()) {
        task.setValue(Task.DUE_DATE, task.getValue(Task.DUE_DATE) / 1000L * 1000L);
        taskService.save(task);
      }
    }
    t.close();

    TodorooCursor<Metadata> m =
        metadataService.query(
            Query.select(Metadata.PROPERTIES)
                .where(
                    Criterion.or(
                        Metadata.KEY.eq("producteev-note"), Metadata.KEY.eq("rmilk-note"))));

    StringProperty PDV_NOTE_ID = Metadata.VALUE1;
    StringProperty PDV_NOTE_MESSAGE = Metadata.VALUE2;
    LongProperty PDV_NOTE_CREATED = new LongProperty(Metadata.TABLE, Metadata.VALUE3.name);

    StringProperty RTM_NOTE_ID = Metadata.VALUE1;
    StringProperty RTM_NOTE_TITLE = Metadata.VALUE2;
    StringProperty RTM_NOTE_TEXT = Metadata.VALUE3;
    LongProperty RTM_NOTE_CREATED = new LongProperty(Metadata.TABLE, Metadata.VALUE4.name);

    Metadata metadata = new Metadata();
    for (m.moveToFirst(); !m.isAfterLast(); m.moveToNext()) {
      metadata.readFromCursor(m);

      String id, body, title, provider;
      long created;
      if ("rmilk-note".equals(metadata.getValue(Metadata.KEY))) {
        id = metadata.getValue(RTM_NOTE_ID);
        body = metadata.getValue(RTM_NOTE_TEXT);
        title = metadata.getValue(RTM_NOTE_TITLE);
        created = metadata.getValue(RTM_NOTE_CREATED);
        provider = MilkNoteHelper.PROVIDER;
      } else {
        id = metadata.getValue(PDV_NOTE_ID);
        body = metadata.getValue(PDV_NOTE_MESSAGE);
        created = metadata.getValue(PDV_NOTE_CREATED);
        title =
            DateUtilities.getDateStringWithWeekday(ContextManager.getContext(), new Date(created));
        provider = ProducteevDataService.NOTE_PROVIDER;
      }

      metadata.setValue(Metadata.KEY, NoteMetadata.METADATA_KEY);
      metadata.setValue(Metadata.CREATION_DATE, created);
      metadata.setValue(NoteMetadata.BODY, body);
      metadata.setValue(NoteMetadata.TITLE, title);
      metadata.setValue(NoteMetadata.THUMBNAIL, null);
      metadata.setValue(NoteMetadata.EXT_PROVIDER, provider);
      metadata.setValue(NoteMetadata.EXT_ID, id);

      metadata.clearValue(Metadata.ID);
      metadataService.save(metadata);
    }
    m.close();
  }
예제 #8
0
  public void checkAndMigrateLegacy() throws IOException {
    if (!gtasksPreferenceService.migrationHasOccurred()) {

      // Fetch all tasks that have associated gtask metadata
      String defaultListTitle =
          gtasksListService.getListName(
              Preferences.getStringValue(GtasksPreferenceService.PREF_DEFAULT_LIST));
      String defaultListId = null;

      TodorooCursor<Task> allTasksWithGtaskData =
          taskService.query(
              Query.select(Task.PROPERTIES)
                  .where(
                      Task.ID.in(
                          Query.select(Metadata.TASK)
                              .from(Metadata.TABLE)
                              .where(Metadata.KEY.eq(GtasksMetadata.METADATA_KEY)))));

      try {
        if (allTasksWithGtaskData.getCount() > 0) {
          // Fetch all remote tasks from all remote lists (this may be an expensive operation)
          // and map their titles to their real remote ids
          HashMap<String, String> taskAndListTitlesToRemoteTaskIds = new HashMap<String, String>();

          List<TaskList> items = allLists.getItems();
          for (TaskList list : items) {
            if (list.getTitle().equals(defaultListTitle)) {
              defaultListId = list.getId();
            }

            Tasks allTasks = gtasksService.getAllGtasksFromListId(list.getId(), false, false, 0);

            List<com.google.api.services.tasks.model.Task> tasksItems = allTasks.getItems();
            if (tasksItems != null) {
              for (com.google.api.services.tasks.model.Task t : tasksItems) {
                String key = constructKeyFromTitles(t.getTitle(), list.getTitle());
                taskAndListTitlesToRemoteTaskIds.put(key, t.getId());
              }
            }
          }

          if (defaultListId == null) {
            com.google.api.services.tasks.model.TaskList defaultList =
                gtasksService.getGtaskList("@default"); // $NON-NLS-1$
            defaultListId = defaultList.getId();
          }
          Preferences.setString(GtasksPreferenceService.PREF_DEFAULT_LIST, defaultListId);

          // For each local task, check to see if its title paired with any list title has a match
          // in the map
          for (allTasksWithGtaskData.moveToFirst();
              !allTasksWithGtaskData.isAfterLast();
              allTasksWithGtaskData.moveToNext()) {
            GtasksTaskContainer container =
                gtasksMetadataService.readTaskAndMetadata(allTasksWithGtaskData);
            // memorize the original listname for the case that the task is not matched,
            // then it should at least be recreated in the correct list
            String originalListName =
                gtasksListService.getListName(
                    container.gtaskMetadata.getValue(GtasksMetadata.LIST_ID));
            String originalListId = null;

            // Search through lists to see if one of them has match
            String taskTitle = container.task.getValue(Task.TITLE);
            boolean foundMatch = false;
            items = allLists.getItems();
            for (TaskList list : items) {
              String expectedKey = constructKeyFromTitles(taskTitle, list.getTitle());

              // save the new id of the current list
              // if it matches the listname of the current task
              if (list.getTitle() != null && list.getTitle().equals(originalListName)) {
                originalListId = list.getId();
              }

              if (taskAndListTitlesToRemoteTaskIds.containsKey(expectedKey)) {
                foundMatch = true;
                String newRemoteTaskId = taskAndListTitlesToRemoteTaskIds.get(expectedKey);
                String newRemoteListId = list.getId();

                container.gtaskMetadata.setValue(GtasksMetadata.ID, newRemoteTaskId);
                container.gtaskMetadata.setValue(GtasksMetadata.LIST_ID, newRemoteListId);
                gtasksMetadataService.saveTaskAndMetadata(container);
                break;
              }
            }

            if (!foundMatch) {
              // For non-matches, make the task look newly created
              container.gtaskMetadata = GtasksMetadata.createEmptyMetadata(container.task.getId());
              container.gtaskMetadata.setValue(GtasksMetadata.ID, ""); // $NON-NLS-1$
              if (originalListId != null) {
                // set the list-id based on the original listname, saved above during for-loop
                container.gtaskMetadata.setValue(GtasksMetadata.LIST_ID, originalListId);
              } else {
                // remote list or local list was renamed, so put this unmatched task in the default
                // list
                container.gtaskMetadata.setValue(GtasksMetadata.LIST_ID, defaultListId);
              }
              gtasksMetadataService.saveTaskAndMetadata(container);
              break;
            }
          }
        }

        // migrate the list-id's afterwards, so that we can put the non-matched tasks in their
        // original lists
        // if the listnames didnt change before migration (defaultlist otherwise)
        listService.migrateListIds(allLists);

      } finally {
        allTasksWithGtaskData.close();
      }
      Preferences.setBoolean(
          GtasksPreferenceService.PREF_MIGRATION_HAS_OCCURRED, true); // Record successful migration
    }
  }