001/** 002 * 003 * Copyright 2003-2007 Jive Software. 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package org.jivesoftware.smackx.workgroup.agent; 019 020import org.jivesoftware.smackx.workgroup.packet.Transcript; 021import org.jivesoftware.smackx.workgroup.packet.Transcripts; 022import org.jivesoftware.smack.SmackException.NoResponseException; 023import org.jivesoftware.smack.SmackException.NotConnectedException; 024import org.jivesoftware.smack.XMPPConnection; 025import org.jivesoftware.smack.XMPPException.XMPPErrorException; 026 027/** 028 * A TranscriptManager helps to retrieve the full conversation transcript of a given session 029 * {@link #getTranscript(String, String)} or to retrieve a list with the summary of all the 030 * conversations that a user had {@link #getTranscripts(String, String)}. 031 * 032 * @author Gaston Dombiak 033 */ 034public class TranscriptManager { 035 private XMPPConnection connection; 036 037 public TranscriptManager(XMPPConnection connection) { 038 this.connection = connection; 039 } 040 041 /** 042 * Returns the full conversation transcript of a given session. 043 * 044 * @param sessionID the id of the session to get the full transcript. 045 * @param workgroupJID the JID of the workgroup that will process the request. 046 * @return the full conversation transcript of a given session. 047 * @throws XMPPErrorException 048 * @throws NoResponseException 049 * @throws NotConnectedException 050 */ 051 public Transcript getTranscript(String workgroupJID, String sessionID) throws NoResponseException, XMPPErrorException, NotConnectedException { 052 Transcript request = new Transcript(sessionID); 053 request.setTo(workgroupJID); 054 Transcript response = (Transcript) connection.createPacketCollectorAndSend(request).nextResultOrThrow(); 055 return response; 056 } 057 058 /** 059 * Returns the transcripts of a given user. The answer will contain the complete history of 060 * conversations that a user had. 061 * 062 * @param userID the id of the user to get his conversations. 063 * @param workgroupJID the JID of the workgroup that will process the request. 064 * @return the transcripts of a given user. 065 * @throws XMPPErrorException 066 * @throws NoResponseException 067 * @throws NotConnectedException 068 */ 069 public Transcripts getTranscripts(String workgroupJID, String userID) throws NoResponseException, XMPPErrorException, NotConnectedException { 070 Transcripts request = new Transcripts(userID); 071 request.setTo(workgroupJID); 072 Transcripts response = (Transcripts) connection.createPacketCollectorAndSend(request).nextResultOrThrow(); 073 return response; 074 } 075}