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.messaging;
025
026import microsoft.exchange.webservices.data.core.EwsUtilities;
027import microsoft.exchange.webservices.data.core.ExchangeService;
028import microsoft.exchange.webservices.data.core.request.DisconnectPhoneCallRequest;
029import microsoft.exchange.webservices.data.core.request.GetPhoneCallRequest;
030import microsoft.exchange.webservices.data.core.request.PlayOnPhoneRequest;
031import microsoft.exchange.webservices.data.core.response.GetPhoneCallResponse;
032import microsoft.exchange.webservices.data.core.response.PlayOnPhoneResponse;
033import microsoft.exchange.webservices.data.property.complex.ItemId;
034
035/**
036 * Represents the Unified Messaging functionalities.
037 */
038public final class UnifiedMessaging {
039
040  /**
041   * The service.
042   */
043  private ExchangeService service;
044
045  /**
046   * Constructor.
047   *
048   * @param service the service
049   */
050  public UnifiedMessaging(ExchangeService service) {
051    this.service = service;
052  }
053
054  /**
055   * Calls a phone and reads a message to the person who picks up.
056   *
057   * @param itemId     the item id
058   * @param dialString the dial string
059   * @return An object providing status for the phone call.
060   * @throws Exception the exception
061   */
062  public PhoneCall playOnPhone(ItemId itemId, String dialString)
063      throws Exception {
064    EwsUtilities.validateParam(itemId, "itemId");
065    EwsUtilities.validateParam(dialString, "dialString");
066
067    PlayOnPhoneRequest request = new PlayOnPhoneRequest(service);
068    request.setDialString(dialString);
069    request.setItemId(itemId);
070    PlayOnPhoneResponse serviceResponse = request.execute();
071
072    PhoneCall callInformation = new PhoneCall(service, serviceResponse
073        .getPhoneCallId());
074
075    return callInformation;
076  }
077
078  /**
079   * Retrieves information about a current phone call.
080   *
081   * @param id the id
082   * @return An object providing status for the phone call.
083   * @throws Exception the exception
084   */
085  protected PhoneCall getPhoneCallInformation(PhoneCallId id)
086      throws Exception {
087    GetPhoneCallRequest request = new GetPhoneCallRequest(service);
088    request.setId(id);
089    GetPhoneCallResponse response = request.execute();
090
091    return response.getPhoneCall();
092  }
093
094  /**
095   * Disconnects a phone call.
096   *
097   * @param id the id
098   * @throws Exception the exception
099   */
100  protected void disconnectPhoneCall(PhoneCallId id) throws Exception {
101    DisconnectPhoneCallRequest request = new DisconnectPhoneCallRequest(
102        service);
103    request.setId(id);
104    request.execute();
105  }
106}