001package microsoft.exchange.webservices.data.core.request; 002 003import microsoft.exchange.webservices.data.core.*; 004import microsoft.exchange.webservices.data.core.enumeration.misc.*; 005import microsoft.exchange.webservices.data.core.enumeration.service.error.*; 006import microsoft.exchange.webservices.data.core.response.*; 007import microsoft.exchange.webservices.data.core.service.item.*; 008 009import java.util.*; 010 011public class UploadItemsRequest extends MultiResponseServiceRequest<UploadItemsResponse> { 012 013 private List<UploadItem> items; 014 015 /** 016 * The item ids. 017 */ 018 019 /** 020 * Initializes a new instance of the class. 021 * 022 * @param service the service 023 * @param errorHandlingMode the error handling mode 024 * @throws Exception 025 */ 026 public UploadItemsRequest(ExchangeService service, ServiceErrorHandling errorHandlingMode) 027 throws Exception { 028 super(service, errorHandlingMode); 029 } 030 031 /** 032 * Validate request. 033 * 034 * @throws Exception the exception 035 */ 036 @Override 037 protected void validate() throws Exception { 038 super.validate(); 039 EwsUtilities.validateParam(items, "items"); 040 for (UploadItem i : items) { 041 i.validate(); 042 } 043 } 044 045 /** 046 * Gets the expected response message count. 047 * 048 * @return Number of expected response messages 049 */ 050 @Override 051 protected int getExpectedResponseMessageCount() { 052 return items.size(); 053 } 054 055 /** 056 * Creates the service response. 057 * 058 * @param service the service 059 * @param responseIndex the response index 060 * @return Service response. 061 */ 062 @Override 063 protected UploadItemsResponse createServiceResponse(ExchangeService service, 064 int responseIndex) { 065 return new UploadItemsResponse(); 066 } 067 068 /** 069 * Gets the name of the XML element. 070 * 071 * @return XML element name 072 */ 073 @Override 074 public String getXmlElementName() { 075 return XmlElementNames.UploadItems; 076 } 077 078 /** 079 * Gets the name of the response XML element. 080 * 081 * @return XML element name 082 */ 083 @Override 084 protected String getResponseXmlElementName() { 085 return XmlElementNames.UploadItemsResponse; 086 } 087 088 /** 089 * Gets the name of the response message XML element. 090 * 091 * @return XML element name 092 */ 093 @Override 094 protected String getResponseMessageXmlElementName() { 095 return XmlElementNames.UploadItemsResponseMessage; 096 } 097 098 /** 099 * Writes XML elements. 100 * 101 * @param writer the writer 102 * @throws Exception the exception 103 */ 104 @Override 105 protected void writeElementsToXml(EwsServiceXmlWriter writer) 106 throws Exception { 107 if (!items.isEmpty()) { 108 writer.writeStartElement(XmlNamespace.Messages, XmlElementNames.Items); 109 items.stream().forEach(item -> item.writeToXml(writer)); 110 writer.writeEndElement(); 111 } 112 } 113 114 /** 115 * Gets the request version. 116 * 117 * @return Earliest Exchange version in which this request is supported. 118 */ 119 @Override 120 protected ExchangeVersion getMinimumRequiredServerVersion() { 121 return ExchangeVersion.Exchange2010_SP1; 122 } 123 124 public void setItems(List<UploadItem> items) { 125 this.items = items; 126 } 127 128 public List<UploadItem> getItems() { 129 return items; 130 } 131}