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.smack.SmackException.NoResponseException;
021import org.jivesoftware.smack.SmackException.NotConnectedException;
022import org.jivesoftware.smack.XMPPConnection;
023import org.jivesoftware.smack.XMPPException.XMPPErrorException;
024
025import org.jivesoftware.smackx.workgroup.packet.Transcript;
026import org.jivesoftware.smackx.workgroup.packet.Transcripts;
027
028import org.jxmpp.jid.EntityBareJid;
029import org.jxmpp.jid.Jid;
030
031/**
032 * A TranscriptManager helps to retrieve the full conversation transcript of a given session
033 * {@link #getTranscript(EntityBareJid, String)} or to retrieve a list with the summary of all the
034 * conversations that a user had {@link #getTranscripts(EntityBareJid, Jid)}.
035 *
036 * @author Gaston Dombiak
037 */
038public class TranscriptManager {
039    private XMPPConnection connection;
040
041    public TranscriptManager(XMPPConnection connection) {
042        this.connection = connection;
043    }
044
045    /**
046     * Returns the full conversation transcript of a given session.
047     *
048     * @param sessionID the id of the session to get the full transcript.
049     * @param workgroupJID the JID of the workgroup that will process the request.
050     * @return the full conversation transcript of a given session.
051     * @throws XMPPErrorException if there was an XMPP error returned.
052     * @throws NoResponseException if there was no response from the remote entity.
053     * @throws NotConnectedException if the XMPP connection is not connected.
054     * @throws InterruptedException if the calling thread was interrupted.
055     */
056    public Transcript getTranscript(EntityBareJid workgroupJID, String sessionID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
057        Transcript request = new Transcript(sessionID);
058        request.setTo(workgroupJID);
059        Transcript response = connection.sendIqRequestAndWaitForResponse(request);
060        return response;
061    }
062
063    /**
064     * Returns the transcripts of a given user. The answer will contain the complete history of
065     * conversations that a user had.
066     *
067     * @param userID the id of the user to get his conversations.
068     * @param workgroupJID the JID of the workgroup that will process the request.
069     * @return the transcripts of a given user.
070     * @throws XMPPErrorException if there was an XMPP error returned.
071     * @throws NoResponseException if there was no response from the remote entity.
072     * @throws NotConnectedException if the XMPP connection is not connected.
073     * @throws InterruptedException if the calling thread was interrupted.
074     */
075    public Transcripts getTranscripts(EntityBareJid workgroupJID, Jid userID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
076        Transcripts request = new Transcripts(userID);
077        request.setTo(workgroupJID);
078        Transcripts response = connection.sendIqRequestAndWaitForResponse(request);
079        return response;
080    }
081}