Commit 6a884e2b authored by Matt Tucker's avatar Matt Tucker Committed by matt

Final round of pubsub updates for 2.6.0.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3728 b35dd754-fafc-0310-a699-88a17e54d16e
parent e81d57d2
...@@ -724,7 +724,7 @@ public class NodeSubscription { ...@@ -724,7 +724,7 @@ public class NodeSubscription {
* @return true if the published item matches the keyword filter specified in * @return true if the published item matches the keyword filter specified in
* the subscription. * the subscription.
*/ */
private boolean isKeywordMatched(PublishedItem publishedItem) { boolean isKeywordMatched(PublishedItem publishedItem) {
// Check if keyword was defined and it was not matched // Check if keyword was defined and it was not matched
if (keyword != null && keyword.length() > 0 && !publishedItem.containsKeyword(keyword)) { if (keyword != null && keyword.length() > 0 && !publishedItem.containsKeyword(keyword)) {
return false; return false;
......
...@@ -179,7 +179,8 @@ public class PubSubEngine { ...@@ -179,7 +179,8 @@ public class PubSubEngine {
String nodeID = action.attributeValue("node"); String nodeID = action.attributeValue("node");
if (nodeID == null) { if (nodeID == null) {
// if user is not sysadmin then return nodeid-required error // if user is not sysadmin then return nodeid-required error
if (!service.isServiceAdmin(iq.getFrom())) { if (!service.isServiceAdmin(iq.getFrom()) ||
!service.isCollectionNodesSupported()) {
// Configure elements must have a node attribute so answer an error // Configure elements must have a node attribute so answer an error
Element pubsubError = DocumentHelper.createElement(QName.get( Element pubsubError = DocumentHelper.createElement(QName.get(
"nodeid-required", "http://jabber.org/protocol/pubsub#errors")); "nodeid-required", "http://jabber.org/protocol/pubsub#errors"));
...@@ -321,7 +322,7 @@ public class PubSubEngine { ...@@ -321,7 +322,7 @@ public class PubSubEngine {
// No node was specified. Return bad_request error // No node was specified. Return bad_request error
Element pubsubError = DocumentHelper.createElement(QName.get( Element pubsubError = DocumentHelper.createElement(QName.get(
"nodeid-required", "http://jabber.org/protocol/pubsub#errors")); "nodeid-required", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.item_not_found, pubsubError); sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
return; return;
} }
else { else {
...@@ -408,7 +409,7 @@ public class PubSubEngine { ...@@ -408,7 +409,7 @@ public class PubSubEngine {
// No node was specified. Return bad_request error // No node was specified. Return bad_request error
Element pubsubError = DocumentHelper.createElement(QName.get( Element pubsubError = DocumentHelper.createElement(QName.get(
"nodeid-required", "http://jabber.org/protocol/pubsub#errors")); "nodeid-required", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.item_not_found, pubsubError); sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
return; return;
} }
else { else {
...@@ -423,7 +424,6 @@ public class PubSubEngine { ...@@ -423,7 +424,6 @@ public class PubSubEngine {
// Get the items to delete // Get the items to delete
Iterator itemElements = retractElement.elementIterator("item"); Iterator itemElements = retractElement.elementIterator("item");
if (!itemElements.hasNext()) { if (!itemElements.hasNext()) {
// TODO Confirm that at least one item should be present in the retract element. Waiting for stpeter confirmation.
Element pubsubError = DocumentHelper.createElement(QName.get( Element pubsubError = DocumentHelper.createElement(QName.get(
"item-required", "http://jabber.org/protocol/pubsub#errors")); "item-required", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError); sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
...@@ -431,17 +431,21 @@ public class PubSubEngine { ...@@ -431,17 +431,21 @@ public class PubSubEngine {
} }
if (node.isCollectionNode()) { if (node.isCollectionNode()) {
// TODO Is this the correct error to return???
// Cannot delete items from a collection node. Return an error. // Cannot delete items from a collection node. Return an error.
sendErrorPacket(iq, PacketError.Condition.not_allowed, null); Element pubsubError = DocumentHelper.createElement(QName.get(
"unsupported", "http://jabber.org/protocol/pubsub#errors"));
pubsubError.addAttribute("feature", "persistent-items");
sendErrorPacket(iq, PacketError.Condition.feature_not_implemented, pubsubError);
return; return;
} }
LeafNode leafNode = (LeafNode) node; LeafNode leafNode = (LeafNode) node;
if (!leafNode.isItemRequired()) { if (!leafNode.isItemRequired()) {
// TODO JEP specifies to return this error if node is not persisting items but this checking makes more sense. Waiting for stpeter confirmation.
// Cannot delete items from a leaf node that doesn't handle itemIDs. Return an error. // Cannot delete items from a leaf node that doesn't handle itemIDs. Return an error.
sendErrorPacket(iq, PacketError.Condition.not_allowed, null); Element pubsubError = DocumentHelper.createElement(QName.get(
"unsupported", "http://jabber.org/protocol/pubsub#errors"));
pubsubError.addAttribute("feature", "persistent-items");
sendErrorPacket(iq, PacketError.Condition.feature_not_implemented, pubsubError);
return; return;
} }
...@@ -449,7 +453,6 @@ public class PubSubEngine { ...@@ -449,7 +453,6 @@ public class PubSubEngine {
while (itemElements.hasNext()) { while (itemElements.hasNext()) {
Element itemElement = (Element) itemElements.next(); Element itemElement = (Element) itemElements.next();
String itemID = itemElement.attributeValue("id"); String itemID = itemElement.attributeValue("id");
// TODO Return an error if no id was specified?
if (itemID != null) { if (itemID != null) {
PublishedItem item = node.getPublishedItem(itemID); PublishedItem item = node.getPublishedItem(itemID);
if (item == null) { if (item == null) {
...@@ -463,11 +466,18 @@ public class PubSubEngine { ...@@ -463,11 +466,18 @@ public class PubSubEngine {
} }
else { else {
// Publisher does not have sufficient privileges to delete this item // Publisher does not have sufficient privileges to delete this item
sendErrorPacket(iq, PacketError.Condition.not_authorized, null); sendErrorPacket(iq, PacketError.Condition.forbidden, null);
return; return;
} }
} }
} }
else {
// No item ID was specified so return a bad_request error
Element pubsubError = DocumentHelper.createElement(QName.get(
"item-required", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
return;
}
} }
// Send reply with success // Send reply with success
router.route(IQ.createResultIQ(iq)); router.route(IQ.createResultIQ(iq));
...@@ -479,9 +489,18 @@ public class PubSubEngine { ...@@ -479,9 +489,18 @@ public class PubSubEngine {
String nodeID = subscribeElement.attributeValue("node"); String nodeID = subscribeElement.attributeValue("node");
Node node; Node node;
if (nodeID == null) { if (nodeID == null) {
if (service.isCollectionNodesSupported()) {
// Entity subscribes to root collection node // Entity subscribes to root collection node
node = service.getRootCollectionNode(); node = service.getRootCollectionNode();
} }
else {
// Service does not have a root collection node so return a nodeid-required error
Element pubsubError = DocumentHelper.createElement(QName.get(
"nodeid-required", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
return;
}
}
else { else {
// Look for the specified node // Look for the specified node
node = service.getNode(nodeID); node = service.getNode(nodeID);
...@@ -599,9 +618,18 @@ public class PubSubEngine { ...@@ -599,9 +618,18 @@ public class PubSubEngine {
String subID = unsubscribeElement.attributeValue("subid"); String subID = unsubscribeElement.attributeValue("subid");
Node node; Node node;
if (nodeID == null) { if (nodeID == null) {
if (service.isCollectionNodesSupported()) {
// Entity unsubscribes from root collection node // Entity unsubscribes from root collection node
node = service.getRootCollectionNode(); node = service.getRootCollectionNode();
} }
else {
// Service does not have a root collection node so return a nodeid-required error
Element pubsubError = DocumentHelper.createElement(QName.get(
"nodeid-required", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
return;
}
}
else { else {
// Look for the specified node // Look for the specified node
node = service.getNode(nodeID); node = service.getNode(nodeID);
...@@ -678,9 +706,18 @@ public class PubSubEngine { ...@@ -678,9 +706,18 @@ public class PubSubEngine {
String subID = optionsElement.attributeValue("subid"); String subID = optionsElement.attributeValue("subid");
Node node; Node node;
if (nodeID == null) { if (nodeID == null) {
if (service.isCollectionNodesSupported()) {
// Entity requests subscription options of root collection node // Entity requests subscription options of root collection node
node = service.getRootCollectionNode(); node = service.getRootCollectionNode();
} }
else {
// Service does not have a root collection node so return a nodeid-required error
Element pubsubError = DocumentHelper.createElement(QName.get(
"nodeid-required", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
return;
}
}
else { else {
// Look for the specified node // Look for the specified node
node = service.getNode(nodeID); node = service.getNode(nodeID);
...@@ -750,9 +787,18 @@ public class PubSubEngine { ...@@ -750,9 +787,18 @@ public class PubSubEngine {
String subID = optionsElement.attributeValue("subid"); String subID = optionsElement.attributeValue("subid");
Node node; Node node;
if (nodeID == null) { if (nodeID == null) {
if (service.isCollectionNodesSupported()) {
// Entity submits new subscription options of root collection node // Entity submits new subscription options of root collection node
node = service.getRootCollectionNode(); node = service.getRootCollectionNode();
} }
else {
// Service does not have a root collection node so return a nodeid-required error
Element pubsubError = DocumentHelper.createElement(QName.get(
"nodeid-required", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
return;
}
}
else { else {
// Look for the specified node // Look for the specified node
node = service.getNode(nodeID); node = service.getNode(nodeID);
...@@ -884,11 +930,14 @@ public class PubSubEngine { ...@@ -884,11 +930,14 @@ public class PubSubEngine {
private void getPublishedItems(IQ iq, Element itemsElement) { private void getPublishedItems(IQ iq, Element itemsElement) {
String nodeID = itemsElement.attributeValue("node"); String nodeID = itemsElement.attributeValue("node");
//String subID = itemsElement.attributeValue("subid"); String subID = itemsElement.attributeValue("subid");
Node node; Node node;
if (nodeID == null) { if (nodeID == null) {
// Entity subscribes to root collection node // User must specify a leaf node ID so return a nodeid-required error
node = service.getRootCollectionNode(); Element pubsubError = DocumentHelper.createElement(QName.get(
"nodeid-required", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.bad_request, pubsubError);
return;
} }
else { else {
// Look for the specified node // Look for the specified node
...@@ -925,8 +974,8 @@ public class PubSubEngine { ...@@ -925,8 +974,8 @@ public class PubSubEngine {
return; return;
} }
/*// Get the user's subscription // Get the user's subscription
NodeSubscription subscription; NodeSubscription subscription = null;
if (node.isMultipleSubscriptionsEnabled()) { if (node.isMultipleSubscriptionsEnabled()) {
if (subID == null) { if (subID == null) {
// No subid was specified and the node supports multiple subscriptions // No subid was specified and the node supports multiple subscriptions
...@@ -945,7 +994,15 @@ public class PubSubEngine { ...@@ -945,7 +994,15 @@ public class PubSubEngine {
return; return;
} }
} }
}*/ }
if (subscription != null && !subscription.isActive()) {
Element pubsubError = DocumentHelper.createElement(
QName.get("not-subscribed", "http://jabber.org/protocol/pubsub#errors"));
sendErrorPacket(iq, PacketError.Condition.not_authorized, pubsubError);
return;
}
LeafNode leafNode = (LeafNode) node; LeafNode leafNode = (LeafNode) node;
// Get list of items to send to the user // Get list of items to send to the user
...@@ -966,15 +1023,16 @@ public class PubSubEngine { ...@@ -966,15 +1023,16 @@ public class PubSubEngine {
} }
if (max_items != null) { if (max_items != null) {
// Get the N most recent published items // Get the N most recent published items
items = leafNode.getPublishedItems(recentItems); items = new ArrayList<PublishedItem>(leafNode.getPublishedItems(recentItems));
} }
else { else {
List requestedItems = itemsElement.elements("item"); List requestedItems = itemsElement.elements("item");
if (requestedItems.isEmpty()) { if (requestedItems.isEmpty()) {
// Get all the active items that were published to the node // Get all the active items that were published to the node
items = leafNode.getPublishedItems(); items = new ArrayList<PublishedItem>(leafNode.getPublishedItems());
} }
else { else {
items = new ArrayList<PublishedItem>();
// Indicate that payload should be included (if exists) no matter // Indicate that payload should be included (if exists) no matter
// the node configuration // the node configuration
forceToIncludePayload = true; forceToIncludePayload = true;
...@@ -989,6 +1047,18 @@ public class PubSubEngine { ...@@ -989,6 +1047,18 @@ public class PubSubEngine {
} }
} }
} }
if (subscription != null && subscription.getKeyword() != null) {
// Filter items that do not match the subscription keyword
for (Iterator<PublishedItem> it = items.iterator(); it.hasNext();) {
PublishedItem item = it.next();
if (!subscription.isKeywordMatched(item)) {
// Remove item that does not match keyword
it.remove();
}
}
}
// Send items to the user // Send items to the user
leafNode.sendPublishedItems(iq, items, forceToIncludePayload); leafNode.sendPublishedItems(iq, items, forceToIncludePayload);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment