Search in sources :

Example 6 with PEPService

use of org.jivesoftware.openfire.pep.PEPService in project Openfire by igniterealtime.

the class PrivateStorage method get.

/**
 * Returns the data stored under a key corresponding to the name and namespace
 * of the given element. The Element must be in the form:<p>
 *
 * <code>&lt;name xmlns='namespace'/&gt;</code><p>
 *
 * If no data is currently stored under the given key, an empty element will be
 * returned.
 *
 * @param data an XML document who's element name and namespace is used to
 *      match previously stored private data.
 * @param username the username of the account where private data is being stored.
 * @return the data stored under the given key or the data element.
 */
public Element get(String username, Element data) {
    if (enabled) {
        final PEPServiceManager serviceMgr = XMPPServer.getInstance().getIQPEPHandler().getServiceManager();
        final PEPService pepService = serviceMgr.getPEPService(XMPPServer.getInstance().createJID(username, null));
        if (pepService != null) {
            final Node node = pepService.getNode(data.getNamespaceURI());
            if (node != null) {
                final PublishedItem item = node.getPublishedItem("current");
                if (item != null) {
                    data.clearContent();
                    data = item.getPayload();
                }
            }
        }
    }
    return data;
}
Also used : PEPServiceManager(org.jivesoftware.openfire.pep.PEPServiceManager) PEPService(org.jivesoftware.openfire.pep.PEPService) Node(org.jivesoftware.openfire.pubsub.Node) LeafNode(org.jivesoftware.openfire.pubsub.LeafNode) PublishedItem(org.jivesoftware.openfire.pubsub.PublishedItem)

Example 7 with PEPService

use of org.jivesoftware.openfire.pep.PEPService in project Openfire by igniterealtime.

the class DefaultPubSubPersistenceProvider method loadPEPServiceFromDB.

@Override
public PEPService loadPEPServiceFromDB(JID jid) {
    PEPService pepService = null;
    Connection con = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        con = DbConnectionManager.getConnection();
        // Get all PEP services
        pstmt = con.prepareStatement(GET_PEP_SERVICE);
        pstmt.setString(1, jid.toString());
        rs = pstmt.executeQuery();
        // Restore old PEPService
        while (rs.next()) {
            String serviceID = rs.getString(1);
            if (!jid.toString().equals(serviceID)) {
                log.warn("Loading a PEP service for {} that has a different name: {}", jid, serviceID);
            }
            // Create a new PEPService
            pepService = new PEPService(XMPPServer.getInstance(), jid);
        }
    } catch (SQLException sqle) {
        log.error(sqle.getMessage(), sqle);
    } finally {
        DbConnectionManager.closeConnection(rs, pstmt, con);
    }
    return pepService;
}
Also used : PEPService(org.jivesoftware.openfire.pep.PEPService) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 8 with PEPService

use of org.jivesoftware.openfire.pep.PEPService in project Openfire by igniterealtime.

the class NodeAffiliate method sendPublishedNotifications.

/**
 * Sends an event notification for the published items to the affiliate. The event
 * notification may contain zero, one or many published items based on the items
 * included in the original publication. If the affiliate has many subscriptions and
 * many items were published then the affiliate will get a notification for each set
 * of items that affected the same subscriptions.
 *
 * If the affiliate is an owner of the node, and the node is in a PEP service, then
 * all connected resources of the affiliated user will be sent an event notification.
 *
 * @param notification the message to sent to the subscribers. The message will be completed
 *        with the items to include in each notification.
 * @param event the event Element included in the notification message. Passed as an
 *        optimization to avoid future look ups.
 * @param leafNode the leaf node where the items where published.
 * @param publishedItems the list of items that were published. Could be an empty list.
 */
void sendPublishedNotifications(Message notification, Element event, LeafNode leafNode, List<PublishedItem> publishedItems) {
    if (!publishedItems.isEmpty()) {
        Map<List<NodeSubscription>, List<PublishedItem>> itemsBySubs = getItemsBySubscriptions(leafNode, publishedItems);
        // Send one notification for published items that affect the same subscriptions
        for (List<NodeSubscription> nodeSubscriptions : itemsBySubs.keySet()) {
            // Add items information
            Element items = event.addElement("items");
            items.addAttribute("node", getNode().getUniqueIdentifier().getNodeId());
            for (PublishedItem publishedItem : itemsBySubs.get(nodeSubscriptions)) {
                // If the node ID looks like a JID, replace it with the published item's node ID.
                if (getNode().getUniqueIdentifier().getNodeId().contains("@")) {
                    items.addAttribute("node", publishedItem.getNodeID());
                }
                // Add item information to the event notification
                Element item = items.addElement("item");
                if (leafNode.isItemRequired()) {
                    item.addAttribute("id", publishedItem.getID());
                }
                if (leafNode.isPayloadDelivered()) {
                    item.add(publishedItem.getPayload().createCopy());
                }
                // where the item was published are different
                if (leafNode != getNode()) {
                    item.addAttribute("node", leafNode.getUniqueIdentifier().getNodeId());
                }
            }
            // Send the event notification
            sendEventNotification(notification, nodeSubscriptions);
            // Remove the added items information
            event.remove(items);
        }
    } else {
        // Filter affiliate subscriptions and only use approved and configured ones
        List<NodeSubscription> affectedSubscriptions = new ArrayList<>();
        for (NodeSubscription subscription : getSubscriptions()) {
            if (subscription.canSendPublicationEvent(leafNode, null)) {
                affectedSubscriptions.add(subscription);
            }
        }
        // Add item information to the event notification
        Element items = event.addElement("items");
        items.addAttribute("node", leafNode.getUniqueIdentifier().getNodeId());
        // Send the event notification
        sendEventNotification(notification, affectedSubscriptions);
        // Remove the added items information
        event.remove(items);
    }
    // XEP-0136 specifies that all connected resources of the owner of the PEP service should also get a notification.
    if (leafNode.getService() instanceof PEPService) {
        final PEPService service = (PEPService) leafNode.getService();
        final Collection<ClientSession> sessions = SessionManager.getInstance().getSessions(service.getAddress().getNode());
        for (final ClientSession session : sessions) {
            // Add item information to the event notification
            Element items = event.addElement("items");
            items.addAttribute("node", leafNode.getUniqueIdentifier().getNodeId());
            for (PublishedItem publishedItem : publishedItems) {
                // If the node ID looks like a JID, replace it with the published item's node ID.
                if (getNode().getUniqueIdentifier().getNodeId().contains("@")) {
                    items.addAttribute("node", publishedItem.getNodeID());
                }
                // Add item information to the event notification
                Element item = items.addElement("item");
                if (leafNode.isItemRequired()) {
                    item.addAttribute("id", publishedItem.getID());
                }
                if (leafNode.isPayloadDelivered()) {
                    item.add(publishedItem.getPayload().createCopy());
                }
                // where the item was published are different
                if (leafNode != getNode()) {
                    item.addAttribute("node", leafNode.getUniqueIdentifier().getNodeId());
                }
            }
            // Send the event notification
            service.sendNotification(leafNode, notification, session.getAddress());
            // Remove the added items information
            event.remove(items);
        }
    }
}
Also used : PEPService(org.jivesoftware.openfire.pep.PEPService) Element(org.dom4j.Element) ClientSession(org.jivesoftware.openfire.session.ClientSession) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

PEPService (org.jivesoftware.openfire.pep.PEPService)8 Element (org.dom4j.Element)4 ClientSession (org.jivesoftware.openfire.session.ClientSession)3 ArrayList (java.util.ArrayList)2 PEPServiceManager (org.jivesoftware.openfire.pep.PEPServiceManager)2 LeafNode (org.jivesoftware.openfire.pubsub.LeafNode)2 Node (org.jivesoftware.openfire.pubsub.Node)2 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 List (java.util.List)1 Lock (java.util.concurrent.locks.Lock)1 PubSubEngine (org.jivesoftware.openfire.pubsub.PubSubEngine)1 PublishedItem (org.jivesoftware.openfire.pubsub.PublishedItem)1 DataForm (org.xmpp.forms.DataForm)1 JID (org.xmpp.packet.JID)1 Message (org.xmpp.packet.Message)1