microsoft.exchange.webservices.data.core.service.item.Item Java Examples

The following examples show how to use microsoft.exchange.webservices.data.core.service.item.Item. 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: ExchangeFileSystem.java    From iaf with Apache License 2.0 7 votes vote down vote up
@Override
public Iterator<Item> listFiles(String folder) throws FileSystemException {
	try {
		FolderId folderId = findFolder(basefolderId,folder);
		ItemView view = new ItemView(getMaxNumberOfMessagesToList());
		view.getOrderBy().add(ItemSchema.DateTimeReceived, SortDirection.Ascending);
		FindItemsResults<Item> findResults;
		if ("NDR".equalsIgnoreCase(getFilter())) {
			SearchFilter searchFilterBounce = new SearchFilter.IsEqualTo(ItemSchema.ItemClass, "REPORT.IPM.Note.NDR");
			findResults = exchangeService.findItems(folderId,searchFilterBounce, view);
		} else {
			findResults = exchangeService.findItems(folderId, view);
		}
		if (findResults.getTotalCount() == 0) {
			return null;
		} else {
			return findResults.getItems().iterator();
		}
	} catch (Exception e) {
		throw new FileSystemException("Cannot list messages in folder ["+folder+"]", e);
	}
}
 
Example #2
Source File: UpdateItemRequest.java    From ews-java-api with MIT License 6 votes vote down vote up
@Override
protected void writeElementsToXml(EwsServiceXmlWriter writer)
    throws Exception {
  if (this.savedItemsDestinationFolder != null) {
    writer.writeStartElement(XmlNamespace.Messages,
        XmlElementNames.SavedItemFolderId);
    this.savedItemsDestinationFolder.writeToXml(writer);
    writer.writeEndElement();
  }

  writer.writeStartElement(XmlNamespace.Messages,
      XmlElementNames.ItemChanges);

  for (Item item : this.items) {
    item.writeToXmlForUpdate(writer);
  }

  writer.writeEndElement();
}
 
Example #3
Source File: ExchangeService.java    From ews-java-api with MIT License 6 votes vote down vote up
/**
 * Obtains a grouped list of item by searching the contents of a specific
 * folder. Calling this method results in a call to EWS.
 *
 * @param parentFolderId the parent folder id
 * @param queryString    the query string
 * @param view           the view
 * @param groupBy        the group by
 * @return A list of item containing the contents of the specified folder.
 * @throws Exception the exception
 */
public GroupedFindItemsResults<Item> findItems(FolderId parentFolderId,
    String queryString, ItemView view, Grouping groupBy)
    throws Exception {
  EwsUtilities.validateParam(groupBy, "groupBy");
  EwsUtilities.validateParamAllowNull(queryString, "queryString");

  List<FolderId> folderIdArray = new ArrayList<FolderId>();
  folderIdArray.add(parentFolderId);

  ServiceResponseCollection<FindItemResponse<Item>> responses = this
      .findItems(folderIdArray, null, /* searchFilter */
          queryString, view, groupBy, ServiceErrorHandling.ThrowOnError);

  return responses.getResponseAtIndex(0).getGroupedFindResults();
}
 
Example #4
Source File: ExchangeService.java    From ews-java-api with MIT License 6 votes vote down vote up
/**
 * Obtains a grouped list of item by searching the contents of a specific
 * folder. Calling this method results in a call to EWS.
 *
 * @param parentFolderId the parent folder id
 * @param searchFilter   the search filter
 * @param view           the view
 * @param groupBy        the group by
 * @return A list of item containing the contents of the specified folder.
 * @throws Exception the exception
 */
public GroupedFindItemsResults<Item> findItems(FolderId parentFolderId,
    SearchFilter searchFilter, ItemView view, Grouping groupBy)
    throws Exception {
  EwsUtilities.validateParam(groupBy, "groupBy");
  EwsUtilities.validateParamAllowNull(searchFilter, "searchFilter");

  List<FolderId> folderIdArray = new ArrayList<FolderId>();
  folderIdArray.add(parentFolderId);

  ServiceResponseCollection<FindItemResponse<Item>> responses = this
      .findItems(folderIdArray, searchFilter, null, /* queryString */
          view, groupBy, ServiceErrorHandling.ThrowOnError);

  return responses.getResponseAtIndex(0).getGroupedFindResults();
}
 
Example #5
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 #6
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 #7
Source File: EwsUtilitiesTest.java    From ews-java-api with MIT License 6 votes vote down vote up
@Test
public void testGetItemTypeFromXmlElementName() {
  assertEquals(Task.class, EwsUtilities.getItemTypeFromXmlElementName("Task"));
  assertEquals(EmailMessage.class, EwsUtilities.getItemTypeFromXmlElementName("Message"));
  assertEquals(PostItem.class, EwsUtilities.getItemTypeFromXmlElementName("PostItem"));
  assertEquals(SearchFolder.class, EwsUtilities.getItemTypeFromXmlElementName("SearchFolder"));
  assertEquals(Conversation.class, EwsUtilities.getItemTypeFromXmlElementName("Conversation"));
  assertEquals(Folder.class, EwsUtilities.getItemTypeFromXmlElementName("Folder"));
  assertEquals(CalendarFolder.class, EwsUtilities.getItemTypeFromXmlElementName("CalendarFolder"));
  assertEquals(MeetingMessage.class, EwsUtilities.getItemTypeFromXmlElementName("MeetingMessage"));
  assertEquals(Contact.class, EwsUtilities.getItemTypeFromXmlElementName("Contact"));
  assertEquals(Item.class, EwsUtilities.getItemTypeFromXmlElementName("Item"));
  assertEquals(Appointment.class, EwsUtilities.getItemTypeFromXmlElementName("CalendarItem"));
  assertEquals(ContactsFolder.class, EwsUtilities.getItemTypeFromXmlElementName("ContactsFolder"));
  assertEquals(MeetingRequest.class, EwsUtilities.getItemTypeFromXmlElementName("MeetingRequest"));
  assertEquals(TasksFolder.class, EwsUtilities.getItemTypeFromXmlElementName("TasksFolder"));
  assertEquals(MeetingCancellation.class, EwsUtilities.getItemTypeFromXmlElementName("MeetingCancellation"));
  assertEquals(MeetingResponse.class, EwsUtilities.getItemTypeFromXmlElementName("MeetingResponse"));
  assertEquals(ContactGroup.class, EwsUtilities.getItemTypeFromXmlElementName("DistributionList"));
}
 
Example #8
Source File: ExchangeFileSystem.java    From iaf with Apache License 2.0 6 votes vote down vote up
@Override
public InputStream readAttachment(Attachment a) throws FileSystemException, IOException {
	try {
		a.load();
	} catch (Exception e) {
		throw new FileSystemException("Cannot load attachment",e);
	}
	byte[] content = null;
	if (a instanceof FileAttachment) {
		content=((FileAttachment)a).getContent(); // TODO: should do streaming, instead of via byte array
	}
	if (a instanceof ItemAttachment) {
		ItemAttachment itemAttachment=(ItemAttachment)a;
		Item attachmentItem = itemAttachment.getItem();
		return readFile(attachmentItem);
	}
	if (content==null) {
		log.warn("content of attachment is null");
		content = new byte[0];
	}
	InputStream binaryInputStream = new ByteArrayInputStream(content);
	return binaryInputStream;
}
 
Example #9
Source File: ExchangeService.java    From ews-java-api with MIT License 6 votes vote down vote up
/**
 * Finds item.
 *
 * @param <TItem>           The type of item
 * @param parentFolderIds   The parent folder ids.
 * @param searchFilter      The search filter. Available search filter classes include
 *                          SearchFilter.IsEqualTo, SearchFilter.ContainsSubstring and
 *                          SearchFilter.SearchFilterCollection
 * @param queryString       the query string
 * @param view              The view controlling the number of folder returned.
 * @param groupBy           The group by.
 * @param errorHandlingMode Indicates the type of error handling should be done.
 * @return Service response collection.
 * @throws Exception the exception
 */
public <TItem extends Item> ServiceResponseCollection<FindItemResponse<TItem>> findItems(
    Iterable<FolderId> parentFolderIds, SearchFilter searchFilter, String queryString, ViewBase view,
    Grouping groupBy, ServiceErrorHandling errorHandlingMode) throws Exception {
  EwsUtilities.validateParamCollection(parentFolderIds.iterator(),
      "parentFolderIds");
  EwsUtilities.validateParam(view, "view");
  EwsUtilities.validateParamAllowNull(groupBy, "groupBy");
  EwsUtilities.validateParamAllowNull(queryString, "queryString");
  EwsUtilities.validateParamAllowNull(searchFilter, "searchFilter");

  FindItemRequest<TItem> request = new FindItemRequest<TItem>(this,
      errorHandlingMode);

  request.getParentFolderIds().addRangeFolderId(parentFolderIds);
  request.setSearchFilter(searchFilter);
  request.setQueryString(queryString);
  request.setView(view);
  request.setGroupBy(groupBy);

  return request.execute();
}
 
Example #10
Source File: SendItemRequest.java    From ews-java-api with MIT License 6 votes vote down vote up
/**
 * Writes the elements to XML.
 *
 * @param writer the writer
 * @throws Exception the exception
 */
@Override
protected void writeElementsToXml(EwsServiceXmlWriter writer) throws Exception {
  writer
      .writeStartElement(XmlNamespace.Messages,
          XmlElementNames.ItemIds);

  for (Item item : this.getItems()) {
    item.getId().writeToXml(writer, XmlElementNames.ItemId);
  }

  writer.writeEndElement(); // ItemIds

  if (this.savedCopyDestinationFolderId != null) {
    writer.writeStartElement(XmlNamespace.Messages,
        XmlElementNames.SavedItemFolderId);
    this.savedCopyDestinationFolderId.writeToXml(writer);
    writer.writeEndElement();
  }
}
 
Example #11
Source File: MoveCopyItemResponse.java    From ews-java-api with MIT License 6 votes vote down vote up
/**
 * Reads response elements from XML.
 *
 * @param reader the reader
 * @throws Exception the exception
 */
@Override
protected void readElementsFromXml(EwsServiceXmlReader reader)
    throws Exception {
  super.readElementsFromXml(reader);
  List<Item> items = reader.readServiceObjectsCollectionFromXml(
      XmlElementNames.Items, this, false, /* clearPropertyBag */
      null, /* requestedPropertySet */
      false); /* summaryPropertiesOnly */

  // We only receive the copied or moved item if the copy or move
  // operation was within
  // a single mailbox. No item is returned if the operation is
  // cross-mailbox, from a
  // mailbox to a public folder or from a public folder to a mailbox.
  if (items.size() > 0) {
    this.item = items.get(0);
  }
}
 
Example #12
Source File: AttachmentCollection.java    From ews-java-api with MIT License 6 votes vote down vote up
/**
 * Adds an item attachment to the collection.
 *
 * @param <TItem> the generic type
 * @param cls     the cls
 * @return An ItemAttachment instance.
 * @throws Exception the exception
 */
public <TItem extends Item> GenericItemAttachment<TItem> addItemAttachment(
    Class<TItem> cls) throws Exception {
  if (cls.getDeclaredFields().length == 0) {
    throw new InvalidOperationException(String.format(
        "Items of type %s are not supported as attachments.", cls
            .getName()));
  }

  GenericItemAttachment<TItem> itemAttachment =
      new GenericItemAttachment<TItem>(
          this.owner);
  itemAttachment.setTItem((TItem) EwsUtilities.createItemFromItemClass(
      itemAttachment, cls, true));

  this.internalAdd(itemAttachment);

  return itemAttachment;
}
 
Example #13
Source File: UpdateItemRequest.java    From ews-java-api with MIT License 6 votes vote down vote up
@Override
protected void validate() throws ServiceLocalException, Exception {
  super.validate();
  EwsUtilities.validateParamCollection(this.getItems().iterator(), "Items");
  for (int i = 0; i < this.getItems().size(); i++) {
    if ((this.getItems().get(i) == null) ||
        this.getItems().get(i).isNew()) {
      throw new ArgumentException(String.format("Items[%d] is either null or does not have an Id.", i));
    }
  }

  if (this.savedItemsDestinationFolder != null) {
    this.savedItemsDestinationFolder.validate(this.getService()
        .getRequestedServerVersion());
  }

  // Validate each item.
  for (Item item : this.getItems()) {
    item.validate();
  }
}
 
Example #14
Source File: EwsUtilities.java    From ews-java-api with MIT License 5 votes vote down vote up
/**
 * Finds the first item of type TItem (not a descendant type) in the
 * specified collection.
 *
 * @param <TItem> TItem is the type of the item to find.
 * @param cls     the cls
 * @param items   the item
 * @return A TItem instance or null if no instance of TItem could be found.
 */
@SuppressWarnings("unchecked")
public static <TItem extends Item> TItem findFirstItemOfType(
  Class<TItem> cls, Iterable<Item> items
) {
  for (Item item : items) {
    // We're looking for an exact class match here.
    final Class<? extends Item> itemClass = item.getClass();
    if (itemClass.equals(cls)) {
      return (TItem) item;
    }
  }

  return null;
}
 
Example #15
Source File: ExchangeService.java    From ews-java-api with MIT License 5 votes vote down vote up
/**
 * Obtains a list of item by searching the contents of a specific folder.
 * Calling this method results in a call to EWS.
 *
 * @param parentFolderId the parent folder id
 * @param searchFilter   the search filter
 * @param view           the view
 * @return An object representing the results of the search operation.
 * @throws Exception the exception
 */
public FindItemsResults<Item> findItems(FolderId parentFolderId,
    SearchFilter searchFilter, ItemView view) throws Exception {
  EwsUtilities.validateParamAllowNull(searchFilter, "searchFilter");
  List<FolderId> folderIdArray = new ArrayList<FolderId>();
  folderIdArray.add(parentFolderId);
  ServiceResponseCollection<FindItemResponse<Item>> responses = this
      .findItems(folderIdArray, searchFilter, null, /* queryString */
          view, null, /* groupBy */
          ServiceErrorHandling.ThrowOnError);

  return responses.getResponseAtIndex(0).getResults();
}
 
Example #16
Source File: ExchangeFileSystem.java    From iaf with Apache License 2.0 5 votes vote down vote up
@Override
	public Map<String, Object> getAdditionalFileProperties(Item f) throws FileSystemException {
		EmailMessage emailMessage;
//		PropertySet ps = new PropertySet(EmailMessageSchema.DateTimeReceived,
//				EmailMessageSchema.From, EmailMessageSchema.Subject,
//				EmailMessageSchema.Body,
//				EmailMessageSchema.DateTimeSent);
		PropertySet ps=PropertySet.FirstClassProperties;
		try {
			emailMessage = EmailMessage.bind(exchangeService, f.getId(), ps);
			Map<String, Object> result=new LinkedHashMap<String,Object>();
			result.put("mailId", emailMessage.getInternetMessageId());
			result.put("toRecipients", makeListOfAdresses(emailMessage.getToRecipients()));
			result.put("ccRecipients", makeListOfAdresses(emailMessage.getCcRecipients()));
			result.put("bccRecipients", makeListOfAdresses(emailMessage.getBccRecipients()));
			result.put("from", emailMessage.getFrom().getAddress());
			result.put("subject", emailMessage.getSubject());
			result.put("dateTimeSent", emailMessage.getDateTimeSent());
			result.put("dateTimeReceived", emailMessage.getDateTimeReceived());
			Map<String,String> headers = new LinkedHashMap<String,String>();
			for(InternetMessageHeader internetMessageHeader : emailMessage.getInternetMessageHeaders()) {
				headers.put(internetMessageHeader.getName(), internetMessageHeader.getValue());
			}
			result.put("headers", headers);
			
//			for (Entry<PropertyDefinition, Object> entry:emailMessage.getPropertyBag().getProperties().entrySet()) {
//				result.put(entry.getKey().getName(), entry.getValue());
//			}
			return result;
		} catch (Exception e) {
			throw new FileSystemException(e);
		}
	}
 
Example #17
Source File: ExchangeFileSystem.java    From iaf with Apache License 2.0 5 votes vote down vote up
@Override
public boolean exists(Item f) throws FileSystemException {
	try {
		ItemView view = new ItemView(1);
		view.getOrderBy().add(ItemSchema.DateTimeReceived, SortDirection.Ascending);
		SearchFilter searchFilter =  new SearchFilter.IsEqualTo(ItemSchema.Id, f.getId().toString());
		FindItemsResults<Item> findResults;
		findResults = exchangeService.findItems(basefolderId,searchFilter, view);
		return findResults.getTotalCount()!=0;
	} catch (Exception e) {
		throw new FileSystemException(e);
	}
}
 
Example #18
Source File: CalendarActionResults.java    From ews-java-api with MIT License 5 votes vote down vote up
/**
 * Initializes a new instance of the class.
 *
 * @param items the item
 */
public CalendarActionResults(Iterable<Item> items) {
  this.appointment = EwsUtilities.findFirstItemOfType(Appointment.class, items);
  this.meetingRequest = EwsUtilities.findFirstItemOfType(
      MeetingRequest.class, items);
  this.meetingResponse = EwsUtilities.findFirstItemOfType(
      MeetingResponse.class, items);
  this.meetingCancellation = EwsUtilities.findFirstItemOfType(
      MeetingCancellation.class, items);
}
 
Example #19
Source File: ExchangeService.java    From ews-java-api with MIT License 5 votes vote down vote up
/**
 * Copies multiple item in a single call to EWS.
 *
 * @param itemId              the item id
 * @param destinationFolderId the destination folder id
 * @return A ServiceResponseCollection providing copy results for each of
 * the specified item Ids.
 * @throws Exception the exception
 */
public Item moveItem(ItemId itemId, FolderId destinationFolderId)
    throws Exception {
  List<ItemId> itemIdArray = new ArrayList<ItemId>();
  itemIdArray.add(itemId);

  return this.internalMoveItems(itemIdArray, destinationFolderId, null,
      ServiceErrorHandling.ThrowOnError).getResponseAtIndex(0)
      .getItem();
}
 
Example #20
Source File: ItemIdWrapperList.java    From ews-java-api with MIT License 5 votes vote down vote up
/**
 * Adds the specified item.
 *
 * @param items the item
 * @throws ServiceLocalException the service local exception
 */
public void addRangeItem(Iterable<Item> items)
    throws ServiceLocalException {
  for (Item item : items) {
    this.add(item);
  }
}
 
Example #21
Source File: ExchangeFileSystem.java    From iaf with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteFile(Item f) throws FileSystemException {
	 try {
		f.delete(DeleteMode.MoveToDeletedItems);
	} catch (Exception e) {
		throw new FileSystemException("Could not delete",e);
	}
}
 
Example #22
Source File: ExchangeService.java    From ews-java-api with MIT License 5 votes vote down vote up
/**
 * Obtains a grouped list of item by searching the contents of a specific
 * folder. Calling this method results in a call to EWS.
 *
 * @param parentFolderId the parent folder id
 * @param view           the view
 * @param groupBy        the group by
 * @return A list of item containing the contents of the specified folder.
 * @throws Exception the exception
 */
public GroupedFindItemsResults<Item> findItems(FolderId parentFolderId,
    ItemView view, Grouping groupBy) throws Exception {
  EwsUtilities.validateParam(groupBy, "groupBy");

  List<FolderId> folderIdArray = new ArrayList<FolderId>();
  folderIdArray.add(parentFolderId);

  ServiceResponseCollection<FindItemResponse<Item>> responses = this
      .findItems(folderIdArray, null, /* searchFilter */
          null, /* queryString */
          view, groupBy, ServiceErrorHandling.ThrowOnError);

  return responses.getResponseAtIndex(0).getGroupedFindResults();
}
 
Example #23
Source File: ExchangeFileSystem.java    From iaf with Apache License 2.0 5 votes vote down vote up
@Override
public Item toFile(String filename) throws FileSystemException {
	try {
		ItemId itemId = ItemId.getItemIdFromString(filename);
		Item item = Item.bind(exchangeService,itemId);
		return item;
	} catch (Exception e) {
		throw new FileSystemException("Cannot convert filename ["+filename+"] into an ItemId");
	}
}
 
Example #24
Source File: GetItemResponse.java    From ews-java-api with MIT License 5 votes vote down vote up
/**
 * Gets Item instance.
 *
 * @param service        the service
 * @param xmlElementName the xml element name
 * @return Item
 * @throws Exception the exception
 */
private Item getObjectInstance(ExchangeService service,
    String xmlElementName) throws Exception {
  if (this.getItem() != null) {
    return this.getItem();
  } else {
    return EwsUtilities.createEwsObjectFromXmlElementName(Item.class,
        service, xmlElementName);

  }
}
 
Example #25
Source File: GetItemResponse.java    From ews-java-api with MIT License 5 votes vote down vote up
/**
 * Reads response elements from XML.
 *
 * @param reader the reader
 * @throws InstantiationException the instantiation exception
 * @throws IllegalAccessException the illegal access exception
 * @throws Exception              the exception
 */
protected void readElementsFromXml(EwsServiceXmlReader reader)
    throws InstantiationException, IllegalAccessException, Exception {
  super.readElementsFromXml(reader);

  List<Item> items = reader.readServiceObjectsCollectionFromXml(
      XmlElementNames.Items, this,
      true, /* clearPropertyBag */
      this.propertySet, /* requestedPropertySet */
      false); /* summaryPropertiesOnly */

  this.item = items.get(0);
}
 
Example #26
Source File: ExchangeService.java    From ews-java-api with MIT License 5 votes vote down vote up
/**
 * Loads the property of multiple item in a single call to EWS.
 *
 * @param items         the item
 * @param propertySet   the property set
 * @param errorHandling the error handling
 * @return A ServiceResponseCollection providing results for each of the
 * specified item.
 * @throws Exception the exception
 */
public ServiceResponseCollection<ServiceResponse> internalLoadPropertiesForItems(Iterable<Item> items,
    PropertySet propertySet, ServiceErrorHandling errorHandling) throws Exception {
  GetItemRequestForLoad request = new GetItemRequestForLoad(this,
      errorHandling);
  // return null;

  request.getItemIds().addRangeItem(items);
  request.setPropertySet(propertySet);

  return request.execute();
}
 
Example #27
Source File: ExchangeService.java    From ews-java-api with MIT License 5 votes vote down vote up
/**
 * Binds to multiple item in a single call to EWS.
 *
 * @param itemId      the item id
 * @param propertySet the property set
 * @return A ServiceResponseCollection providing results for each of the
 * specified item Ids.
 * @throws Exception the exception
 */
public Item bindToItem(ItemId itemId, PropertySet propertySet)
    throws Exception {
  EwsUtilities.validateParam(itemId, "itemId");
  EwsUtilities.validateParam(propertySet, "propertySet");
  List<ItemId> itmLst = new ArrayList<ItemId>();
  itmLst.add(itemId);
  ServiceResponseCollection<GetItemResponse> responses = this
      .internalBindToItems(itmLst, propertySet, ServiceErrorHandling.ThrowOnError);

  return responses.getResponseAtIndex(0).getItem();
}
 
Example #28
Source File: ExchangeService.java    From ews-java-api with MIT License 5 votes vote down vote up
/**
 * Bind to item.
 *
 * @param <TItem>     The type of the item.
 * @param c           the c
 * @param itemId      the item id
 * @param propertySet the property set
 * @return the t item
 * @throws Exception the exception
 */
public <TItem extends Item> TItem bindToItem(Class<TItem> c, ItemId itemId, PropertySet propertySet) throws Exception {
  Item result = this.bindToItem(itemId, propertySet);
  if (c.isAssignableFrom(result.getClass())) {
    return (TItem) result;
  } else {
    throw new ServiceLocalException(String.format(
        "The item type returned by the service (%s) isn't compatible with the requested item type (%s).", result.getClass().getName(),
        c.getName()));
  }
}
 
Example #29
Source File: ExchangeFileSystem.java    From iaf with Apache License 2.0 5 votes vote down vote up
public Item extractNestedItem(Item item) throws Exception {
	Iterator<Attachment> attachments = listAttachments(item);
	if (attachments!=null) {
		while (attachments.hasNext()) {
			Attachment attachment=attachments.next();
			if (attachment instanceof ItemAttachment) {
				ItemAttachment itemAttachment = (ItemAttachment)attachment;
				itemAttachment.load();
				return itemAttachment.getItem();
			}
		}
	}
	return null;
}
 
Example #30
Source File: CreateItemRequest.java    From ews-java-api with MIT License 5 votes vote down vote up
/**
 * Validate request..
 *
 * @throws ServiceLocalException the service local exception
 * @throws Exception             the exception
 */
@Override
protected void validate() throws ServiceLocalException, Exception {
  super.validate();
  //	Iterable<Item> item = this.getItems();
  // Validate each item.
  for (Item item : this.getItems()) {
    item.validate();
  }
}