microsoft.exchange.webservices.data.core.enumeration.service.ConflictResolutionMode Java Examples

The following examples show how to use microsoft.exchange.webservices.data.core.enumeration.service.ConflictResolutionMode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExchangeService.java    From ews-java-api with MIT License 6 votes vote down vote up
/**
 * Updates multiple item in a single EWS call. UpdateItems does not
 * support item that have unsaved attachments.
 *
 * @param items                              the item
 * @param savedItemsDestinationFolderId      the saved item destination folder id
 * @param conflictResolution                 the conflict resolution
 * @param messageDisposition                 the message disposition
 * @param sendInvitationsOrCancellationsMode the send invitations or cancellations mode
 * @param errorHandling                      the error handling
 * @return A ServiceResponseCollection providing update results for each of
 * the specified item.
 * @throws Exception the exception
 */
private ServiceResponseCollection<UpdateItemResponse> internalUpdateItems(
    Iterable<Item> items,
    FolderId savedItemsDestinationFolderId,
    ConflictResolutionMode conflictResolution,
    MessageDisposition messageDisposition,
    SendInvitationsOrCancellationsMode sendInvitationsOrCancellationsMode,
    ServiceErrorHandling errorHandling) throws Exception {
  UpdateItemRequest request = new UpdateItemRequest(this, errorHandling);

  request.getItems().addAll((Collection<? extends Item>) items);
  request.setSavedItemsDestinationFolder(savedItemsDestinationFolderId);
  request.setMessageDisposition(messageDisposition);
  request.setConflictResolutionMode(conflictResolution);
  request
      .setSendInvitationsOrCancellationsMode(sendInvitationsOrCancellationsMode);

  return request.execute();
}
 
Example #2
Source File: ExchangeService.java    From ews-java-api with MIT License 6 votes vote down vote up
/**
 * Updates an item.
 *
 * @param item                               the item
 * @param savedItemsDestinationFolderId      the saved item destination folder id
 * @param conflictResolution                 the conflict resolution
 * @param messageDisposition                 the message disposition
 * @param sendInvitationsOrCancellationsMode the send invitations or cancellations mode
 * @return A ServiceResponseCollection providing deletion results for each
 * of the specified item Ids.
 * @throws Exception the exception
 */
public Item updateItem(Item item, FolderId savedItemsDestinationFolderId,
    ConflictResolutionMode conflictResolution, MessageDisposition messageDisposition,
    SendInvitationsOrCancellationsMode sendInvitationsOrCancellationsMode)
    throws Exception {
  List<Item> itemIdArray = new ArrayList<Item>();
  itemIdArray.add(item);

  ServiceResponseCollection<UpdateItemResponse> responses = this
      .internalUpdateItems(itemIdArray,
          savedItemsDestinationFolderId, conflictResolution,
          messageDisposition, sendInvitationsOrCancellationsMode,
          ServiceErrorHandling.ThrowOnError);

  return responses.getResponseAtIndex(0).getReturnedItem();
}
 
Example #3
Source File: Item.java    From ews-java-api with MIT License 5 votes vote down vote up
/**
 * Update item.
 *
 * @param parentFolderId                     the parent folder id
 * @param conflictResolutionMode             the conflict resolution mode
 * @param messageDisposition                 the message disposition
 * @param sendInvitationsOrCancellationsMode the send invitations or cancellations mode
 * @return Updated item.
 * @throws ServiceResponseException the service response exception
 * @throws Exception                the exception
 */
protected Item internalUpdate(
    FolderId parentFolderId,
    ConflictResolutionMode conflictResolutionMode,
    MessageDisposition messageDisposition,
    SendInvitationsOrCancellationsMode sendInvitationsOrCancellationsMode)
    throws ServiceResponseException, Exception {
  this.throwIfThisIsNew();
  this.throwIfThisIsAttachment();

  Item returnedItem = null;

  if (this.isDirty() && this.getPropertyBag().getIsUpdateCallNecessary()) {
    returnedItem = this
        .getService()
        .updateItem(
            this,
            parentFolderId,
            conflictResolutionMode,
            messageDisposition,
            sendInvitationsOrCancellationsMode != null ? sendInvitationsOrCancellationsMode
                : this
                .getDefaultSendInvitationsOrCancellationsMode());
  }
  if (this.hasUnprocessedAttachmentChanges()) {
    // Validation of the item and its attachments occurs in
    // UpdateItems.
    // If we didn't update the item we still need to validate
    // attachments.
    this.getAttachments().validate();
    this.getAttachments().save();

  }

  return returnedItem;
}
 
Example #4
Source File: EmailMessage.java    From ews-java-api with MIT License 5 votes vote down vote up
/**
 * Send message.
 *
 * @param parentFolderId     The parent folder id.
 * @param messageDisposition The message disposition.
 * @throws Exception the exception
 */
private void internalSend(FolderId parentFolderId,
    MessageDisposition messageDisposition) throws Exception {
  this.throwIfThisIsAttachment();

  if (this.isNew()) {
    if ((this.getAttachments().getCount() == 0) ||
        (messageDisposition == MessageDisposition.SaveOnly)) {
      this.internalCreate(parentFolderId, messageDisposition, null);
    } else {
      // Bug E14:80316 -- If the message has attachments, save as a
      // draft (and add attachments) before sending.
      this.internalCreate(null, // null means use the Drafts folder in
          // the mailbox of the authenticated
          // user.
          MessageDisposition.SaveOnly, null);

      this.getService().sendItem(this, parentFolderId);
    }
  } else if (this.isDirty()) {
    // Validate and save attachments before sending.
    this.getAttachments().validate();
    this.getAttachments().save();

    if (this.getPropertyBag().getIsUpdateCallNecessary()) {
      this.internalUpdate(parentFolderId,
          ConflictResolutionMode.AutoResolve, messageDisposition,
          null);
    } else {
      this.getService().sendItem(this, parentFolderId);
    }
  } else {
    this.getService().sendItem(this, parentFolderId);
  }

  // this.internalCreate(parentFolderId, messageDisposition, null);
}
 
Example #5
Source File: ConsumeEWS.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Fills the internal message queue if such queue is empty. This is due to
 * the fact that per single session there may be multiple messages retrieved
 * from the email server (see FETCH_SIZE).
 */
protected void fillMessageQueueIfNecessary(ProcessContext context) throws ProcessException {
    if (this.messageQueue.isEmpty()) {
        ExchangeService service = this.initializeIfNecessary(context);
        boolean deleteOnRead = context.getProperty(SHOULD_DELETE_MESSAGES).getValue().equals("true");
        boolean markAsRead = context.getProperty(SHOULD_MARK_READ).getValue().equals("true");

        try {
            //Get Folder
            Folder folder = getFolder(service);

            ItemView view = new ItemView(messageQueue.remainingCapacity());
            view.getOrderBy().add(ItemSchema.DateTimeReceived, SortDirection.Ascending);

            SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
            FindItemsResults<Item> findResults = service.findItems(folder.getId(), sf, view);

            if(findResults == null || findResults.getItems().size()== 0){
                return;
            }

            service.loadPropertiesForItems(findResults, PropertySet.FirstClassProperties);

            for (Item item : findResults) {
                EmailMessage ewsMessage = (EmailMessage) item;
                messageQueue.add(parseMessage(ewsMessage));

                if(deleteOnRead){
                    ewsMessage.delete(DeleteMode.HardDelete);
                } else if(markAsRead){
                    ewsMessage.setIsRead(true);
                    ewsMessage.update(ConflictResolutionMode.AlwaysOverwrite);
                }
            }

            service.close();
        } catch (Exception e) {
            throw new ProcessException("Failed retrieving new messages from EWS.", e);
        }
    }
}
 
Example #6
Source File: ConsumeEWS.java    From nifi with Apache License 2.0 4 votes vote down vote up
/**
 * Fills the internal message queue if such queue is empty. This is due to
 * the fact that per single session there may be multiple messages retrieved
 * from the email server (see FETCH_SIZE).
 */
protected void fillMessageQueueIfNecessary(ProcessContext context) throws ProcessException {
    if (this.messageQueue.isEmpty()) {
        ExchangeService service = this.initializeIfNecessary(context);
        boolean deleteOnRead = context.getProperty(SHOULD_DELETE_MESSAGES).getValue().equals("true");
        boolean markAsRead = context.getProperty(SHOULD_MARK_READ).getValue().equals("true");
        String includeHeaders = context.getProperty(INCLUDE_EMAIL_HEADERS).getValue();
        String excludeHeaders = context.getProperty(EXCLUDE_EMAIL_HEADERS).getValue();

        List<String> includeHeadersList = null;
        List<String> excludeHeadersList = null;

        if (!StringUtils.isEmpty(includeHeaders)) {
            includeHeadersList = Arrays.asList(includeHeaders.split(","));
        }

        if (!StringUtils.isEmpty(excludeHeaders)) {
            excludeHeadersList = Arrays.asList(excludeHeaders.split(","));
        }

        try {
            //Get Folder
            Folder folder = getFolder(service);

            ItemView view = new ItemView(messageQueue.remainingCapacity());
            view.getOrderBy().add(ItemSchema.DateTimeReceived, SortDirection.Ascending);

            SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
            FindItemsResults<Item> findResults = service.findItems(folder.getId(), sf, view);

            if(findResults == null || findResults.getItems().size()== 0){
                return;
            }

            service.loadPropertiesForItems(findResults, PropertySet.FirstClassProperties);

            for (Item item : findResults) {
                EmailMessage ewsMessage = (EmailMessage) item;
                messageQueue.add(parseMessage(ewsMessage,includeHeadersList,excludeHeadersList));

                if(deleteOnRead){
                    ewsMessage.delete(DeleteMode.HardDelete);
                } else if(markAsRead){
                    ewsMessage.setIsRead(true);
                    ewsMessage.update(ConflictResolutionMode.AlwaysOverwrite);
                }
            }

            service.close();
        } catch (Exception e) {
            throw new ProcessException("Failed retrieving new messages from EWS.", e);
        }
    }
}
 
Example #7
Source File: Appointment.java    From ews-java-api with MIT License 3 votes vote down vote up
/**
 * Applies the local changes that have been made to this appointment.
 * Calling this method results in at least one call to EWS. Mutliple calls
 * to EWS might be made if attachments have been added or removed.
 *
 * @param conflictResolutionMode             the conflict resolution mode
 * @param sendInvitationsOrCancellationsMode the send invitations or cancellations mode
 * @throws Exception the exception
 */
public void update(
    ConflictResolutionMode conflictResolutionMode,
    SendInvitationsOrCancellationsMode
        sendInvitationsOrCancellationsMode)
    throws Exception {
  this.internalUpdate(null, conflictResolutionMode, null,
      sendInvitationsOrCancellationsMode);
}
 
Example #8
Source File: UpdateItemRequest.java    From ews-java-api with MIT License 2 votes vote down vote up
/**
 * Gets the conflict resolution mode.
 *
 * @return the conflict resolution mode
 */
public ConflictResolutionMode getConflictResolutionMode() {
  return this.conflictResolutionMode;
}
 
Example #9
Source File: UpdateItemRequest.java    From ews-java-api with MIT License 2 votes vote down vote up
/**
 * Sets the conflict resolution mode.
 *
 * @param value the new conflict resolution mode
 */
public void setConflictResolutionMode(ConflictResolutionMode value) {
  this.conflictResolutionMode = value;
}
 
Example #10
Source File: Item.java    From ews-java-api with MIT License 2 votes vote down vote up
/**
 * Applies the local changes that have been made to this item. Calling this
 * method results in at least one call to EWS. Mutliple calls to EWS might
 * be made if attachments have been added or removed.
 *
 * @param conflictResolutionMode the conflict resolution mode
 * @throws ServiceResponseException the service response exception
 * @throws Exception                the exception
 */
public void update(ConflictResolutionMode conflictResolutionMode)
    throws ServiceResponseException, Exception {
  this.internalUpdate(null /* parentFolder */, conflictResolutionMode,
      MessageDisposition.SaveOnly, null);
}
 
Example #11
Source File: Task.java    From ews-java-api with MIT License 2 votes vote down vote up
/**
 * Applies the local changes that have been made to this task. Calling
 * this method results in at least one call to EWS. Mutliple calls to EWS
 * might be made if attachments have been added or removed.
 *
 * @param conflictResolutionMode the conflict resolution mode
 * @return A Task object representing the completed occurrence if the task
 * is recurring and the update marks it as completed; or a Task
 * object representing the current occurrence if the task is
 * recurring and the uypdate changed its recurrence pattern; or null
 * in every other case.
 * @throws ServiceResponseException the service response exception
 * @throws Exception                the exception
 */
public Task updateTask(ConflictResolutionMode conflictResolutionMode)
    throws ServiceResponseException, Exception {
  return (Task) this.internalUpdate(null /* parentFolder */,
      conflictResolutionMode, MessageDisposition.SaveOnly, null);
}