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 microsoft.exchange.webservices.data.attribute.RequiredServerVersion;
027import microsoft.exchange.webservices.data.attribute.ServiceObjectDefinition;
028import microsoft.exchange.webservices.data.core.ExchangeService;
029import microsoft.exchange.webservices.data.core.PropertySet;
030import microsoft.exchange.webservices.data.core.XmlElementNames;
031import microsoft.exchange.webservices.data.core.service.schema.ContactGroupSchema;
032import microsoft.exchange.webservices.data.core.service.schema.ContactSchema;
033import microsoft.exchange.webservices.data.core.service.schema.ServiceObjectSchema;
034import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
035import microsoft.exchange.webservices.data.core.exception.service.local.ServiceObjectPropertyException;
036import microsoft.exchange.webservices.data.property.complex.GroupMemberCollection;
037import microsoft.exchange.webservices.data.property.complex.ItemAttachment;
038import microsoft.exchange.webservices.data.property.complex.ItemId;
039
040/**
041 * Represents a Contact Group. Properties available on contact groups are
042 * defined in the ContactGroupSchema class.
043 */
044@ServiceObjectDefinition(xmlElementName = XmlElementNames.DistributionList, returnedByServer = true)
045public class ContactGroup extends Item {
046
047  /**
048   * Initializes an unsaved local instance of the class.
049   *
050   * @param service the service
051   * @throws Exception the exception
052   */
053  public ContactGroup(ExchangeService service) throws Exception {
054    super(service);
055  }
056
057  /**
058   * Initializes an new instance of the class.
059   *
060   * @param parentAttachment the parent attachment
061   * @throws Exception the exception
062   */
063  public ContactGroup(ItemAttachment parentAttachment) throws Exception {
064    super(parentAttachment);
065  }
066
067  /**
068   * Gets the name under which this contact group is filed as.
069   *
070   * @return the file as
071   * @throws Exception the exception
072   */
073  @RequiredServerVersion(version = ExchangeVersion.Exchange2010)
074  public String getFileAs() throws Exception {
075    return (String) this
076        .getObjectFromPropertyDefinition(ContactSchema.FileAs);
077  }
078
079  /**
080   * Gets  the display name of the contact group.
081   *
082   * @return the display name
083   * @throws Exception the exception
084   */
085  public String getDisplayName() throws Exception {
086    return (String) this
087        .getObjectFromPropertyDefinition(ContactSchema.DisplayName);
088  }
089
090  /**
091   * Sets the display name.
092   *
093   * @param value the new display name
094   * @throws Exception the exception
095   */
096  public void setDisplayName(String value) throws Exception {
097    this.getPropertyBag().setObjectFromPropertyDefinition(
098        ContactSchema.DisplayName, value);
099  }
100
101  /**
102   * Gets the members of the contact group.
103   *
104   * @return the members
105   * @throws Exception the exception
106   */
107  @RequiredServerVersion(version = ExchangeVersion.Exchange2010)
108  public GroupMemberCollection getMembers() throws Exception {
109    return (GroupMemberCollection) this
110        .getObjectFromPropertyDefinition(ContactGroupSchema.Members);
111
112  }
113
114  /**
115   * Binds to an existing contact group and loads the specified set of
116   * property.Calling this method results in a call to EWS.
117   *
118   * @param service     the service
119   * @param id          the id
120   * @param propertySet the property set
121   * @return A ContactGroup instance representing the contact group
122   * corresponding to the specified Id
123   * @throws Exception the exception
124   */
125  public static ContactGroup bind(ExchangeService service, ItemId id,
126      PropertySet propertySet) throws Exception {
127    return service.bindToItem(ContactGroup.class, id, propertySet);
128  }
129
130  /**
131   * Binds to an existing contact group and loads the specified set of
132   * property.Calling this method results in a call to EWS.
133   *
134   * @param service the service
135   * @param id      the id
136   * @return A ContactGroup instance representing the contact group
137   * corresponding to the specified Id.
138   * @throws Exception the exception
139   */
140  public static ContactGroup bind(ExchangeService service, ItemId id)
141      throws Exception {
142    return ContactGroup.bind(service, id, PropertySet
143        .getFirstClassProperties());
144  }
145
146  /**
147   * Internal method to return the schema associated with this type of object.
148   *
149   * @return The schema associated with this type of object.
150   */
151  @Override public ServiceObjectSchema getSchema() {
152    return ContactGroupSchema.Instance;
153  }
154
155  /**
156   * Gets the minimum required server version.
157   *
158   * @return Earliest Exchange version in which this service object type is
159   * supported.
160   */
161  @Override public ExchangeVersion getMinimumRequiredServerVersion() {
162    return ExchangeVersion.Exchange2007_SP1;
163  }
164
165  /**
166   * Sets the subject.
167   *
168   * @param subject the new subject
169   * @throws ServiceObjectPropertyException the service object property exception
170   */
171  @Override
172  public void setSubject(String subject)
173      throws ServiceObjectPropertyException {
174    // Set is disabled in client API even though it is implemented in
175    // protocol for Item.Subject.
176    // Setting Subject out of sync with DisplayName breaks interop with OLK.
177    // See E14:70417, 65663, 6529.
178    throw new ServiceObjectPropertyException("This property is read-only and can't be set.",
179        ContactGroupSchema.Subject);
180  }
181}