Search in sources :

Example 1 with NodeSubscription

use of org.jivesoftware.openfire.pubsub.NodeSubscription in project Openfire by igniterealtime.

the class PEPService method sendLastPublishedItems.

/**
     * Sends an event notification for the last published item of each leaf node under the
     * root collection node to the recipient JID. If the recipient has no subscription to
     * the root collection node, has not yet been authorized, or is pending to be
     * configured -- then no notifications are going to be sent.<p>
     *
     * Depending on the subscription configuration the event notifications may or may not have
     * a payload, may not be sent if a keyword (i.e. filter) was defined and it was not matched.
     *
     * @param recipientJID the recipient that is to receive the last published item notifications.
     */
public void sendLastPublishedItems(JID recipientJID) {
    // Ensure the recipient has a subscription to this service's root collection node.
    NodeSubscription subscription = rootCollectionNode.getSubscription(recipientJID);
    if (subscription == null) {
        subscription = rootCollectionNode.getSubscription(new JID(recipientJID.toBareJID()));
    }
    if (subscription == null) {
        return;
    }
    // Send the last published item of each leaf node to the recipient.
    for (Node leafNode : rootCollectionNode.getNodes()) {
        // Retrieve last published item for the leaf node.
        PublishedItem leafLastPublishedItem = null;
        leafLastPublishedItem = leafNode.getLastPublishedItem();
        if (leafLastPublishedItem == null) {
            continue;
        }
        // Check if the published item can be sent to the subscriber
        if (!subscription.canSendPublicationEvent(leafLastPublishedItem.getNode(), leafLastPublishedItem)) {
            return;
        }
        // Send event notification to the subscriber
        Message notification = new Message();
        Element event = notification.getElement().addElement("event", "http://jabber.org/protocol/pubsub#event");
        Element items = event.addElement("items");
        items.addAttribute("node", leafLastPublishedItem.getNodeID());
        Element item = items.addElement("item");
        if (leafLastPublishedItem.getNode().isItemRequired()) {
            item.addAttribute("id", leafLastPublishedItem.getID());
        }
        if (leafLastPublishedItem.getNode().isPayloadDelivered() && leafLastPublishedItem.getPayload() != null) {
            item.add(leafLastPublishedItem.getPayload().createCopy());
        }
        // Add a message body (if required)
        if (subscription.isIncludingBody()) {
            notification.setBody(LocaleUtils.getLocalizedString("pubsub.notification.message.body"));
        }
        // Include date when published item was created
        notification.getElement().addElement("delay", "urn:xmpp:delay").addAttribute("stamp", XMPPDateTimeFormat.format(leafLastPublishedItem.getCreationDate()));
        // Send the event notification to the subscriber
        this.sendNotification(subscription.getNode(), notification, subscription.getJID());
    }
}
Also used : JID(org.xmpp.packet.JID) Message(org.xmpp.packet.Message) NodeSubscription(org.jivesoftware.openfire.pubsub.NodeSubscription) CollectionNode(org.jivesoftware.openfire.pubsub.CollectionNode) Node(org.jivesoftware.openfire.pubsub.Node) Element(org.dom4j.Element) PublishedItem(org.jivesoftware.openfire.pubsub.PublishedItem)

Example 2 with NodeSubscription

use of org.jivesoftware.openfire.pubsub.NodeSubscription in project Openfire by igniterealtime.

the class IQPEPHandler method cancelSubscriptionToPEPService.

/**
     * Cancels a subscription to a PEPService's root collection node.
     *
     * @param unsubscriber the JID of the subscriber whose subscription is being canceled.
     * @param serviceOwner the JID of the owner of the PEP service for which the subscription is being canceled.
     */
private void cancelSubscriptionToPEPService(JID unsubscriber, JID serviceOwner) {
    // Retrieve recipientJID's PEP service, if it exists.
    PEPService pepService = pepServiceManager.getPEPService(serviceOwner.toBareJID());
    if (pepService == null) {
        return;
    }
    // Cancel unsubscriberJID's subscription to recipientJID's PEP service, if it exists.
    CollectionNode rootNode = pepService.getRootCollectionNode();
    NodeSubscription nodeSubscription = rootNode.getSubscription(unsubscriber);
    if (nodeSubscription != null) {
        rootNode.cancelSubscription(nodeSubscription);
    }
}
Also used : NodeSubscription(org.jivesoftware.openfire.pubsub.NodeSubscription) CollectionNode(org.jivesoftware.openfire.pubsub.CollectionNode)

Example 3 with NodeSubscription

use of org.jivesoftware.openfire.pubsub.NodeSubscription in project Openfire by igniterealtime.

the class IQPEPHandler method subscribedToPresence.

@Override
public void subscribedToPresence(JID subscriberJID, JID authorizerJID) {
    final PEPService pepService = pepServiceManager.getPEPService(authorizerJID.toBareJID());
    if (pepService != null) {
        createSubscriptionToPEPService(pepService, subscriberJID, authorizerJID);
        // Delete any leaf node subscriptions the subscriber may have already
        // had (since a subscription to the PEP service, and thus its leaf PEP
        // nodes, would be duplicating publish notifications from previous leaf
        // node subscriptions).
        CollectionNode rootNode = pepService.getRootCollectionNode();
        for (Node node : pepService.getNodes()) {
            if (rootNode.isChildNode(node)) {
                for (NodeSubscription subscription : node.getSubscriptions(subscriberJID)) {
                    node.cancelSubscription(subscription);
                }
            }
        }
        pepService.sendLastPublishedItems(subscriberJID);
    }
}
Also used : NodeSubscription(org.jivesoftware.openfire.pubsub.NodeSubscription) CollectionNode(org.jivesoftware.openfire.pubsub.CollectionNode) Node(org.jivesoftware.openfire.pubsub.Node) LeafNode(org.jivesoftware.openfire.pubsub.LeafNode) CollectionNode(org.jivesoftware.openfire.pubsub.CollectionNode)

Aggregations

CollectionNode (org.jivesoftware.openfire.pubsub.CollectionNode)3 NodeSubscription (org.jivesoftware.openfire.pubsub.NodeSubscription)3 Node (org.jivesoftware.openfire.pubsub.Node)2 Element (org.dom4j.Element)1 LeafNode (org.jivesoftware.openfire.pubsub.LeafNode)1 PublishedItem (org.jivesoftware.openfire.pubsub.PublishedItem)1 JID (org.xmpp.packet.JID)1 Message (org.xmpp.packet.Message)1