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.service.folder;
025    
026    import microsoft.exchange.webservices.data.attribute.ServiceObjectDefinition;
027    import microsoft.exchange.webservices.data.core.EwsUtilities;
028    import microsoft.exchange.webservices.data.core.ExchangeService;
029    import microsoft.exchange.webservices.data.core.PropertySet;
030    import microsoft.exchange.webservices.data.core.XmlElementNames;
031    import microsoft.exchange.webservices.data.core.response.FindItemResponse;
032    import microsoft.exchange.webservices.data.core.response.ServiceResponseCollection;
033    import microsoft.exchange.webservices.data.core.service.item.Appointment;
034    import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
035    import microsoft.exchange.webservices.data.core.enumeration.property.WellKnownFolderName;
036    import microsoft.exchange.webservices.data.property.complex.FolderId;
037    import microsoft.exchange.webservices.data.search.CalendarView;
038    import microsoft.exchange.webservices.data.search.FindItemsResults;
039    import microsoft.exchange.webservices.data.search.filter.SearchFilter;
040    
041    /**
042     * Represents a folder containing appointments.
043     */
044    @ServiceObjectDefinition(xmlElementName = XmlElementNames.CalendarFolder)
045    public class CalendarFolder extends Folder {
046    
047      /**
048       * Binds to an existing calendar folder and loads the specified set of
049       * property. Calling this method results in a call to EWS.
050       *
051       * @param service     the service
052       * @param id          the id
053       * @param propertySet the property set
054       * @return A CalendarFolder instance representing the calendar folder
055       * corresponding to the specified Id
056       * @throws Exception the exception
057       */
058      public static CalendarFolder bind(ExchangeService service, FolderId id,
059          PropertySet propertySet) throws Exception {
060        return service.bindToFolder(CalendarFolder.class, id, propertySet);
061      }
062    
063      /**
064       * Binds to an existing calendar folder and loads the specified set of
065       * property. Calling this method results in a call to EWS.
066       *
067       * @param service the service
068       * @param id      the id
069       * @return A CalendarFolder instance representing the calendar folder
070       * corresponding to the specified Id
071       * @throws Exception the exception
072       */
073      public static CalendarFolder bind(ExchangeService service, FolderId id)
074          throws Exception {
075        return CalendarFolder.bind(service, id, PropertySet
076            .getFirstClassProperties());
077      }
078    
079      /**
080       * Binds to an existing calendar folder and loads the specified set of
081       * property. Calling this method results in a call to EWS.
082       *
083       * @param service     the service
084       * @param name        the name
085       * @param propertySet the property set
086       * @return A CalendarFolder instance representing the calendar folder with
087       * the specified name.
088       * @throws Exception the exception
089       */
090      public static CalendarFolder bind(ExchangeService service,
091          WellKnownFolderName name, PropertySet
092          propertySet) throws Exception {
093        return CalendarFolder.bind(service, new FolderId(name), propertySet);
094      }
095    
096      /**
097       * Binds to an existing calendar folder and loads the specified set of
098       * property. Calling this method results in a call to EWS.
099       *
100       * @param service the service
101       * @param name    the name
102       * @return A CalendarFolder instance representing the calendar folder with
103       * the specified name.
104       * @throws Exception the exception
105       */
106      public static CalendarFolder bind(ExchangeService service,
107          WellKnownFolderName name) throws Exception {
108        return CalendarFolder.bind(service, new FolderId(name), PropertySet
109            .getFirstClassProperties());
110      }
111    
112      /**
113       * Initializes an unsaved local instance of "CalendarFolder". To bind to an
114       * existing calendar folder, use CalendarFolder.Bind() instead. Calling this
115       * method results in a call to EWS.
116       *
117       * @param service the service
118       * @throws Exception the exception
119       */
120      public CalendarFolder(ExchangeService service) throws Exception {
121        super(service);
122      }
123    
124      /**
125       * Obtains a list of appointments by searching the contents of this folder
126       * and performing recurrence expansion for recurring appointments. Calling
127       * this method results in a call to EWS.
128       *
129       * @param view the view
130       * @return An object representing the results of the search operation.
131       * @throws Exception the exception
132       */
133      public FindItemsResults<Appointment> findAppointments(CalendarView view)
134          throws Exception {
135        EwsUtilities.validateParam(view, "view");
136    
137        ServiceResponseCollection<FindItemResponse<Appointment>> responses =
138            this.internalFindItems((SearchFilter) null, view, null
139                                            /* groupBy */);
140    
141        return responses.getResponseAtIndex(0).getResults();
142      }
143    
144      /**
145       * Obtains a list of appointments by searching the contents of this folder
146       * and performing recurrence expansion.
147       *
148       * @return Earliest Exchange version in which this service object type is
149       * supported.
150       */
151      @Override public ExchangeVersion getMinimumRequiredServerVersion() {
152        return ExchangeVersion.Exchange2007_SP1;
153      }
154    }