Ejemplo n.º 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;
  }
Ejemplo n.º 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();
  }
Ejemplo n.º 3
0
 /**
  * Validates this instance.
  *
  * @throws Exception the exception
  */
 public void validate() throws Exception {
   // Validate all added attachments
   if (this.owner.isNew()
       && this.owner.getService().getRequestedServerVersion().ordinal()
           >= ExchangeVersion.Exchange2010_SP2.ordinal()) {
     boolean contactPhotoFound = false;
     for (int attachmentIndex = 0;
         attachmentIndex < this.getAddedItems().size();
         attachmentIndex++) {
       final Attachment attachment = this.getAddedItems().get(attachmentIndex);
       if (attachment != null) {
         if (attachment.isNew() && attachment instanceof FileAttachment) {
           // At the server side, only the last attachment with
           // IsContactPhoto is kept, all other IsContactPhoto
           // attachments are removed. CreateAttachment will generate
           // AttachmentId for each of such attachments (although
           // only the last one is valid).
           //
           // With E14 SP2 CreateItemWithAttachment, such request will only
           // return 1 AttachmentId; but the client
           // expects to see all, so let us prevent such "invalid" request
           // in the first place.
           //
           // The IsNew check is to still let CreateAttachmentRequest allow
           // multiple IsContactPhoto attachments.
           //
           if (((FileAttachment) attachment).isContactPhoto()) {
             if (contactPhotoFound) {
               throw new ServiceValidationException("Multiple contact photos in attachment.");
             }
             contactPhotoFound = true;
           }
         }
         attachment.validate(attachmentIndex);
       }
     }
   }
 }