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.core.service.item;
025
026import java.util.Date;
027
028import org.apache.commons.logging.Log;
029import org.apache.commons.logging.LogFactory;
030
031import microsoft.exchange.webservices.data.attribute.ServiceObjectDefinition;
032import microsoft.exchange.webservices.data.core.ExchangeService;
033import microsoft.exchange.webservices.data.core.PropertySet;
034import microsoft.exchange.webservices.data.core.XmlElementNames;
035import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
036import microsoft.exchange.webservices.data.core.enumeration.service.calendar.AppointmentType;
037import microsoft.exchange.webservices.data.core.exception.service.local.ServiceLocalException;
038import microsoft.exchange.webservices.data.core.service.schema.MeetingResponseSchema;
039import microsoft.exchange.webservices.data.core.service.schema.ServiceObjectSchema;
040import microsoft.exchange.webservices.data.property.complex.ItemAttachment;
041import microsoft.exchange.webservices.data.property.complex.ItemId;
042import microsoft.exchange.webservices.data.property.complex.recurrence.pattern.Recurrence;
043
044/**
045 * Represents a response to a meeting request. Properties available on meeting
046 * messages are defined in the MeetingMessageSchema class.
047 */
048@ServiceObjectDefinition(xmlElementName = XmlElementNames.MeetingResponse)
049public class MeetingResponse extends MeetingMessage {
050
051  private static final Log LOG = LogFactory.getLog(MeetingResponse.class);
052
053  /**
054   * Initializes a new instance of the class.
055   *
056   * @param parentAttachment The parentAttachment
057   * @throws Exception the exception
058   */
059  public MeetingResponse(ItemAttachment parentAttachment)
060      throws Exception {
061    super(parentAttachment);
062  }
063
064  /**
065   * Initializes a new instance of the class.
066   *
067   * @param service EWS service to which this object belongs.
068   * @throws Exception the exception
069   */
070  public MeetingResponse(ExchangeService service) throws Exception {
071    super(service);
072  }
073
074  /**
075   * Binds to an existing meeting response and loads the specified set of
076   * property. Calling this method results in a call to EWS.
077   *
078   * @param service     The service to use to bind to the meeting response.
079   * @param id          The Id of the meeting response to bind to.
080   * @param propertySet The set of property to load.
081   * @return A MeetingResponse instance representing the meeting response
082   * corresponding to the specified Id.
083   */
084  public static MeetingResponse bind(ExchangeService service, ItemId id,
085      PropertySet propertySet) {
086    try {
087      return service.bindToItem(MeetingResponse.class, id, propertySet);
088    } catch (Exception e) {
089      LOG.error(e);
090      return null;
091    }
092  }
093
094  /**
095   * Binds to an existing meeting response and loads the specified set of
096   * property. Calling this method results in a call to EWS.
097   *
098   * @param service The service to use to bind to the meeting response.
099   * @param id      The Id of the meeting response to bind to.
100   * @return A MeetingResponse instance representing the meeting response
101   * corresponding to the specified Id.
102   */
103  public static MeetingResponse bind(ExchangeService service, ItemId id) {
104    return MeetingResponse.bind(service, id, PropertySet
105        .getFirstClassProperties());
106  }
107
108  /**
109   * Internal method to return the schema associated with this type of object.
110   *
111   * @return The schema associated with this type of object.
112   */
113  @Override public ServiceObjectSchema getSchema() {
114    return MeetingResponseSchema.Instance;
115  }
116
117  /**
118   * Gets the minimum required server version.
119   *
120   * @return Earliest Exchange version in which this service object type is
121   * supported.
122   */
123  @Override public ExchangeVersion getMinimumRequiredServerVersion() {
124    return ExchangeVersion.Exchange2007_SP1;
125  }
126
127  // Properties
128
129  /**
130   * Gets the start time of the appointment.
131   *
132   * @return the start
133   * @throws ServiceLocalException the service local exception
134   */
135  public Date getStart() throws ServiceLocalException {
136    return getPropertyBag().getObjectFromPropertyDefinition(
137        MeetingResponseSchema.Start);
138  }
139
140  /**
141   * Gets or sets the end time of the appointment.
142   *
143   * @return the end
144   * @throws ServiceLocalException the service local exception
145   */
146  public Date getEnd() throws ServiceLocalException {
147    return getPropertyBag().getObjectFromPropertyDefinition(
148        MeetingResponseSchema.End);
149  }
150
151  /**
152   * Gets  the location of this appointment.
153   *
154   * @return the location
155   * @throws ServiceLocalException the service local exception
156   */
157  public String getLocation() throws ServiceLocalException {
158    return getPropertyBag().getObjectFromPropertyDefinition(
159        MeetingResponseSchema.Location);
160  }
161
162  /**
163   * Gets the recurrence pattern for this appointment. Available
164   * recurrence pattern classes include Recurrence.DailyPattern,
165   * Recurrence.MonthlyPattern and Recurrence.YearlyPattern.
166   *
167   * @return the recurrence
168   * @throws ServiceLocalException the service local exception
169   */
170  public Recurrence getRecurrence() throws ServiceLocalException {
171    return getPropertyBag().getObjectFromPropertyDefinition(
172        MeetingResponseSchema.Recurrence);
173  }
174
175  /**
176   * Gets a value indicating the type of this appointment.
177   *
178   * @return the appointment type
179   * @throws ServiceLocalException the service local exception
180   */
181  public AppointmentType getAppointmentType() throws ServiceLocalException {
182    return getPropertyBag().getObjectFromPropertyDefinition(
183        MeetingResponseSchema.AppointmentType);
184  }
185
186  /**
187   * Gets the proposed start time.
188   *
189   * @return the start
190   * @throws ServiceLocalException the service local exception
191   */
192  public Date getProposedStart() throws ServiceLocalException {
193    return getPropertyBag().getObjectFromPropertyDefinition(
194        MeetingResponseSchema.ProposedStart);
195  }
196
197  /**
198   * Sets the proposed start.
199   *
200   * @param value the proposed start
201   * @throws Exception
202   */
203  public void setProposedStart(Date value) throws Exception {
204    this.getPropertyBag().setObjectFromPropertyDefinition(
205        MeetingResponseSchema.ProposedStart, value);
206  }
207
208  /**
209   * Gets the proposed end time.
210   *
211   * @return the start
212   * @throws ServiceLocalException the service local exception
213   */
214  public Date getProposedEnd() throws ServiceLocalException {
215    return getPropertyBag().getObjectFromPropertyDefinition(
216        MeetingResponseSchema.ProposedEnd);
217  }
218
219  /**
220   * Sets the proposed end.
221   *
222   * @param value the proposed start
223   * @throws Exception
224   */
225  public void setProposedEnd(Date value) throws Exception {
226    this.getPropertyBag().setObjectFromPropertyDefinition(
227        MeetingResponseSchema.ProposedEnd, value);
228  }
229
230}