001/*
002 * The MIT License
003 * Copyright (c) 2012 Microsoft Corporation
004 *
005 * Permission is hereby granted, free of charge, to any person obtaining a copy
006 * of this software and associated documentation files (the "Software"), to deal
007 * in the Software without restriction, including without limitation the rights
008 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
009 * copies of the Software, and to permit persons to whom the Software is
010 * furnished to do so, subject to the following conditions:
011 *
012 * The above copyright notice and this permission notice shall be included in
013 * all copies or substantial portions of the Software.
014 *
015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
018 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
019 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
021 * THE SOFTWARE.
022 */
023
024package microsoft.exchange.webservices.data.autodiscover.request;
025
026import microsoft.exchange.webservices.data.core.EwsServiceXmlWriter;
027import microsoft.exchange.webservices.data.core.EwsUtilities;
028import microsoft.exchange.webservices.data.core.ExchangeService;
029import microsoft.exchange.webservices.data.core.XmlElementNames;
030import microsoft.exchange.webservices.data.core.request.MultiResponseServiceRequest;
031import microsoft.exchange.webservices.data.core.response.ServiceResponse;
032import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
033import microsoft.exchange.webservices.data.core.enumeration.service.error.ServiceErrorHandling;
034import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace;
035import microsoft.exchange.webservices.data.misc.ConversationAction;
036
037import java.util.ArrayList;
038import java.util.List;
039
040/**
041 * Represents a request to a Apply Conversation Action operation
042 */
043public final class ApplyConversationActionRequest extends MultiResponseServiceRequest<ServiceResponse> {
044
045  private List<ConversationAction> conversationActions =
046      new ArrayList<ConversationAction>();
047
048  public List<ConversationAction> getConversationActions() {
049    return this.conversationActions;
050  }
051
052  /**
053   * Initializes a new instance of the ApplyConversationActionRequest class
054   *
055   * @param service           The service
056   * @param errorHandlingMode Indicates how errors should be handled
057   * @throws Exception on error
058   */
059  public ApplyConversationActionRequest(ExchangeService service, ServiceErrorHandling errorHandlingMode) throws Exception {
060    super(service, errorHandlingMode);
061  }
062
063  /**
064   * Creates the service response.
065   *
066   * @param service       The service.
067   * @param responseIndex Index of the response.
068   * @return Service response.
069   */
070  @Override
071  protected ServiceResponse createServiceResponse(ExchangeService service,
072      int responseIndex) {
073    return new ServiceResponse();
074  }
075
076  /**
077   * Gets the expected response message count.
078   *
079   * @return Number of expected response messages.
080   */
081  @Override
082  protected int getExpectedResponseMessageCount() {
083    return this.conversationActions.size();
084  }
085
086  /**
087   * Validate request.
088   *
089   * @throws Exception on validation error
090   */
091  @Override
092  protected void validate() throws Exception {
093    super.validate();
094    EwsUtilities.validateParamCollection(
095      conversationActions.iterator(), "conversationActions"
096    );
097
098    for (int iAction = 0; iAction < this.getConversationActions().size(); iAction++) {
099      this.getConversationActions().get(iAction).validate();
100    }
101  }
102
103
104  /**
105   * Writes XML elements.
106   *
107   * @param writer The writer.
108   * @throws Exception on validation error
109   */
110  @Override
111  protected void writeElementsToXml(EwsServiceXmlWriter writer) throws Exception {
112    writer.writeStartElement(
113        XmlNamespace.Messages,
114        XmlElementNames.ConversationActions);
115    for (int iAction = 0; iAction < this.getConversationActions().size(); iAction++) {
116      this.getConversationActions().get(iAction).
117          writeElementsToXml(writer);
118    }
119    writer.writeEndElement();
120  }
121
122  /**
123   * Gets the name of the XML element.
124   *
125   * @return XML element name.
126   */
127  @Override public String getXmlElementName() {
128    return XmlElementNames.ApplyConversationAction;
129  }
130
131  /**
132   * Gets the name of the response XML element.
133   *
134   * @return XML element name.
135   */
136  @Override
137  protected String getResponseXmlElementName() {
138    return XmlElementNames.ApplyConversationActionResponse;
139  }
140
141  /**
142   * Gets the name of the response message XML element.
143   *
144   * @return XML element name.
145   */
146  @Override
147  protected String getResponseMessageXmlElementName() {
148    return XmlElementNames.ApplyConversationActionResponseMessage;
149  }
150
151  /**
152   * Gets the request version.
153   *
154   * @return Earliest Exchange version in which this request is supported.
155   */
156  @Override
157  protected ExchangeVersion getMinimumRequiredServerVersion() {
158    return ExchangeVersion.Exchange2010_SP1;
159  }
160}
161