You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by mj...@apache.org on 2009/08/06 10:01:47 UTC

svn commit: r801534 - in /mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src: main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/ main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/ main/java/org/apache...

Author: mjakl
Date: Thu Aug  6 08:01:46 2009
New Revision: 801534

URL: http://svn.apache.org/viewvc?rev=801534&view=rev
Log:
A user is now able to retrieve his/her subscriptions to a single node or to all nodes (retrieve-subscriptions). This fixes VYSPER-85.

Added:
    mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/NodeSubscriberVisitor.java
    mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/SubscriptionItem.java
    mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/PubSubRetrieveSubscriptionsHandler.java
    mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/SubscriberSubscriptionVisitor.java
    mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/PubSubRetrieveSubscriptionsTestCase.java
Modified:
    mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/AbstractPublishSubscribeIQHandler.java
    mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/SubscriberPayloadNotificationVisitor.java
    mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/SubscriberVisitor.java
    mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/model/LeafNode.java
    mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/LeafNodeInMemoryStorageProvider.java
    mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/PubSubTests.java
    mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/disco/PubSubDiscoInfoTestCase.java

Modified: mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/AbstractPublishSubscribeIQHandler.java
URL: http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/AbstractPublishSubscribeIQHandler.java?rev=801534&r1=801533&r2=801534&view=diff
==============================================================================
--- mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/AbstractPublishSubscribeIQHandler.java (original)
+++ mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/AbstractPublishSubscribeIQHandler.java Thu Aug  6 08:01:46 2009
@@ -110,9 +110,6 @@
      */
     protected String extractNodeName(IQStanza stanza) {
         String node = stanza.getFirstInnerElement().getFirstInnerElement().getAttributeValue("node");
-        if(node == null) {
-            //throw Exception();
-        }
         return node;
     }
 }

Added: mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/NodeSubscriberVisitor.java
URL: http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/NodeSubscriberVisitor.java?rev=801534&view=auto
==============================================================================
--- mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/NodeSubscriberVisitor.java (added)
+++ mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/NodeSubscriberVisitor.java Thu Aug  6 08:01:46 2009
@@ -0,0 +1,66 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.vysper.xmpp.modules.extension.xep0060_pubsub;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.vysper.xmpp.addressing.Entity;
+import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.handler.SubscriberSubscriptionVisitor;
+import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.model.LeafNode;
+
+/**
+ * This Visitor is used to traverse over all nodes of a collection node
+ * and collect all subscriptions of a user (matching bare JIDs).
+ *  
+ * @author The Apache MINA Project (http://mina.apache.org)
+ */
+public class NodeSubscriberVisitor implements NodeVisitor {
+
+    // the collected subscriptions
+    protected List<SubscriptionItem> subscriptions = null;
+    // the user to filter
+    protected Entity bareJID = null;
+    
+    /**
+     * Create a new visitor with the user as filter.
+     */
+    public NodeSubscriberVisitor(Entity userJID) {
+        this.bareJID = userJID.getBareJID();
+        subscriptions = new ArrayList<SubscriptionItem>();
+    }
+
+    /**
+     * Called for each node. Adds all subscriptions to the global list of subscriptions.
+     */
+    public void visit(LeafNode node) {
+        SubscriberSubscriptionVisitor subscriptionVisitor = new SubscriberSubscriptionVisitor(bareJID);
+        node.acceptSubscribers(subscriptionVisitor);
+        subscriptions.addAll(subscriptionVisitor.getSubscriptions());
+    }
+
+    /**
+     * Returns the list of subscriptions.
+     */
+    public List<SubscriptionItem> getSubscriptions() {
+        return subscriptions;
+    }
+    
+}

Modified: mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/SubscriberPayloadNotificationVisitor.java
URL: http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/SubscriberPayloadNotificationVisitor.java?rev=801534&r1=801533&r2=801534&view=diff
==============================================================================
--- mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/SubscriberPayloadNotificationVisitor.java (original)
+++ mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/SubscriberPayloadNotificationVisitor.java Thu Aug  6 08:01:46 2009
@@ -65,9 +65,10 @@
      * Send each visited subscriber a notification with the configured payload included.
      * 
      * @param nodeJID the node from which the message comes from
+     * @param subscriptionID the subscription ID
      * @param subscriber the receiver of the notification
      */
-    public void visit(String nodeName, Entity subscriber) {
+    public void visit(String nodeName, String subscriptionID, Entity subscriber) {
         Stanza event = createMessageEventStanza(nodeName, subscriber, "en", item); // TODO extract the hardcoded "en"
 
         try {

Modified: mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/SubscriberVisitor.java
URL: http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/SubscriberVisitor.java?rev=801534&r1=801533&r2=801534&view=diff
==============================================================================
--- mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/SubscriberVisitor.java (original)
+++ mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/SubscriberVisitor.java Thu Aug  6 08:01:46 2009
@@ -33,8 +33,9 @@
      * over all subscriptions of a node.
      * 
      * @param nodeName the name of the node
+     * @param subID the subscription ID
      * @param sub the subscriber JID
      */
-    public void visit(String nodeName, Entity sub);
+    public void visit(String nodeName, String subID, Entity sub);
 
 }

Added: mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/SubscriptionItem.java
URL: http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/SubscriptionItem.java?rev=801534&view=auto
==============================================================================
--- mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/SubscriptionItem.java (added)
+++ mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/SubscriptionItem.java Thu Aug  6 08:01:46 2009
@@ -0,0 +1,70 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.vysper.xmpp.modules.extension.xep0060_pubsub;
+
+import org.apache.vysper.xmpp.addressing.Entity;
+
+/** 
+ * @author The Apache MINA Project (http://mina.apache.org)
+ */
+public class SubscriptionItem {
+
+    protected String nodeName = null;
+    protected String subscriptionID = null;
+    protected Entity subscriberJID = null;
+    
+    /**
+     * Creates a new subscription item with teh supplied name, subscriptionID and subscriber JID.
+     */
+    public SubscriptionItem(String nodeName, String subID, Entity sub) {
+        this.nodeName = nodeName;
+        this.subscriptionID = subID;
+        this.subscriberJID = sub;
+    }
+
+    /**
+     * @return the nodeName of the subscription.
+     */
+    public String getNodeName() {
+        return nodeName;
+    }
+
+    /**
+     * @return the JID of the subscriber.
+     */
+    public Entity getSubscriberJID() {
+        return subscriberJID;
+    }
+
+    /**
+     * @return the subscription ID of this subscription.
+     */
+    public String getSubscriptionID() {
+        return subscriptionID;
+    }
+    
+    /**
+     * @return the state of the subscription. Currently fixed as "subscribed".
+     */
+    public String getSubscriptionState() {
+        return "subscribed"; // TODO
+    }
+
+}

Added: mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/PubSubRetrieveSubscriptionsHandler.java
URL: http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/PubSubRetrieveSubscriptionsHandler.java?rev=801534&view=auto
==============================================================================
--- mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/PubSubRetrieveSubscriptionsHandler.java (added)
+++ mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/PubSubRetrieveSubscriptionsHandler.java Thu Aug  6 08:01:46 2009
@@ -0,0 +1,134 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.vysper.xmpp.modules.extension.xep0060_pubsub.handler;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.vysper.compliance.SpecCompliant;
+import org.apache.vysper.xmpp.addressing.Entity;
+import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.NodeSubscriberVisitor;
+import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.PubSubServiceConfiguration;
+import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.SubscriptionItem;
+import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.model.CollectionNode;
+import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.model.LeafNode;
+import org.apache.vysper.xmpp.protocol.NamespaceURIs;
+import org.apache.vysper.xmpp.server.ServerRuntimeContext;
+import org.apache.vysper.xmpp.server.SessionContext;
+import org.apache.vysper.xmpp.stanza.IQStanza;
+import org.apache.vysper.xmpp.stanza.IQStanzaType;
+import org.apache.vysper.xmpp.stanza.Stanza;
+import org.apache.vysper.xmpp.stanza.StanzaBuilder;
+
+
+/**
+ * This class handles the "subscriptions" use cases for the "pubsub" namespace.
+ * 
+ * @author The Apache MINA Project (http://mina.apache.org)
+ */
+@SpecCompliant(spec="xep-0060", section="5.6", status= SpecCompliant.ComplianceStatus.FINISHED, coverage = SpecCompliant.ComplianceCoverage.PARTIAL)
+public class PubSubRetrieveSubscriptionsHandler extends AbstractPubSubGeneralHandler {
+
+    /**
+     * @param serviceConfiguration
+     */
+    public PubSubRetrieveSubscriptionsHandler(PubSubServiceConfiguration serviceConfiguration) {
+        super(serviceConfiguration);
+    }
+
+    /**
+     * @return "subscriptions" as worker element.
+     */
+    @Override
+    protected String getWorkerElement() {
+        return "subscriptions";
+    }
+
+    /**
+     * This method takes care of handling the "subscriptions" use-case
+     * 
+     * @return the appropriate response stanza
+     */
+    @Override
+    protected Stanza handleGet(IQStanza stanza,
+            ServerRuntimeContext serverRuntimeContext,
+            SessionContext sessionContext) {
+        Entity serverJID = serviceConfiguration.getServerJID();
+        CollectionNode root = serviceConfiguration.getRootNode();
+        
+        Entity sender = extractSenderJID(stanza, sessionContext);
+        String iqStanzaID = stanza.getAttributeValue("id");
+
+        StanzaBuilder sb = StanzaBuilder.createIQStanza(serverJID, sender, IQStanzaType.RESULT, iqStanzaID);
+        sb.startInnerElement("pubsub");
+        sb.addNamespaceAttribute(NamespaceURIs.XEP0060_PUBSUB);
+        String nodeName = extractNodeName(stanza);
+        
+        List<SubscriptionItem> subscriptions = collectSubscriptions(root, sender, nodeName);
+
+        buildSuccessStanza(sb, nodeName, subscriptions);
+
+        sb.endInnerElement(); // pubsub
+        return new IQStanza(sb.getFinalStanza());
+    }
+
+    /**
+     * Traverses through all nodes or a single node to collect all subscriptions of the user.
+     * @return the list of subscriptions or an empty list.
+     */
+    private List<SubscriptionItem> collectSubscriptions(CollectionNode root, Entity sender, String nodeName) {
+        List<SubscriptionItem> subscriptions;
+        if(nodeName == null) { // all subscriptions for all nodes
+            NodeSubscriberVisitor nodeSubscriptionVisitor = new NodeSubscriberVisitor(sender);
+            root.acceptNodes(nodeSubscriptionVisitor);
+            subscriptions = nodeSubscriptionVisitor.getSubscriptions();
+        } else { // only the subscriptions for the requested node
+            LeafNode node = root.find(nodeName);
+
+            if(node == null) {
+                // done - this is only a filter - no error conditions are defined
+                subscriptions = Collections.emptyList();
+            } else {
+                SubscriberSubscriptionVisitor subscriptionVisitor = new SubscriberSubscriptionVisitor(sender);
+                node.acceptSubscribers(subscriptionVisitor);
+                subscriptions = subscriptionVisitor.getSubscriptions();
+            }
+        }
+        return subscriptions;
+    }
+
+    /**
+     * This method adds the default "success" elements to the given StanzaBuilder.
+     */
+    private void buildSuccessStanza(StanzaBuilder sb, String nodeName, List<SubscriptionItem> subscriptions) {
+        sb.startInnerElement("subscriptions");
+        
+        for(SubscriptionItem s : subscriptions) {
+            sb.startInnerElement("subscription");
+            sb.addAttribute("node", s.getNodeName());
+            sb.addAttribute("jid", s.getSubscriberJID().getFullQualifiedName());
+            sb.addAttribute("subscription", s.getSubscriptionState());
+            sb.addAttribute("subid", s.getSubscriptionID());
+            sb.endInnerElement();
+        }
+        
+        sb.endInnerElement();
+    }
+}

Added: mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/SubscriberSubscriptionVisitor.java
URL: http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/SubscriberSubscriptionVisitor.java?rev=801534&view=auto
==============================================================================
--- mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/SubscriberSubscriptionVisitor.java (added)
+++ mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/SubscriberSubscriptionVisitor.java Thu Aug  6 08:01:46 2009
@@ -0,0 +1,66 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.vysper.xmpp.modules.extension.xep0060_pubsub.handler;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.vysper.xmpp.addressing.Entity;
+import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.SubscriberVisitor;
+import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.SubscriptionItem;
+
+/**
+ * This Visitor is used to traverse over all subscriptions of a user (matching bare JIDs).
+ *  
+ * @author The Apache MINA Project (http://mina.apache.org)
+ */
+public class SubscriberSubscriptionVisitor implements SubscriberVisitor {
+
+    // the collected subscriptions
+    protected List<SubscriptionItem> subscriptions = null;
+    // the user to filter
+    protected Entity bareJID = null;
+    
+    /**
+     * Create a new visitor with the user as filter.
+     */
+    public SubscriberSubscriptionVisitor(Entity userJID) {
+        this.bareJID = userJID.getBareJID();
+        subscriptions = new ArrayList<SubscriptionItem>();
+    }
+    
+    /**
+     * Traverses all subscriptions and collects the subscriptions of the
+     * user (matching bareJID).
+     */
+    public void visit(String nodeName, String subID, Entity sub) {
+        if(sub.getBareJID().equals(bareJID)) {
+            SubscriptionItem si = new SubscriptionItem(nodeName, subID, sub);
+            subscriptions.add(si);
+        }
+    }
+
+    /**
+     * Returns the list of subscriptions.
+     */
+    public List<SubscriptionItem> getSubscriptions() {
+        return subscriptions;
+    }
+}

Modified: mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/model/LeafNode.java
URL: http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/model/LeafNode.java?rev=801534&r1=801533&r2=801534&view=diff
==============================================================================
--- mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/model/LeafNode.java (original)
+++ mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/model/LeafNode.java Thu Aug  6 08:01:46 2009
@@ -28,6 +28,7 @@
 import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.PubSubAffiliation;
 import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.PubSubServiceConfiguration;
 import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.SubscriberPayloadNotificationVisitor;
+import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.SubscriberVisitor;
 import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.feature.PubsubFeatures;
 import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.storageprovider.LeafNodeStorageProvider;
 import org.apache.vysper.xmpp.modules.servicediscovery.management.Feature;
@@ -191,6 +192,14 @@
     }
 
     /**
+     * Call the SubscriberVisitor for each subscription of this node.
+     * @param sv
+     */
+    public void acceptSubscribers(SubscriberVisitor sv) {
+        storage.acceptForEachSubscriber(name, sv);
+    }
+    
+    /**
      * @return the name of the node.
      */
     public String getName() {
@@ -220,6 +229,7 @@
         infoElements.add(PubsubFeatures.MULTI_SUBSCRIBE.getFeature());
         infoElements.add(PubsubFeatures.PUBLISH.getFeature());
         infoElements.add(PubsubFeatures.SUBSCRIBE.getFeature());
+        infoElements.add(PubsubFeatures.RETRIEVE_SUBSCRIPTIONS.getFeature());
         return infoElements;
     }
 

Modified: mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/LeafNodeInMemoryStorageProvider.java
URL: http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/LeafNodeInMemoryStorageProvider.java?rev=801534&r1=801533&r2=801534&view=diff
==============================================================================
--- mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/LeafNodeInMemoryStorageProvider.java (original)
+++ mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/main/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/storageprovider/LeafNodeInMemoryStorageProvider.java Thu Aug  6 08:01:46 2009
@@ -138,8 +138,8 @@
      */
     public void acceptForEachSubscriber(String nodeName, SubscriberVisitor subscriberVisitor) {
         Map<String, Entity> subscribers = nodeSubscribers.get(nodeName);
-        for(Entity sub : subscribers.values()) {
-            subscriberVisitor.visit(nodeName, sub);
+        for(String subID : subscribers.keySet()) {
+            subscriberVisitor.visit(nodeName, subID, subscribers.get(subID));
         }
     }
 

Modified: mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/PubSubTests.java
URL: http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/PubSubTests.java?rev=801534&r1=801533&r2=801534&view=diff
==============================================================================
--- mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/PubSubTests.java (original)
+++ mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/PubSubTests.java Thu Aug  6 08:01:46 2009
@@ -26,6 +26,7 @@
 import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.disco.PubSubDiscoItemsTestCase;
 import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.handler.PubSubCreateNodeTestCase;
 import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.handler.PubSubPublishTestCase;
+import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.handler.PubSubRetrieveSubscriptionsTestCase;
 import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.handler.PubSubSubscribeTestCase;
 import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.handler.PubSubUnsubscribeTestCase;
 import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.handler.owner.PubSubConfigureNodeTestCase;
@@ -50,6 +51,7 @@
         suite.addTestSuite(PubSubPublishTestCase.class);
         suite.addTestSuite(PubSubSubscribeTestCase.class);
         suite.addTestSuite(PubSubUnsubscribeTestCase.class);
+        suite.addTestSuite(PubSubRetrieveSubscriptionsTestCase.class);
 
         suite.addTestSuite(CollectionNodeTestCase.class);
         suite.addTestSuite(LeafNodeTestCase.class);

Modified: mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/disco/PubSubDiscoInfoTestCase.java
URL: http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/disco/PubSubDiscoInfoTestCase.java?rev=801534&r1=801533&r2=801534&view=diff
==============================================================================
--- mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/disco/PubSubDiscoInfoTestCase.java (original)
+++ mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/disco/PubSubDiscoInfoTestCase.java Thu Aug  6 08:01:46 2009
@@ -119,6 +119,7 @@
                 , PubsubFeatures.MULTI_SUBSCRIBE.toString()
                 , PubsubFeatures.PUBLISH.toString()
                 , PubsubFeatures.SUBSCRIBE.toString()
+                , PubsubFeatures.RETRIEVE_SUBSCRIPTIONS.toString()
                 };
         XMLElement[] elementList = collectFeatures(inner, featuresList);
         

Added: mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/PubSubRetrieveSubscriptionsTestCase.java
URL: http://svn.apache.org/viewvc/mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/PubSubRetrieveSubscriptionsTestCase.java?rev=801534&view=auto
==============================================================================
--- mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/PubSubRetrieveSubscriptionsTestCase.java (added)
+++ mina/sandbox/vysper/trunk/server/extensions/xep0060-pubsub/src/test/java/org/apache/vysper/xmpp/modules/extension/xep0060_pubsub/handler/PubSubRetrieveSubscriptionsTestCase.java Thu Aug  6 08:01:46 2009
@@ -0,0 +1,141 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.vysper.xmpp.modules.extension.xep0060_pubsub.handler;
+
+import org.apache.vysper.xmpp.addressing.Entity;
+import org.apache.vysper.xmpp.modules.core.base.handler.IQHandler;
+import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.AbstractPublishSubscribeTestCase;
+import org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.model.LeafNode;
+import org.apache.vysper.xmpp.protocol.NamespaceURIs;
+import org.apache.vysper.xmpp.protocol.ResponseStanzaContainer;
+import org.apache.vysper.xmpp.stanza.IQStanza;
+import org.apache.vysper.xmpp.stanza.IQStanzaType;
+import org.apache.vysper.xmpp.stanza.Stanza;
+import org.apache.vysper.xmpp.stanza.StanzaBuilder;
+import org.apache.vysper.xmpp.xmlfragment.XMLElement;
+
+/**
+ * @author The Apache MINA Project (http://mina.apache.org)
+ */
+public class PubSubRetrieveSubscriptionsTestCase extends AbstractPublishSubscribeTestCase {
+    protected LeafNode n1 = null;
+    protected LeafNode n2 = null;
+    protected LeafNode n3 = null;
+
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        
+        n1 = new LeafNode(serviceConfiguration, "Node1", "Node 1 used for testing purposes", client);
+        n2 = new LeafNode(serviceConfiguration, "Node2", "Node 2 used for testing purposes", client);
+        n3 = new LeafNode(serviceConfiguration, "Node3", "Node 3 used for testing purposes", client);
+        
+        root.add(n1);
+        root.add(n2);
+        root.add(n3);
+    }
+    
+    @Override
+    protected IQHandler getHandler() {
+        return new PubSubRetrieveSubscriptionsHandler(serviceConfiguration);
+    }
+
+    @Override
+    protected AbstractStanzaGenerator getDefaultStanzaGenerator() {
+        return new DefaultSubscribeStanzaGenerator();
+    }
+
+    public void testNoSubscriptions() {
+        AbstractStanzaGenerator sg = getDefaultStanzaGenerator();
+        Stanza stanza = sg.getStanza(client, pubsubService, "id123", null);
+        ResponseStanzaContainer result = sendStanza(stanza, true);
+        
+        assertTrue(result.hasResponse());
+        
+        IQStanza response = new IQStanza(result.getResponseStanza());
+        assertEquals(IQStanzaType.RESULT.value(),response.getType());
+        XMLElement sub = response.getFirstInnerElement().getFirstInnerElement();
+        assertEquals("subscriptions", sub.getName());
+        assertEquals(0, sub.getInnerElements().size()); // there should be no subscriptions
+    }
+    
+    public void testManySubscriptions() {
+        AbstractStanzaGenerator sg = getDefaultStanzaGenerator();
+        
+        n1.subscribe("id123", client);
+        n1.subscribe("id124", client);
+        n2.subscribe("id125", client);
+        n3.subscribe("id126", client);
+        
+        Stanza stanza = sg.getStanza(client, pubsubService, "4711", null);
+        ResponseStanzaContainer result = sendStanza(stanza, true);
+        
+        assertTrue(result.hasResponse());
+        
+        IQStanza response = new IQStanza(result.getResponseStanza());
+        assertEquals(IQStanzaType.RESULT.value(),response.getType());
+        XMLElement sub = response.getFirstInnerElement().getFirstInnerElement();
+        assertEquals("subscriptions", sub.getName());
+        assertEquals(4, sub.getInnerElements().size());
+    }
+    
+    public void testSubscriptionsForOneNode() {
+        AbstractStanzaGenerator sg = getDefaultStanzaGenerator();
+        
+        n1.subscribe("id123", client);
+        n1.subscribe("id124", client);
+        n2.subscribe("id125", client);
+        n3.subscribe("id126", client);
+        
+        Stanza stanza = sg.getStanza(client, pubsubService, "4711", "Node1");
+        ResponseStanzaContainer result = sendStanza(stanza, true);
+        
+        assertTrue(result.hasResponse());
+        
+        IQStanza response = new IQStanza(result.getResponseStanza());
+        assertEquals(IQStanzaType.RESULT.value(),response.getType());
+        XMLElement sub = response.getFirstInnerElement().getFirstInnerElement();
+        assertEquals("subscriptions", sub.getName());
+        assertEquals(2, sub.getInnerElements().size());
+    }
+
+    class DefaultSubscribeStanzaGenerator extends AbstractStanzaGenerator {
+        @Override
+        protected StanzaBuilder buildInnerElement(Entity client, Entity pubsub, StanzaBuilder sb, String node) {
+            sb.startInnerElement("subscriptions");
+            if(node!=null) {
+                sb.addAttribute("node", node);
+            }
+            sb.endInnerElement();
+            return sb;
+        }
+
+        @Override
+        protected String getNamespace() {
+            return NamespaceURIs.XEP0060_PUBSUB;
+        }
+
+        @Override
+        protected IQStanzaType getStanzaType() {
+            return IQStanzaType.GET;
+        }
+    }
+
+}