예제 #1
0
  /**
   * Determines whether there are any unsaved attachment collection changes.
   *
   * @return True if attachment adds or deletes haven't been processed yet.
   * @throws ServiceLocalException
   */
  public boolean hasUnprocessedChanges() throws ServiceLocalException {
    // Any new attachments?
    for (Attachment attachment : this) {
      if (attachment.isNew()) {
        return true;
      }
    }

    // Any pending deletions?
    for (Attachment attachment : this.getRemovedItems()) {
      if (!attachment.isNew()) {
        return true;
      }
    }

    Collection<ItemAttachment> itemAttachments = new ArrayList<ItemAttachment>();
    for (Object event : this.getItems()) {
      if (event instanceof ItemAttachment) {
        itemAttachments.add((ItemAttachment) event);
      }
    }

    // Recurse: process item attachments to check
    // for new or deleted sub-attachments.
    for (ItemAttachment itemAttachment : itemAttachments) {
      if (itemAttachment.getItem() != null) {
        if (itemAttachment.getItem().getAttachments().hasUnprocessedChanges()) {
          return true;
        }
      }
    }

    return false;
  }
예제 #2
0
  /**
   * Saves this collection by creating new attachment and deleting removed ones.
   *
   * @throws Exception the exception
   */
  public void save() throws Exception {
    ArrayList<Attachment> attachments = new ArrayList<Attachment>();

    for (Attachment attachment : this.getRemovedItems()) {
      if (!attachment.isNew()) {
        attachments.add(attachment);
      }
    }

    // If any, delete them by calling the DeleteAttachment web method.
    if (attachments.size() > 0) {
      this.internalDeleteAttachments(attachments);
    }

    attachments.clear();

    // Retrieve a list of attachments that have to be created.
    for (Attachment attachment : this) {
      if (attachment.isNew()) {
        attachments.add(attachment);
      }
    }

    // If there are any, create them by calling the CreateAttachment web
    // method.
    if (attachments.size() > 0) {
      if (this.owner.isAttachment()) {
        this.internalCreateAttachments(this.owner.getParentAttachment().getId(), attachments);
      } else {
        this.internalCreateAttachments(this.owner.getId().getUniqueId(), attachments);
      }
    }

    // Process all of the item attachments in this collection.
    for (Attachment attachment : this) {
      ItemAttachment itemAttachment =
          (ItemAttachment) ((attachment instanceof ItemAttachment) ? attachment : null);
      if (itemAttachment != null) {
        // Bug E14:80864: Make sure item was created/loaded before
        // trying to create/delete sub-attachments
        if (itemAttachment.getItem() != null) {
          // Create/delete any sub-attachments
          itemAttachment.getItem().getAttachments().save();

          // Clear the item's change log
          itemAttachment.getItem().clearChangeLog();
        }
      }
    }

    super.clearChangeLog();
  }