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.EwsServiceXmlWriter;
027    import microsoft.exchange.webservices.data.core.EwsUtilities;
028    import microsoft.exchange.webservices.data.core.ExchangeService;
029    import microsoft.exchange.webservices.data.core.XmlElementNames;
030    import microsoft.exchange.webservices.data.core.response.DelegateManagementResponse;
031    import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
032    import microsoft.exchange.webservices.data.core.enumeration.service.MeetingRequestsDeliveryScope;
033    import microsoft.exchange.webservices.data.core.enumeration.misc.XmlNamespace;
034    import microsoft.exchange.webservices.data.property.complex.DelegateUser;
035    
036    import java.util.ArrayList;
037    import java.util.List;
038    
039    /**
040     * Represents an AddDelegate request.
041     */
042    public class AddDelegateRequest extends
043        DelegateManagementRequestBase<DelegateManagementResponse> {
044    
045      /**
046       * The delegate users.
047       */
048      private List<DelegateUser> delegateUsers = new ArrayList<DelegateUser>();
049    
050      /**
051       * The meeting request delivery scope.
052       */
053      private MeetingRequestsDeliveryScope meetingRequestsDeliveryScope;
054    
055      /**
056       * Initializes a new instance of the class.
057       *
058       * @param service the service
059       * @throws Exception
060       */
061      public AddDelegateRequest(ExchangeService service)
062          throws Exception {
063        super(service);
064      }
065    
066      /**
067       * Initializes a new instance of the class.
068       *
069       * @throws Exception the exception
070       */
071      @Override
072      protected void validate() throws Exception {
073        super.validate();
074        EwsUtilities.validateParamCollection(this.getDelegateUsers().iterator(), "DelegateUsers");
075        for (DelegateUser delegateUser : this.getDelegateUsers()) {
076          delegateUser.validateUpdateDelegate();
077        }
078    
079        if (this.meetingRequestsDeliveryScope != null) {
080          EwsUtilities.validateEnumVersionValue(this.
081                  getMeetingRequestsDeliveryScope(),
082              this.getService().getRequestedServerVersion());
083        }
084      }
085    
086      /**
087       * Writes the elements to XML.
088       *
089       * @param writer the writer
090       * @throws Exception the exception
091       */
092      @Override
093      protected void writeElementsToXml(EwsServiceXmlWriter writer)
094          throws Exception {
095        super.writeElementsToXml(writer);
096    
097        writer.writeStartElement(XmlNamespace.Messages,
098            XmlElementNames.DelegateUsers);
099    
100        for (DelegateUser delegateUser : this.getDelegateUsers()) {
101          delegateUser.writeToXml(writer, XmlElementNames.DelegateUser);
102        }
103    
104        writer.writeEndElement(); // DelegateUsers
105    
106        if (this.getMeetingRequestsDeliveryScope() != null) {
107          writer.writeElementValue(XmlNamespace.Messages,
108              XmlElementNames.DeliverMeetingRequests, this
109                  .getMeetingRequestsDeliveryScope());
110        }
111      }
112    
113      /**
114       * Gets the name of the XML element.
115       *
116       * @return XML element name.
117       */
118      @Override public String getXmlElementName() {
119        return XmlElementNames.AddDelegate;
120      }
121    
122      /**
123       * Gets the name of the response XML element.
124       *
125       * @return XML element name.
126       */
127      @Override
128      protected String getResponseXmlElementName() {
129        return XmlElementNames.AddDelegateResponse;
130      }
131    
132      /**
133       * Creates the response.
134       *
135       * @return Service response.
136       */
137      @Override
138      protected DelegateManagementResponse createResponse() {
139        return new DelegateManagementResponse(true, this.delegateUsers);
140      }
141    
142      /**
143       * Gets the request version.
144       *
145       * @return Earliest Exchange version in which this request is supported.
146       */
147      @Override
148      protected ExchangeVersion getMinimumRequiredServerVersion() {
149        return ExchangeVersion.Exchange2007_SP1;
150      }
151    
152      /**
153       * Gets the meeting request delivery scope. <value>The meeting
154       * request delivery scope.</value>
155       *
156       * @return the meeting request delivery scope
157       */
158      public MeetingRequestsDeliveryScope getMeetingRequestsDeliveryScope() {
159        return this.meetingRequestsDeliveryScope;
160      }
161    
162      /**
163       * Sets the meeting request delivery scope.
164       *
165       * @param meetingRequestsDeliveryScope the new meeting request delivery scope
166       */
167      public void setMeetingRequestsDeliveryScope(
168          MeetingRequestsDeliveryScope meetingRequestsDeliveryScope) {
169        this.meetingRequestsDeliveryScope = meetingRequestsDeliveryScope;
170      }
171    
172      /**
173       * Gets the delegate users. <value>The delegate users.</value>
174       *
175       * @return the delegate users
176       */
177      public List<DelegateUser> getDelegateUsers() {
178        return this.delegateUsers;
179      }
180    
181    }