Search in sources :

Example 11 with AndFilter

use of org.jivesoftware.smack.filter.AndFilter in project Smack by igniterealtime.

the class Workgroup method isAvailable.

/**
     * Returns true if the workgroup is available for receiving new requests. The workgroup will be
     * available only when agents are available for this workgroup.
     *
     * @return true if the workgroup is available for receiving new requests.
     * @throws XMPPErrorException 
     * @throws NoResponseException 
     * @throws NotConnectedException 
     * @throws InterruptedException 
     */
public boolean isAvailable() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    Presence directedPresence = new Presence(Presence.Type.available);
    directedPresence.setTo(workgroupJID);
    StanzaFilter typeFilter = new StanzaTypeFilter(Presence.class);
    StanzaFilter fromFilter = FromMatchesFilter.create(workgroupJID);
    StanzaCollector collector = connection.createStanzaCollectorAndSend(new AndFilter(fromFilter, typeFilter), directedPresence);
    Presence response = (Presence) collector.nextResultOrThrow();
    return Presence.Type.available == response.getType();
}
Also used : StanzaTypeFilter(org.jivesoftware.smack.filter.StanzaTypeFilter) AndFilter(org.jivesoftware.smack.filter.AndFilter) StanzaFilter(org.jivesoftware.smack.filter.StanzaFilter) Presence(org.jivesoftware.smack.packet.Presence) StanzaCollector(org.jivesoftware.smack.StanzaCollector)

Example 12 with AndFilter

use of org.jivesoftware.smack.filter.AndFilter in project Smack by igniterealtime.

the class AgentSession method setStatus.

/**
     * Sets the agent's current status with the workgroup. The presence mode affects how offers
     * are routed to the agent. The possible presence modes with their meanings are as follows:<ul>
     * <p/>
     * <li>Presence.Mode.AVAILABLE -- (Default) the agent is available for more chats
     * (equivalent to Presence.Mode.CHAT).
     * <li>Presence.Mode.DO_NOT_DISTURB -- the agent is busy and should not be disturbed.
     * However, special case, or extreme urgency chats may still be offered to the agent.
     * <li>Presence.Mode.AWAY -- the agent is not available and should not
     * have a chat routed to them (equivalent to Presence.Mode.EXTENDED_AWAY).</ul>
     *
     * @param presenceMode the presence mode of the agent.
     * @param status       sets the status message of the presence update.
     * @throws XMPPErrorException 
     * @throws NoResponseException 
     * @throws NotConnectedException 
     * @throws InterruptedException 
     * @throws IllegalStateException if the agent is not online with the workgroup.
     */
public void setStatus(Presence.Mode presenceMode, String status) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    if (!online) {
        throw new IllegalStateException("Cannot set status when the agent is not online.");
    }
    if (presenceMode == null) {
        presenceMode = Presence.Mode.available;
    }
    this.presenceMode = presenceMode;
    Presence presence = new Presence(Presence.Type.available);
    presence.setMode(presenceMode);
    presence.setTo(this.getWorkgroupJID());
    if (status != null) {
        presence.setStatus(status);
    }
    presence.addExtension(new MetaData(this.metaData));
    StanzaCollector collector = this.connection.createStanzaCollectorAndSend(new AndFilter(new StanzaTypeFilter(Presence.class), FromMatchesFilter.create(workgroupJID)), presence);
    collector.nextResultOrThrow();
}
Also used : AndFilter(org.jivesoftware.smack.filter.AndFilter) StanzaTypeFilter(org.jivesoftware.smack.filter.StanzaTypeFilter) MetaData(org.jivesoftware.smackx.workgroup.MetaData) Presence(org.jivesoftware.smack.packet.Presence) StanzaCollector(org.jivesoftware.smack.StanzaCollector)

Example 13 with AndFilter

use of org.jivesoftware.smack.filter.AndFilter in project Smack by igniterealtime.

the class EntityCapsTest method testLocalEntityCaps.

@SmackIntegrationTest
public void testLocalEntityCaps() throws InterruptedException, NoResponseException, XMPPErrorException, NotConnectedException {
    final String dummyFeature = getNewDummyFeature();
    DiscoverInfo info = EntityCapsManager.getDiscoveryInfoByNodeVer(ecmTwo.getLocalNodeVer());
    assertFalse(info.containsFeature(dummyFeature));
    dropWholeEntityCapsCache();
    performActionAndWaitUntilStanzaReceived(new Runnable() {

        @Override
        public void run() {
            // This should cause a new presence stanza from con1 with and updated
            // 'ver' String
            sdmTwo.addFeature(dummyFeature);
        }
    }, conOne, new AndFilter(PresenceTypeFilter.AVAILABLE, FromMatchesFilter.create(conTwo.getUser())));
    // The presence stanza should get received by con0 and the data should
    // be recorded in the map
    // Note that while both connections use the same static Entity Caps
    // cache,
    // it's assured that *not* con1 added the data to the Entity Caps cache.
    // Every time the entities features
    // and identities change only a new caps 'ver' is calculated and send
    // with the presence stanza
    // The other connection has to receive this stanza and record the
    // information in order for this test to succeed.
    info = EntityCapsManager.getDiscoveryInfoByNodeVer(ecmTwo.getLocalNodeVer());
    assertNotNull(info);
    assertTrue(info.containsFeature(dummyFeature));
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) AndFilter(org.jivesoftware.smack.filter.AndFilter) SmackIntegrationTest(org.igniterealtime.smack.inttest.SmackIntegrationTest) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)

Example 14 with AndFilter

use of org.jivesoftware.smack.filter.AndFilter in project Smack by igniterealtime.

the class EntityCapsTest method testEntityCaps.

@SmackIntegrationTest
public void testEntityCaps() throws XMPPException, InterruptedException, NoResponseException, NotConnectedException, TimeoutException {
    final String dummyFeature = getNewDummyFeature();
    dropWholeEntityCapsCache();
    performActionAndWaitUntilStanzaReceived(new Runnable() {

        @Override
        public void run() {
            sdmTwo.addFeature(dummyFeature);
        }
    }, connection, new AndFilter(PresenceTypeFilter.AVAILABLE, FromMatchesFilter.create(conTwo.getUser())));
    waitUntilTrue(new Condition() {

        @Override
        public boolean evaluate() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
            DiscoverInfo info = sdmOne.discoverInfo(conTwo.getUser());
            return info.containsFeature(dummyFeature);
        }
    });
    DiscoverInfo info = sdmOne.discoverInfo(conTwo.getUser());
    String u1ver = EntityCapsManager.getNodeVersionByJid(conTwo.getUser());
    assertNotNull(u1ver);
    DiscoverInfo entityInfo = EntityCapsManager.CAPS_CACHE.lookup(u1ver);
    assertNotNull(entityInfo);
    assertEquals(info.toXML(), entityInfo.toXML());
}
Also used : AndFilter(org.jivesoftware.smack.filter.AndFilter) DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) SmackIntegrationTest(org.igniterealtime.smack.inttest.SmackIntegrationTest) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)

Example 15 with AndFilter

use of org.jivesoftware.smack.filter.AndFilter in project Smack by igniterealtime.

the class IQTest method testInvalidNamespace.

/**
     * Check that the server responds a 503 error code when the client sends an IQ stanza(/packet) with an
     * invalid namespace.
     */
public void testInvalidNamespace() {
    IQ iq = new IQ() {

        public String getChildElementXML() {
            StringBuilder buf = new StringBuilder();
            buf.append("<query xmlns=\"jabber:iq:anything\">");
            buf.append("</query>");
            return buf.toString();
        }
    };
    PacketFilter filter = new AndFilter(new PacketIDFilter(iq.getStanzaId()), new StanzaTypeFilter(IQ.class));
    StanzaCollector collector = getConnection(0).createStanzaCollector(filter);
    // Send the iq packet with an invalid namespace
    getConnection(0).sendStanza(iq);
    IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
    // Stop queuing results
    collector.cancel();
    if (result == null) {
        fail("No response from server");
    } else if (result.getType() != IQ.Type.error) {
        fail("The server didn't reply with an error packet");
    } else {
        assertEquals("Server answered an incorrect error code", 503, result.getError().getCode());
    }
}
Also used : AndFilter(org.jivesoftware.smack.filter.AndFilter) StanzaTypeFilter(org.jivesoftware.smack.filter.StanzaTypeFilter) PacketFilter(org.jivesoftware.smack.filter.PacketFilter) IQ(org.jivesoftware.smack.packet.IQ) PacketIDFilter(org.jivesoftware.smack.filter.PacketIDFilter)

Aggregations

AndFilter (org.jivesoftware.smack.filter.AndFilter)16 StanzaCollector (org.jivesoftware.smack.StanzaCollector)7 StanzaTypeFilter (org.jivesoftware.smack.filter.StanzaTypeFilter)7 Presence (org.jivesoftware.smack.packet.Presence)7 StanzaFilter (org.jivesoftware.smack.filter.StanzaFilter)5 SmackIntegrationTest (org.igniterealtime.smack.inttest.SmackIntegrationTest)4 AbstractSmackIntegrationTest (org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)3 Message (org.jivesoftware.smack.packet.Message)3 Stanza (org.jivesoftware.smack.packet.Stanza)3 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)3 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)2 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)2 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)2 OrFilter (org.jivesoftware.smack.filter.OrFilter)2 PacketTypeFilter (org.jivesoftware.smack.filter.PacketTypeFilter)2 StandardExtensionElement (org.jivesoftware.smack.packet.StandardExtensionElement)2 MUCInitialPresence (org.jivesoftware.smackx.muc.packet.MUCInitialPresence)2 MetaData (org.jivesoftware.smackx.workgroup.MetaData)2 EntityFullJid (org.jxmpp.jid.EntityFullJid)2 ArrayList (java.util.ArrayList)1