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

The following examples show how to use microsoft.exchange.webservices.data.core.service.item.Item. These examples are extracted from open source projects. 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 Project: ews-java-api   Source File: AttachmentCollection.java    License: 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 2
Source Project: iaf   Source File: ExchangeFileSystem.java    License: 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 3
Source Project: iaf   Source File: ExchangeFileSystem.java    License: Apache License 2.0 6 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 4
Source Project: ews-java-api   Source File: ExchangeService.java    License: 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 5
Source Project: ews-java-api   Source File: ExchangeService.java    License: 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 6
Source Project: ews-java-api   Source File: ExchangeService.java    License: 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 7
Source Project: ews-java-api   Source File: ExchangeService.java    License: 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 8
Source Project: ews-java-api   Source File: ExchangeService.java    License: 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 9
Source Project: ews-java-api   Source File: SendItemRequest.java    License: 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 10
Source Project: ews-java-api   Source File: UpdateItemRequest.java    License: 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 11
Source Project: ews-java-api   Source File: UpdateItemRequest.java    License: 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 12
Source Project: ews-java-api   Source File: MoveCopyItemResponse.java    License: 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 13
Source Project: ews-java-api   Source File: EwsUtilitiesTest.java    License: 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 14
Source Project: ews-java-api   Source File: AttachmentCollection.java    License: MIT License 5 votes vote down vote up
/**
 * The owner of this attachment collection.
 *
 * @param value accepts ServiceObject
 */
public void setOwner(ServiceObject value) {
  Item item = (Item) value;
  EwsUtilities.ewsAssert(item != null, "AttachmentCollection.IOwnedProperty.set_Owner",
                         "value is not a descendant of ItemBase");

  this.owner = item;
}
 
Example 15
Source Project: ews-java-api   Source File: Folder.java    License: MIT License 5 votes vote down vote up
/**
 * Find item.
 *
 * @param queryString query string to be used for indexed search
 * @param view        The view controlling the number of item returned.
 * @return FindItems results collection.
 * @throws Exception the exception
 */
public FindItemsResults<Item> findItems(String queryString, ItemView view)
    throws Exception {
  EwsUtilities.validateParamAllowNull(queryString, "queryString");

  ServiceResponseCollection<FindItemResponse<Item>> responses = this
      .internalFindItems(queryString, view, null /* groupBy */);

  return responses.getResponseAtIndex(0).getResults();
}
 
Example 16
Source Project: ews-java-api   Source File: ItemAttachment.java    License: MIT License 5 votes vote down vote up
/**
 * Sets the item associated with the attachment.
 *
 * @param item the new item
 */
protected void setItem(Item item) {
  this.throwIfThisIsNotNew();

  if (this.item != null) {

    this.item.removeServiceObjectChangedEvent(this);
  }
  this.item = item;
  if (this.item != null) {
    this.item.addServiceObjectChangedEvent(this);
  }
}
 
Example 17
Source Project: ews-java-api   Source File: CalendarActionResults.java    License: 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 18
Source Project: ews-java-api   Source File: ItemIdWrapperList.java    License: 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 19
Source Project: iaf   Source File: ExchangeFileSystem.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public long getFileSize(Item f) throws FileSystemException {
	try {
		return f.getSize();
	} catch (ServiceLocalException e) {
		throw new FileSystemException("Could not determine size",e);
	}
}
 
Example 20
Source Project: iaf   Source File: ExchangeMailListenerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
	public void moveAndCopyToFolders() throws Exception {
		String baseFolder=basefolder2;
		String targetFolder="FileWithAttachments";
		String processedFolder = "processedFolder";
		String logFolder = "logFolder";
		String recipient=mailaddress;
//		String subfolder="Basic";
//		String filename = "readFile";
//		String contents = "Tekst om te lezen";
		
		mailListener.setBaseFolder(baseFolder);
		mailListener.setProcessedFolder(processedFolder);
		mailListener.setLogFolder(logFolder);
		mailListener.setCreateFolders(true);
		configureAndOpen(targetFolder,null);
		
//		if (!folderContainsMessages(subfolder)) {
//			createFile(null, filename, contents);
//			waitForActionToFinish();
//		}
		
		Map<String,Object> threadContext=new HashMap<String,Object>();
		Item rawMessage = (Item)mailListener.getRawMessage(threadContext);
		assertNotNull("no message found", rawMessage);

		PipeLineResult plr = new PipeLineResult();
		plr.setState(PipeLineExit.EXIT_STATE_SUCCESS);
		plr.setResult(new Message("ResultOfPipeline"));
		plr.setExitCode(200);
		
		mailListener.afterMessageProcessed(plr, rawMessage, threadContext);

		
	}
 
Example 21
Source Project: ews-java-api   Source File: ExchangeService.java    License: 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 22
Source Project: ews-java-api   Source File: ExchangeService.java    License: 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 queryString    the query string
 * @param view           the view
 * @return An object representing the results of the search operation.
 * @throws Exception the exception
 */
public FindItemsResults<Item> findItems(FolderId parentFolderId,
    String queryString, ItemView view) throws Exception {
  EwsUtilities.validateParamAllowNull(queryString, "queryString");

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

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

  return responses.getResponseAtIndex(0).getResults();
}
 
Example 23
Source Project: ews-java-api   Source File: ExchangeService.java    License: 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 24
Source Project: iaf   Source File: ExchangeFileSystem.java    License: 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 25
Source Project: iaf   Source File: ExchangeFileSystem.java    License: 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 26
Source Project: ews-java-api   Source File: ExchangeService.java    License: 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 27
Source Project: iaf   Source File: ExchangeFileSystem.java    License: 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 28
Source Project: ews-java-api   Source File: ExchangeService.java    License: 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 29
Source Project: ews-java-api   Source File: ExchangeService.java    License: 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 30
Source Project: ews-java-api   Source File: ExchangeService.java    License: 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()));
  }
}