Search in sources :

Example 1 with MamQueryIQ

use of org.jivesoftware.smackx.mam.element.MamQueryIQ in project Smack by igniterealtime.

the class MamManager method queryArchive.

/**
     * Query an message archive like a MUC archive or a pubsub node archive, addressed by an archiveAddress, applying
     * filters: max count, start date, end date, from/to JID and with additional fields. When archiveAddress is null the
     * default, the server will be requested.
     * 
     * @param node The Pubsub node name, can be null
     * @param max
     * @param start
     * @param end
     * @param withJid
     * @param additionalFields
     * @return the MAM query result
     * @throws NoResponseException
     * @throws XMPPErrorException
     * @throws NotConnectedException
     * @throws InterruptedException
     * @throws NotLoggedInException
     */
public MamQueryResult queryArchive(String node, Integer max, Date start, Date end, Jid withJid, List<FormField> additionalFields) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotLoggedInException {
    DataForm dataForm = null;
    String queryId = UUID.randomUUID().toString();
    if (start != null || end != null || withJid != null || additionalFields != null) {
        dataForm = getNewMamForm();
        addStart(start, dataForm);
        addEnd(end, dataForm);
        addWithJid(withJid, dataForm);
        addAdditionalFields(additionalFields, dataForm);
    }
    MamQueryIQ mamQueryIQ = new MamQueryIQ(queryId, node, dataForm);
    mamQueryIQ.setType(IQ.Type.set);
    mamQueryIQ.setTo(archiveAddress);
    addResultsLimit(max, mamQueryIQ);
    return queryArchive(mamQueryIQ);
}
Also used : DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) MamQueryIQ(org.jivesoftware.smackx.mam.element.MamQueryIQ)

Example 2 with MamQueryIQ

use of org.jivesoftware.smackx.mam.element.MamQueryIQ in project Smack by igniterealtime.

the class MamQueryIQProvider method parse.

@Override
public MamQueryIQ parse(XmlPullParser parser, int initialDepth) throws Exception {
    DataForm dataForm = null;
    String queryId = parser.getAttributeValue("", "queryid");
    String node = parser.getAttributeValue("", "node");
    outerloop: while (true) {
        final int eventType = parser.next();
        final String name = parser.getName();
        switch(eventType) {
            case XmlPullParser.START_TAG:
                switch(name) {
                    case DataForm.ELEMENT:
                        dataForm = DataFormProvider.INSTANCE.parse(parser);
                        break;
                }
                break;
            case XmlPullParser.END_TAG:
                if (parser.getDepth() == initialDepth) {
                    break outerloop;
                }
                break;
        }
    }
    return new MamQueryIQ(queryId, node, dataForm);
}
Also used : DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) MamQueryIQ(org.jivesoftware.smackx.mam.element.MamQueryIQ)

Example 3 with MamQueryIQ

use of org.jivesoftware.smackx.mam.element.MamQueryIQ in project Smack by igniterealtime.

the class MamManager method retrieveFormFields.

/**
 * Get the form fields supported by the server.
 *
 * @param node The PubSub node name, can be null
 * @return the list of form fields.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 * @throws NotLoggedInException if the XMPP connection is not authenticated.
 */
public List<FormField> retrieveFormFields(String node) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException, NotLoggedInException {
    String queryId = StringUtils.secureUniqueRandomString();
    MamQueryIQ mamQueryIq = getElementFactory().newQueryIQ(queryId, node, null);
    mamQueryIq.setTo(archiveAddress);
    MamQueryIQ mamResponseQueryIq = connection().sendIqRequestAndWaitForResponse(mamQueryIq);
    return mamResponseQueryIq.getDataForm().getFields();
}
Also used : MamQueryIQ(org.jivesoftware.smackx.mam.element.MamQueryIQ)

Example 4 with MamQueryIQ

use of org.jivesoftware.smackx.mam.element.MamQueryIQ in project Smack by igniterealtime.

the class MamManager method queryArchive.

public MamQuery queryArchive(MamQueryArgs mamQueryArgs) throws NoResponseException, XMPPErrorException, NotConnectedException, NotLoggedInException, InterruptedException {
    String queryId = StringUtils.secureUniqueRandomString();
    String node = mamQueryArgs.node;
    DataForm dataForm = mamQueryArgs.getDataForm(mamVersion);
    MamQueryIQ mamQueryIQ = getElementFactory().newQueryIQ(queryId, node, dataForm);
    mamQueryIQ.setType(IQ.Type.set);
    mamQueryIQ.setTo(archiveAddress);
    mamQueryArgs.maybeAddRsmSet(mamQueryIQ);
    return queryArchive(mamQueryIQ);
}
Also used : DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) MamQueryIQ(org.jivesoftware.smackx.mam.element.MamQueryIQ)

Example 5 with MamQueryIQ

use of org.jivesoftware.smackx.mam.element.MamQueryIQ in project Smack by igniterealtime.

the class ResultsLimitTest method checkResultsLimit.

@Test
public void checkResultsLimit() throws Exception {
    DataForm dataForm = getNewMamForm();
    MamQueryIQ mamQueryIQ = new MamQueryIQ(MamVersion.MAM2, queryId, dataForm);
    mamQueryIQ.setType(IQ.Type.set);
    mamQueryIQ.setStanzaId("sarasa");
    MamQueryArgs mamQueryArgs = MamQueryArgs.builder().setResultPageSize(10).build();
    mamQueryArgs.maybeAddRsmSet(mamQueryIQ);
    assertEquals(resultsLimitStanza, mamQueryIQ.toXML(StreamOpen.CLIENT_NAMESPACE).toString());
}
Also used : DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) MamQueryIQ(org.jivesoftware.smackx.mam.element.MamQueryIQ) MamQueryArgs(org.jivesoftware.smackx.mam.MamManager.MamQueryArgs) Test(org.junit.jupiter.api.Test)

Aggregations

MamQueryIQ (org.jivesoftware.smackx.mam.element.MamQueryIQ)10 DataForm (org.jivesoftware.smackx.xdata.packet.DataForm)7 Test (org.junit.jupiter.api.Test)5 IQ (org.jivesoftware.smack.packet.IQ)1 MamQueryArgs (org.jivesoftware.smackx.mam.MamManager.MamQueryArgs)1 RSMSet (org.jivesoftware.smackx.rsm.packet.RSMSet)1 FormField (org.jivesoftware.smackx.xdata.FormField)1