Example #1
0
  public void delete(Task item) {
    if (!item.isSaved()) {
      return;
    }

    if (item.containsValue(Task.TITLE) && item.getTitle().length() == 0) {
      taskDao.delete(item.getId());
      item.setId(Task.NO_ID);
    } else {
      long id = item.getId();
      item.clear();
      item.setId(id);
      gcalHelper.deleteTaskEvent(item);
      item.setDeletionDate(DateUtilities.now());
      taskService.save(item);
    }
  }
Example #2
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();
  }