TranscriptManager.java

  1. /**
  2.  *
  3.  * Copyright 2003-2007 Jive Software.
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.jivesoftware.smackx.workgroup.agent;

  18. import org.jivesoftware.smackx.workgroup.packet.Transcript;
  19. import org.jivesoftware.smackx.workgroup.packet.Transcripts;
  20. import org.jivesoftware.smack.SmackException.NoResponseException;
  21. import org.jivesoftware.smack.SmackException.NotConnectedException;
  22. import org.jivesoftware.smack.XMPPConnection;
  23. import org.jivesoftware.smack.XMPPException.XMPPErrorException;
  24. import org.jxmpp.jid.Jid;

  25. /**
  26.  * A TranscriptManager helps to retrieve the full conversation transcript of a given session
  27.  * {@link #getTranscript(Jid, String)} or to retrieve a list with the summary of all the
  28.  * conversations that a user had {@link #getTranscripts(Jid, Jid)}.
  29.  *
  30.  * @author Gaston Dombiak
  31.  */
  32. public class TranscriptManager {
  33.     private XMPPConnection connection;

  34.     public TranscriptManager(XMPPConnection connection) {
  35.         this.connection = connection;
  36.     }

  37.     /**
  38.      * Returns the full conversation transcript of a given session.
  39.      *
  40.      * @param sessionID the id of the session to get the full transcript.
  41.      * @param workgroupJID the JID of the workgroup that will process the request.
  42.      * @return the full conversation transcript of a given session.
  43.      * @throws XMPPErrorException
  44.      * @throws NoResponseException
  45.      * @throws NotConnectedException
  46.      * @throws InterruptedException
  47.      */
  48.     public Transcript getTranscript(Jid workgroupJID, String sessionID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
  49.         Transcript request = new Transcript(sessionID);
  50.         request.setTo(workgroupJID);
  51.         Transcript response = (Transcript) connection.createPacketCollectorAndSend(request).nextResultOrThrow();
  52.         return response;
  53.     }

  54.     /**
  55.      * Returns the transcripts of a given user. The answer will contain the complete history of
  56.      * conversations that a user had.
  57.      *
  58.      * @param userID the id of the user to get his conversations.
  59.      * @param workgroupJID the JID of the workgroup that will process the request.
  60.      * @return the transcripts of a given user.
  61.      * @throws XMPPErrorException
  62.      * @throws NoResponseException
  63.      * @throws NotConnectedException
  64.      * @throws InterruptedException
  65.      */
  66.     public Transcripts getTranscripts(Jid workgroupJID, Jid userID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
  67.         Transcripts request = new Transcripts(userID);
  68.         request.setTo(workgroupJID);
  69.         Transcripts response = (Transcripts) connection.createPacketCollectorAndSend(request).nextResultOrThrow();
  70.         return response;
  71.     }
  72. }