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    
024    package microsoft.exchange.webservices.data.core.request;
025    
026    import microsoft.exchange.webservices.data.core.EwsServiceXmlReader;
027    import microsoft.exchange.webservices.data.core.EwsServiceXmlWriter;
028    import microsoft.exchange.webservices.data.core.ExchangeService;
029    import microsoft.exchange.webservices.data.core.XmlElementNames;
030    import microsoft.exchange.webservices.data.core.response.FindConversationResponse;
031    import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
032    import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace;
033    import microsoft.exchange.webservices.data.core.exception.service.local.ServiceLocalException;
034    import microsoft.exchange.webservices.data.core.exception.service.local.ServiceXmlSerializationException;
035    import microsoft.exchange.webservices.data.misc.FolderIdWrapper;
036    import microsoft.exchange.webservices.data.search.ConversationIndexedItemView;
037    import microsoft.exchange.webservices.data.search.filter.SearchFilter;
038    
039    /**
040     * Represents a request to a Find Conversation operation
041     */
042    public final class FindConversationRequest extends SimpleServiceRequestBase<FindConversationResponse> {
043    
044    
045      private ConversationIndexedItemView view;
046      private SearchFilter.IsEqualTo searchFilter;
047      private FolderIdWrapper folderId;
048    
049      /**
050       * @throws Exception
051       */
052      public FindConversationRequest(ExchangeService service)
053          throws Exception {
054        super(service);
055      }
056    
057    
058      /**
059       * Gets or sets the view controlling the number of conversations returned.
060       */
061      protected ConversationIndexedItemView getIndexedItemView() {
062        return this.view;
063      }
064    
065      public void setIndexedItemView(ConversationIndexedItemView value) {
066        this.view = value;
067      }
068    
069    
070    
071      /**
072       * Gets or sets the search filter.
073       */
074      protected SearchFilter.IsEqualTo getConversationViewFilter() {
075    
076        return this.searchFilter;
077      }
078    
079      public void setConversationViewFilter(SearchFilter.IsEqualTo value) {
080        this.searchFilter = value;
081    
082      }
083    
084      /**
085       * Gets or sets folder id
086       */
087      protected FolderIdWrapper getFolderId() {
088        return this.folderId;
089      }
090    
091      public void setFolderId(FolderIdWrapper value) {
092        this.folderId = value;
093      }
094    
095    
096      /**
097       * Validate request.
098       *
099       * @throws Exception
100       * @throws ServiceLocalException
101       */
102      @Override
103      protected void validate() throws ServiceLocalException, Exception {
104        super.validate();
105        this.view.internalValidate(this);
106      }
107    
108    
109      /**
110       * Writes XML attribute.
111       *
112       * @param writer The writer.
113       * @throws ServiceXmlSerializationException
114       */
115      @Override
116      protected void writeAttributesToXml(EwsServiceXmlWriter writer)
117          throws ServiceXmlSerializationException {
118        super.writeAttributesToXml(writer);
119      }
120    
121    
122      /**
123       * Writes XML attribute.
124       *
125       * @param writer The writer.
126       * @throws Exception
127       */
128      @Override
129      protected void writeElementsToXml(EwsServiceXmlWriter writer)
130          throws Exception {
131        this.getIndexedItemView().writeToXml(writer);
132    
133        if (this.getConversationViewFilter() != null) {
134          writer.writeStartElement(XmlNamespace.Messages,
135              XmlElementNames.Restriction);
136          this.getConversationViewFilter().writeToXml(writer);
137          writer.writeEndElement(); // Restriction
138        }
139    
140        this.getIndexedItemView().writeOrderByToXml(writer);
141    
142        writer.writeStartElement(XmlNamespace.Messages,
143            XmlElementNames.ParentFolderId);
144        this.getFolderId().writeToXml(writer);
145        writer.writeEndElement();
146      }
147    
148      /**
149       * {@inheritDoc}
150       */
151      @Override
152      protected FindConversationResponse parseResponse(EwsServiceXmlReader reader)
153          throws Exception {
154        FindConversationResponse response = new FindConversationResponse();
155        response.loadFromXml(reader,
156            XmlElementNames.FindConversationResponse);
157        return response;
158      }
159    
160      /**
161       * Gets the name of the XML element.
162       *
163       * @return XML element name.
164       */
165      @Override public String getXmlElementName() {
166        return XmlElementNames.FindConversation;
167      }
168    
169      /**
170       * Gets the name of the response XML element.
171       *
172       * @return XML element name.
173       */
174      @Override
175      protected String getResponseXmlElementName() {
176        return XmlElementNames.FindConversationResponse;
177      }
178    
179      /**
180       * Gets the request version.
181       *
182       * @return Earliest Exchange version in which this request is supported.
183       */
184      @Override
185      protected ExchangeVersion getMinimumRequiredServerVersion() {
186        return ExchangeVersion.Exchange2010_SP1;
187      }
188    
189      /**
190       * Executes this request.
191       *
192       * @return Service response.
193       * @throws Exception
194       * @throws ServiceLocalException
195       */
196      public FindConversationResponse execute()
197          throws ServiceLocalException, Exception {
198        FindConversationResponse serviceResponse = internalExecute();
199        serviceResponse.throwIfNecessary();
200        return serviceResponse;
201      }
202    }
203