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 UpdateDelegate request.
041 */
042 public class UpdateDelegateRequest 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 UpdateDelegateRequest(ExchangeService service)
062 throws Exception {
063 super(service);
064 }
065
066 /**
067 * Validate request.
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
080 /**
081 * Writes XML elements.
082 *
083 * @param writer the writer
084 * @throws Exception the exception
085 */
086 @Override
087 protected void writeElementsToXml(EwsServiceXmlWriter writer)
088 throws Exception {
089 super.writeElementsToXml(writer);
090
091 writer.writeStartElement(XmlNamespace.Messages,
092 XmlElementNames.DelegateUsers);
093
094 for (DelegateUser delegateUser : this.getDelegateUsers()) {
095 delegateUser.writeToXml(writer, XmlElementNames.DelegateUser);
096 }
097
098 writer.writeEndElement(); // DelegateUsers
099
100 if (this.getMeetingRequestsDeliveryScope() != null) {
101 writer.writeElementValue(XmlNamespace.Messages,
102 XmlElementNames.DeliverMeetingRequests, this
103 .getMeetingRequestsDeliveryScope());
104 }
105 }
106
107 /**
108 * Gets the name of the response XML element.
109 *
110 * @return XML element name.
111 */
112 @Override
113 protected String getResponseXmlElementName() {
114 return XmlElementNames.UpdateDelegateResponse;
115 }
116
117 /**
118 * Creates the response.
119 *
120 * @return Response object.
121 */
122 @Override
123 protected DelegateManagementResponse createResponse() {
124 return new DelegateManagementResponse(true, this.delegateUsers);
125 }
126
127 /**
128 * Gets the name of the XML element.
129 *
130 * @return Xml element name.
131 */
132 @Override public String getXmlElementName() {
133 return XmlElementNames.UpdateDelegate;
134 }
135
136 /**
137 * Gets the request version.
138 *
139 * @return Earliest Exchange version in which this request is supported.
140 */
141 @Override
142 protected ExchangeVersion getMinimumRequiredServerVersion() {
143 return ExchangeVersion.Exchange2007_SP1;
144 }
145
146 /**
147 * Gets the meeting request delivery scope.
148 *
149 * @return the meeting request delivery scope
150 */
151 public MeetingRequestsDeliveryScope getMeetingRequestsDeliveryScope() {
152 return this.meetingRequestsDeliveryScope;
153 }
154
155 /**
156 * Sets the meeting request delivery scope.
157 *
158 * @param value the new meeting request delivery scope
159 */
160 public void setMeetingRequestsDeliveryScope(
161 MeetingRequestsDeliveryScope value) {
162 this.meetingRequestsDeliveryScope = value;
163 }
164
165 /**
166 * Gets the delegate users.
167 *
168 * @return the delegate users
169 */
170 public List<DelegateUser> getDelegateUsers() {
171 return this.delegateUsers;
172 }
173
174 }