2014-02-17 23:58:40 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Copyright 2003-2007 Jive Software.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.jivesoftware.smackx.workgroup.agent;
|
|
|
|
|
|
|
|
import org.jivesoftware.smackx.search.ReportedData;
|
|
|
|
import org.jivesoftware.smackx.workgroup.packet.TranscriptSearch;
|
|
|
|
import org.jivesoftware.smackx.xdata.Form;
|
2014-03-12 11:50:05 +01:00
|
|
|
import org.jivesoftware.smack.SmackException.NoResponseException;
|
2014-03-19 14:22:20 +01:00
|
|
|
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
2014-03-10 09:45:50 +01:00
|
|
|
import org.jivesoftware.smack.XMPPConnection;
|
2014-03-12 11:50:05 +01:00
|
|
|
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
2014-02-17 23:58:40 +01:00
|
|
|
import org.jivesoftware.smack.packet.IQ;
|
2015-02-14 17:15:02 +01:00
|
|
|
import org.jxmpp.jid.DomainBareJid;
|
2014-02-17 23:58:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A TranscriptSearchManager helps to retrieve the form to use for searching transcripts
|
2015-02-14 17:15:02 +01:00
|
|
|
* {@link #getSearchForm(DomainBareJid)} or to submit a search form and return the results of
|
|
|
|
* the search {@link #submitSearch(DomainBareJid, Form)}.
|
2014-02-17 23:58:40 +01:00
|
|
|
*
|
|
|
|
* @author Gaston Dombiak
|
|
|
|
*/
|
|
|
|
public class TranscriptSearchManager {
|
2014-03-10 09:45:50 +01:00
|
|
|
private XMPPConnection connection;
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2014-03-10 09:45:50 +01:00
|
|
|
public TranscriptSearchManager(XMPPConnection connection) {
|
2014-02-17 23:58:40 +01:00
|
|
|
this.connection = connection;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the Form to use for searching transcripts. It is unlikely that the server
|
|
|
|
* will change the form (without a restart) so it is safe to keep the returned form
|
|
|
|
* for future submissions.
|
|
|
|
*
|
|
|
|
* @param serviceJID the address of the workgroup service.
|
|
|
|
* @return the Form to use for searching transcripts.
|
2014-03-12 11:50:05 +01:00
|
|
|
* @throws XMPPErrorException
|
|
|
|
* @throws NoResponseException
|
2014-03-19 14:22:20 +01:00
|
|
|
* @throws NotConnectedException
|
2015-02-14 09:43:44 +01:00
|
|
|
* @throws InterruptedException
|
2014-02-17 23:58:40 +01:00
|
|
|
*/
|
2015-02-14 17:15:02 +01:00
|
|
|
public Form getSearchForm(DomainBareJid serviceJID) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
2014-02-17 23:58:40 +01:00
|
|
|
TranscriptSearch search = new TranscriptSearch();
|
2014-06-06 02:20:45 +02:00
|
|
|
search.setType(IQ.Type.get);
|
2014-02-17 23:58:40 +01:00
|
|
|
search.setTo(serviceJID);
|
|
|
|
|
2014-02-18 15:05:19 +01:00
|
|
|
TranscriptSearch response = (TranscriptSearch) connection.createPacketCollectorAndSend(
|
|
|
|
search).nextResultOrThrow();
|
2014-02-17 23:58:40 +01:00
|
|
|
return Form.getFormFrom(response);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Submits the completed form and returns the result of the transcript search. The result
|
|
|
|
* will include all the data returned from the server so be careful with the amount of
|
|
|
|
* data that the search may return.
|
|
|
|
*
|
|
|
|
* @param serviceJID the address of the workgroup service.
|
|
|
|
* @param completedForm the filled out search form.
|
|
|
|
* @return the result of the transcript search.
|
2014-03-12 11:50:05 +01:00
|
|
|
* @throws XMPPErrorException
|
|
|
|
* @throws NoResponseException
|
2014-03-19 14:22:20 +01:00
|
|
|
* @throws NotConnectedException
|
2015-02-14 09:43:44 +01:00
|
|
|
* @throws InterruptedException
|
2014-02-17 23:58:40 +01:00
|
|
|
*/
|
2015-02-14 17:15:02 +01:00
|
|
|
public ReportedData submitSearch(DomainBareJid serviceJID, Form completedForm) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
2014-02-17 23:58:40 +01:00
|
|
|
TranscriptSearch search = new TranscriptSearch();
|
2014-06-06 02:20:45 +02:00
|
|
|
search.setType(IQ.Type.get);
|
2014-02-17 23:58:40 +01:00
|
|
|
search.setTo(serviceJID);
|
|
|
|
search.addExtension(completedForm.getDataFormToSend());
|
|
|
|
|
2014-02-18 15:05:19 +01:00
|
|
|
TranscriptSearch response = (TranscriptSearch) connection.createPacketCollectorAndSend(
|
|
|
|
search).nextResultOrThrow();
|
2014-02-17 23:58:40 +01:00
|
|
|
return ReportedData.getReportedDataFrom(response);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|