Ejemplo n.º 1
0
 /** New attachment insertion */
 public Attachment updateAttachment(long noteId, Attachment attachment, SQLiteDatabase db) {
   ContentValues valuesAttachments = new ContentValues();
   valuesAttachments.put(
       KEY_ATTACHMENT_ID,
       attachment.getId() != null ? attachment.getId() : Calendar.getInstance().getTimeInMillis());
   valuesAttachments.put(KEY_ATTACHMENT_NOTE_ID, noteId);
   valuesAttachments.put(KEY_ATTACHMENT_URI, attachment.getUri().toString());
   valuesAttachments.put(KEY_ATTACHMENT_MIME_TYPE, attachment.getMime_type());
   valuesAttachments.put(KEY_ATTACHMENT_NAME, attachment.getName());
   valuesAttachments.put(KEY_ATTACHMENT_SIZE, attachment.getSize());
   valuesAttachments.put(KEY_ATTACHMENT_LENGTH, attachment.getLength());
   db.insertWithOnConflict(
       TABLE_ATTACHMENTS, KEY_ATTACHMENT_ID, valuesAttachments, SQLiteDatabase.CONFLICT_REPLACE);
   return attachment;
 }
  public void testattachFileSheet() throws SmartsheetException, IOException {

    // attach file to sheet
    Attachment attachment =
        smartsheet.sheetResources().attachmentResources().attachFile(sheetId, file, "text/plain");
    testGetAttachmentSheet(attachment.getId());
  }
  // smartsheet.sheetResources().commentResources().attachmentResources().attachFile(sheetId,
  // commentId, file,"text/plain");
  public void testattachFileComment() throws SmartsheetException, IOException {
    // create comment to add to discussion
    Comment comment = new Comment.AddCommentBuilder().setText("This is a test comment").build();

    Discussion discussion =
        new Discussion.CreateDiscussionBuilder()
            .setTitle("New Discussion")
            .setComment(comment)
            .build();
    discussion =
        smartsheet.sheetResources().discussionResources().createDiscussion(sheetId, discussion);

    // comment =
    // smartsheet.sheetResources().discussionResources().comments().addComment(sheetId,discussion.getId(), comment);
    comment = discussion.getComments().get(0);
    commentId = comment.getId();
    discussionId = discussion.getId();

    File file1 = new File("src/integration-test/resources/small-text.txt");
    // attach file to comment
    Attachment attachment =
        smartsheet
            .sheetResources()
            .commentResources()
            .attachmentResources()
            .attachFile(sheetId, commentId, file1, "text/plain");
    testGetAttachmentComment(attachment.getId());
  }
 public void testAttachNewVersion() throws IOException, SmartsheetException {
   Attachment attachment =
       smartsheet
           .sheetResources()
           .attachmentResources()
           .versioningResources()
           .attachNewVersion(sheetId, sheetAttachmentId, file, "text/plain");
   assertNotNull(attachment);
   attachmentWithVersionId = attachment.getId();
 }
  public void testattachFileRow() throws SmartsheetException, IOException {
    // add rows
    Row row = addRows(sheetId);
    rowId = row.getId();

    // attach file to row
    Attachment attachment =
        smartsheet
            .sheetResources()
            .rowResources()
            .attachmentResources()
            .attachFile(sheetId, rowId, file, "text/plain");
    testGetAttachmentRow(attachment.getId());
  }
Ejemplo n.º 6
0
  /**
   * Removes the Attachment specified by the attachmentId.
   *
   * @param attachmentId id of attachment to remove
   * @return removed Attachment or null if one was not found with the id
   */
  public Attachment removeAttachment(final long attachmentId) {
    Attachment removedAttachment = null;

    if (attachments != null) {
      for (int index = attachments.size() - 1; index >= 0; --index) {
        Attachment currentAttachment = attachments.get(index);

        if (currentAttachment.getId() == attachmentId) {
          removedAttachment = attachments.remove(index);
          break;
        }
      }
    }

    return removedAttachment;
  }
  public void testAddRemoveAttachment() throws Exception {
    Map vars = new HashMap();
    vars.put("users", users);
    vars.put("groups", groups);
    vars.put("now", new Date());

    String str =
        "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { createdOn = now, activationTime = now}), ";
    str += "deadlines = new Deadlines(),";
    str += "delegation = new Delegation(),";
    str += "peopleAssignments = new PeopleAssignments(),";
    str += "names = [ new I18NText( 'en-UK', 'This is my task name')] })";

    Task task = (Task) eval(new StringReader(str), vars);
    client.addTask(task, null);

    long taskId = task.getId();

    Attachment attachment = new Attachment();
    Date attachedAt = new Date(System.currentTimeMillis());
    attachment.setAttachedAt(attachedAt);
    attachment.setAttachedBy(users.get("luke"));
    attachment.setName("file1.txt");
    attachment.setAccessType(AccessType.Inline);
    attachment.setContentType("txt");

    byte[] bytes = "Ths is my attachment text1".getBytes();
    Content content = new Content();
    content.setContent(bytes);

    client.addAttachment(taskId, attachment, content);

    Task task1 = client.getTask(taskId);
    // For local clients this will be the same.. that's why is commented
    // assertNotSame(task, task1);
    // assertFalse(task.equals(task1));

    List<Attachment> attachments1 = task1.getTaskData().getAttachments();
    assertEquals(1, attachments1.size());
    Attachment returnedAttachment = attachments1.get(0);
    assertEquals(attachedAt, returnedAttachment.getAttachedAt());
    assertEquals(users.get("luke"), returnedAttachment.getAttachedBy());
    assertEquals(AccessType.Inline, returnedAttachment.getAccessType());
    assertEquals("txt", returnedAttachment.getContentType());
    assertEquals("file1.txt", returnedAttachment.getName());
    assertEquals(bytes.length, returnedAttachment.getSize());

    assertEquals((long) attachment.getId(), (long) returnedAttachment.getId());
    assertEquals((long) content.getId(), (long) returnedAttachment.getAttachmentContentId());

    // Make the same as the returned tasks, so we can test equals
    task.getTaskData().setAttachments(attachments1);
    task.getTaskData().setStatus(Status.Created);
    assertEquals(task, task1);

    content = client.getContent(returnedAttachment.getAttachmentContentId());
    assertEquals("Ths is my attachment text1", new String(content.getContent()));

    // test we can have multiple attachments

    attachment = new Attachment();
    attachedAt = new Date(System.currentTimeMillis());
    attachment.setAttachedAt(attachedAt);
    attachment.setAttachedBy(users.get("tony"));
    attachment.setName("file2.txt");
    attachment.setAccessType(AccessType.Inline);
    attachment.setContentType("txt");

    bytes = "Ths is my attachment text2".getBytes();
    content = new Content();
    content.setContent(bytes);

    client.addAttachment(taskId, attachment, content);

    task1 = client.getTask(taskId);
    // In local clients this will be the same object and we are reusing the tests
    // assertNotSame(task, task1);
    // assertFalse(task.equals(task1));

    List<Attachment> attachments2 = task1.getTaskData().getAttachments();
    assertEquals(2, attachments2.size());

    content = client.getContent(content.getId());
    assertEquals("Ths is my attachment text2", new String(content.getContent()));

    // make two collections the same and compare
    attachment.setSize(26);
    attachment.setAttachmentContentId(content.getId());
    attachments1.add(attachment);
    assertTrue(CollectionUtils.equals(attachments2, attachments1));

    client.deleteAttachment(taskId, attachment.getId(), content.getId());

    task1 = client.getTask(taskId);
    attachments2 = task1.getTaskData().getAttachments();
    assertEquals(1, attachments2.size());

    assertEquals("file1.txt", attachments2.get(0).getName());
  }
Ejemplo n.º 8
0
 /* (non-Javadoc)
  * @see edu.ku.brc.specify.datamodel.DataModelObjBase#getParentId()
  */
 @Override
 @Transient
 public Integer getParentId() {
   return attachment != null ? attachment.getId() : null;
 }
Ejemplo n.º 9
0
  // Inserting or updating single note
  public Note updateNote(Note note, boolean updateLastModification) {
    SQLiteDatabase db = getDatabase(true);

    String content;
    if (note.isLocked()) {
      content = Security.encrypt(note.getContent(), prefs.getString(Constants.PREF_PASSWORD, ""));
    } else {
      content = note.getContent();
    }

    // To ensure note and attachments insertions are atomical and boost performances transaction are
    // used
    db.beginTransaction();

    ContentValues values = new ContentValues();
    values.put(KEY_TITLE, note.getTitle());
    values.put(KEY_CONTENT, content);
    values.put(
        KEY_CREATION,
        note.getCreation() != null ? note.getCreation() : Calendar.getInstance().getTimeInMillis());
    values.put(
        KEY_LAST_MODIFICATION,
        updateLastModification
            ? Calendar.getInstance().getTimeInMillis()
            : (note.getLastModification() != null
                ? note.getLastModification()
                : Calendar.getInstance().getTimeInMillis()));
    values.put(KEY_ARCHIVED, note.isArchived());
    values.put(KEY_TRASHED, note.isTrashed());
    values.put(KEY_REMINDER, note.getAlarm());
    values.put(KEY_REMINDER_FIRED, note.isReminderFired());
    values.put(KEY_RECURRENCE_RULE, note.getRecurrenceRule());
    values.put(KEY_LATITUDE, note.getLatitude());
    values.put(KEY_LONGITUDE, note.getLongitude());
    values.put(KEY_ADDRESS, note.getAddress());
    values.put(KEY_CATEGORY, note.getCategory() != null ? note.getCategory().getId() : null);
    boolean locked = note.isLocked() != null ? note.isLocked() : false;
    values.put(KEY_LOCKED, locked);
    boolean checklist = note.isChecklist() != null ? note.isChecklist() : false;
    values.put(KEY_CHECKLIST, checklist);

    db.insertWithOnConflict(TABLE_NOTES, KEY_ID, values, SQLiteDatabase.CONFLICT_REPLACE);
    Log.d(Constants.TAG, "Updated note titled '" + note.getTitle() + "'");

    // Updating attachments
    List<Attachment> deletedAttachments = note.getAttachmentsListOld();
    for (Attachment attachment : note.getAttachmentsList()) {
      updateAttachment(
          note.get_id() != null ? note.get_id() : values.getAsLong(KEY_CREATION), attachment, db);
      deletedAttachments.remove(attachment);
    }
    // Remove from database deleted attachments
    for (Attachment attachmentDeleted : deletedAttachments) {
      db.delete(
          TABLE_ATTACHMENTS,
          KEY_ATTACHMENT_ID + " = ?",
          new String[] {String.valueOf(attachmentDeleted.getId())});
    }

    db.setTransactionSuccessful();
    db.endTransaction();

    // Fill the note with correct data before returning it
    note.setCreation(
        note.getCreation() != null ? note.getCreation() : values.getAsLong(KEY_CREATION));
    note.setLastModification(values.getAsLong(KEY_LAST_MODIFICATION));

    return note;
  }
 public void testGetAttachmentSheet(long attachmentId) throws SmartsheetException, IOException {
   Attachment attachment =
       smartsheet.sheetResources().attachmentResources().getAttachment(sheetId, attachmentId);
   assertNotNull(attachment);
   sheetAttachmentId = attachment.getId();
 }