Commit c4d63641 authored by Robin Collier's avatar Robin Collier Committed by rcollier

OF-572 Added missing fields to configuration form and allow the hierarchy to be changed.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@13426 b35dd754-fafc-0310-a699-88a17e54d16e
parent 9f4bc5ad
...@@ -2650,9 +2650,15 @@ pubsub.form.conf.short_name=Short name for the node ...@@ -2650,9 +2650,15 @@ pubsub.form.conf.short_name=Short name for the node
pubsub.form.conf.itemreply=Select entity that should receive replies to items pubsub.form.conf.itemreply=Select entity that should receive replies to items
pubsub.form.conf.replyroom=Multi-user chat room to which replies should be sent pubsub.form.conf.replyroom=Multi-user chat room to which replies should be sent
pubsub.form.conf.replyto=Users to which replies should be sent pubsub.form.conf.replyto=Users to which replies should be sent
pubsub.form.conf.leaf_node_association=Users allowed to associate leaf nodes with the node pubsub.form.conf.collection=The collection with which a node is affiliated.
pubsub.form.conf.leaf_node_whitelist=Enter list of users pubsub.form.conf.node_type=Whether the node is a leaf (default) or a collection
pubsub.form.conf.leaf_nodes_max=Max number of leaf nodes pubsub.form.conf.children_association_policy=Who may associate leaf nodes with a collection
pubsub.form.conf.children_association_policy.all=Anyone may associate leaf nodes with the collection
pubsub.form.conf.children_association_policy.owners=Only collection node owners may associate leaf nodes with the collection
pubsub.form.conf.children_association_policy.whitelist=Only those on a whitelist may associate leaf nodes with the collection
pubsub.form.conf.children_association_whitelist=The list of JIDs that may associate leaf nodes with a collection
pubsub.form.conf.children_max=The maximum number of child nodes that can be associated with a collection
pubsub.form.conf.children=The child nodes (leaf or collection) associated with a collection
pubsub.notification.message.body=This message contains an event notification pubsub.notification.message.body=This message contains an event notification
pubsub.form.subscription.title=Subscription configuration pubsub.form.subscription.title=Subscription configuration
pubsub.form.subscription.instruction=Please provide the subscription configuration for node "{0}". pubsub.form.subscription.instruction=Please provide the subscription configuration for node "{0}".
......
...@@ -20,6 +20,13 @@ ...@@ -20,6 +20,13 @@
package org.jivesoftware.openfire.pubsub; package org.jivesoftware.openfire.pubsub;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.dom4j.Element; import org.dom4j.Element;
import org.jivesoftware.util.LocaleUtils; import org.jivesoftware.util.LocaleUtils;
import org.xmpp.forms.DataForm; import org.xmpp.forms.DataForm;
...@@ -27,9 +34,6 @@ import org.xmpp.forms.FormField; ...@@ -27,9 +34,6 @@ import org.xmpp.forms.FormField;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Message; import org.xmpp.packet.Message;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/** /**
* A type of node that contains nodes and/or other collections but no published * A type of node that contains nodes and/or other collections but no published
* items. Collections provide the foundation entity to provide a means of representing * items. Collections provide the foundation entity to provide a means of representing
...@@ -70,15 +74,17 @@ public class CollectionNode extends Node { ...@@ -70,15 +74,17 @@ public class CollectionNode extends Node {
@Override @Override
void configure(FormField field) { protected void configure(FormField field) throws NotAcceptableException {
List<String> values; List<String> values;
if ("pubsub#leaf_node_association_policy".equals(field.getVariable())) { if ("pubsub#leaf_node_association_policy".equals(field.getVariable()) ||
"pubsub#children_association_policy".equals(field.getVariable())) {
values = field.getValues(); values = field.getValues();
if (values.size() > 0) { if (values.size() > 0) {
associationPolicy = LeafNodeAssociationPolicy.valueOf(values.get(0)); associationPolicy = LeafNodeAssociationPolicy.valueOf(values.get(0));
} }
} }
else if ("pubsub#leaf_node_association_whitelist".equals(field.getVariable())) { else if ("pubsub#leaf_node_association_whitelist".equals(field.getVariable()) ||
"pubsub#children_association_whitelist".equals(field.getVariable())) {
// Get the new list of users that may add leaf nodes to this collection node // Get the new list of users that may add leaf nodes to this collection node
associationTrusted = new ArrayList<JID>(); associationTrusted = new ArrayList<JID>();
for (String value : field.getValues()) { for (String value : field.getValues()) {
...@@ -90,10 +96,41 @@ public class CollectionNode extends Node { ...@@ -90,10 +96,41 @@ public class CollectionNode extends Node {
} }
} }
} }
else if ("pubsub#leaf_nodes_max".equals(field.getVariable())) { else if ("pubsub#leaf_nodes_max".equals(field.getVariable()) ||
"pubsub#children_max".equals(field.getVariable())) {
values = field.getValues(); values = field.getValues();
maxLeafNodes = values.size() > 0 ? Integer.parseInt(values.get(0)) : -1; maxLeafNodes = values.size() > 0 ? Integer.parseInt(values.get(0)) : -1;
} }
else if ("pubsub#children".endsWith(field.getVariable())) {
values = field.getValues();
ArrayList<Node> childrenNodes = new ArrayList<Node>(values.size());
// Check all nodes for their existence
for (String nodeId : values)
{
Node childNode = service.getNode(nodeId);
if (childNode == null)
{
throw new NotAcceptableException("Child node does not exist");
}
childrenNodes.add(childNode);
}
// Remove any children not in the new list.
ArrayList<Node> toRemove = new ArrayList<Node>(nodes.values());
toRemove.removeAll(childrenNodes);
for (Node node : toRemove)
{
removeChildNode(node);
}
// Set the parent on the children.
for (Node node : childrenNodes)
{
node.changeParent(this);
}
}
} }
@Override @Override
...@@ -105,22 +142,48 @@ public class CollectionNode extends Node { ...@@ -105,22 +142,48 @@ public class CollectionNode extends Node {
protected void addFormFields(DataForm form, boolean isEditing) { protected void addFormFields(DataForm form, boolean isEditing) {
super.addFormFields(form, isEditing); super.addFormFields(form, isEditing);
FormField typeField = form.getField("pubsub#node_type");
typeField.addValue("collection");
// TODO: remove this field during an upgrade to pubsub version since it is replaced by children_association_policy
FormField formField = form.addField(); FormField formField = form.addField();
formField.setVariable("pubsub#leaf_node_association_policy"); formField.setVariable("pubsub#leaf_node_association_policy");
if (isEditing) { if (isEditing) {
formField.setType(FormField.Type.list_single); formField.setType(FormField.Type.list_single);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.leaf_node_association")); formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.children_association_policy"));
formField.addOption(null, LeafNodeAssociationPolicy.all.name()); formField.addOption(LocaleUtils.getLocalizedString("pubsub.form.conf.children_association_policy.all"), LeafNodeAssociationPolicy.all.name());
formField.addOption(null, LeafNodeAssociationPolicy.owners.name()); formField.addOption(LocaleUtils.getLocalizedString("pubsub.form.conf.children_association_policy.owners"), LeafNodeAssociationPolicy.owners.name());
formField.addOption(null, LeafNodeAssociationPolicy.whitelist.name()); formField.addOption(LocaleUtils.getLocalizedString("pubsub.form.conf.children_association_policy.whitelist"), LeafNodeAssociationPolicy.whitelist.name());
}
formField.addValue(associationPolicy.name());
formField = form.addField();
formField.setVariable("pubsub#children_association_policy");
if (isEditing) {
formField.setType(FormField.Type.list_single);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.children_association_policy"));
formField.addOption(LocaleUtils.getLocalizedString("pubsub.form.conf.children_association_policy.all"), LeafNodeAssociationPolicy.all.name());
formField.addOption(LocaleUtils.getLocalizedString("pubsub.form.conf.children_association_policy.owners"), LeafNodeAssociationPolicy.owners.name());
formField.addOption(LocaleUtils.getLocalizedString("pubsub.form.conf.children_association_policy.whitelist"), LeafNodeAssociationPolicy.whitelist.name());
} }
formField.addValue(associationPolicy.name()); formField.addValue(associationPolicy.name());
// TODO: remove this field during an upgrade to pubsub version since it is replaced by children_association_whitelist
formField = form.addField(); formField = form.addField();
formField.setVariable("pubsub#leaf_node_association_whitelist"); formField.setVariable("pubsub#leaf_node_association_whitelist");
if (isEditing) { if (isEditing) {
formField.setType(FormField.Type.jid_multi); formField.setType(FormField.Type.jid_multi);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.leaf_node_whitelist")); formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.children_association_whitelist"));
}
for (JID contact : associationTrusted) {
formField.addValue(contact.toString());
}
formField = form.addField();
formField.setVariable("pubsub#children_association_whitelist");
if (isEditing) {
formField.setType(FormField.Type.jid_multi);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.children_association_whitelist"));
} }
for (JID contact : associationTrusted) { for (JID contact : associationTrusted) {
formField.addValue(contact.toString()); formField.addValue(contact.toString());
...@@ -130,9 +193,27 @@ public class CollectionNode extends Node { ...@@ -130,9 +193,27 @@ public class CollectionNode extends Node {
formField.setVariable("pubsub#leaf_nodes_max"); formField.setVariable("pubsub#leaf_nodes_max");
if (isEditing) { if (isEditing) {
formField.setType(FormField.Type.text_single); formField.setType(FormField.Type.text_single);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.leaf_nodes_max")); formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.children_max"));
}
formField.addValue(maxLeafNodes);
formField = form.addField();
formField.setVariable("pubsub#chilren_max");
if (isEditing) {
formField.setType(FormField.Type.text_single);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.children_max"));
} }
formField.addValue(maxLeafNodes); formField.addValue(maxLeafNodes);
formField = form.addField();
formField.setVariable("pubsub#children");
if (isEditing) {
formField.setType(FormField.Type.text_multi);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.children"));
}
for (String nodeId : nodes.keySet()) {
formField.addValue(nodeId);
}
} }
/** /**
......
...@@ -89,7 +89,7 @@ public class LeafNode extends Node { ...@@ -89,7 +89,7 @@ public class LeafNode extends Node {
} }
@Override @Override
void configure(FormField field) { protected void configure(FormField field) throws NotAcceptableException {
List<String> values; List<String> values;
String booleanValue; String booleanValue;
if ("pubsub#persist_items".equals(field.getVariable())) { if ("pubsub#persist_items".equals(field.getVariable())) {
...@@ -128,6 +128,9 @@ public class LeafNode extends Node { ...@@ -128,6 +128,9 @@ public class LeafNode extends Node {
protected void addFormFields(DataForm form, boolean isEditing) { protected void addFormFields(DataForm form, boolean isEditing) {
super.addFormFields(form, isEditing); super.addFormFields(form, isEditing);
FormField typeField = form.getField("pubsub#node_type");
typeField.addValue("leaf");
FormField formField = form.addField(); FormField formField = form.addField();
formField.setVariable("pubsub#send_item_subscribe"); formField.setVariable("pubsub#send_item_subscribe");
if (isEditing) { if (isEditing) {
......
...@@ -56,7 +56,6 @@ import org.xmpp.packet.Message; ...@@ -56,7 +56,6 @@ import org.xmpp.packet.Message;
* @author Matt Tucker * @author Matt Tucker
*/ */
public abstract class Node { public abstract class Node {
public static final String PUBSUB_SVC_ID = XMPPServer.getInstance().getPubSubModule().getServiceID(); public static final String PUBSUB_SVC_ID = XMPPServer.getInstance().getPubSubModule().getServiceID();
/** /**
...@@ -662,6 +661,18 @@ public abstract class Node { ...@@ -662,6 +661,18 @@ public abstract class Node {
} }
} }
} }
else if ("pubsub#collection".equals(field.getVariable())) {
// Set the parent collection node
values = field.getValues();
String newParent = values.size() > 0 ? values.get(0) : " ";
Node newParentNode = service.getNode(newParent);
if (!(newParentNode instanceof CollectionNode))
{
throw new NotAcceptableException("Specified node in field pubsub#collection [" + newParent + "] " + ((newParentNode == null) ? "does not exist" : "is not a collection node"));
}
changeParent((CollectionNode) newParentNode);
}
else { else {
// Let subclasses be configured by specified fields // Let subclasses be configured by specified fields
configure(field); configure(field);
...@@ -683,7 +694,7 @@ public abstract class Node { ...@@ -683,7 +694,7 @@ public abstract class Node {
addOwner(jid); addOwner(jid);
} }
} }
// TODO Before removing owner or admin check if user was changed from admin to owner or vice versa. This way his susbcriptions are not going to be deleted. // TODO Before removing owner or admin check if user was changed from admin to owner or vice versa. This way his subscriptions are not going to be deleted.
// Set the new list of publishers // Set the new list of publishers
FormField publisherField = completedForm.getField("pubsub#publisher"); FormField publisherField = completedForm.getField("pubsub#publisher");
if (publisherField != null) { if (publisherField != null) {
...@@ -742,8 +753,9 @@ public abstract class Node { ...@@ -742,8 +753,9 @@ public abstract class Node {
* fields specific to the node type. * fields specific to the node type.
* *
* @param field the form field specific to the node type. * @param field the form field specific to the node type.
* @throws NotAcceptableException if field cannot be configured because of invalid data.
*/ */
abstract void configure(FormField field); protected abstract void configure(FormField field) throws NotAcceptableException;
/** /**
* Node configuration was changed based on the completed form. Subclasses may implement * Node configuration was changed based on the completed form. Subclasses may implement
...@@ -871,6 +883,24 @@ public abstract class Node { ...@@ -871,6 +883,24 @@ public abstract class Node {
} }
formField.addValue(description); formField.addValue(description);
formField = form.addField();
formField.setVariable("pubsub#node_type");
if (isEditing) {
formField.setType(FormField.Type.text_single);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.node_type"));
}
formField = form.addField();
formField.setVariable("pubsub#collection");
if (isEditing) {
formField.setType(FormField.Type.text_single);
formField.setLabel(LocaleUtils.getLocalizedString("pubsub.form.conf.collection"));
}
if (!parent.isRootCollectionNode()) {
formField.addValue(parent.getNodeID());
}
formField = form.addField(); formField = form.addField();
formField.setVariable("pubsub#subscribe"); formField.setVariable("pubsub#subscribe");
if (isEditing) { if (isEditing) {
...@@ -1871,6 +1901,10 @@ public abstract class Node { ...@@ -1871,6 +1901,10 @@ public abstract class Node {
* @param newParent the new parent node of this node. * @param newParent the new parent node of this node.
*/ */
protected void changeParent(CollectionNode newParent) { protected void changeParent(CollectionNode newParent) {
if (parent == newParent) {
return;
}
if (parent != null) { if (parent != null) {
// Remove this node from the current parent node // Remove this node from the current parent node
parent.removeChildNode(this); parent.removeChildNode(this);
...@@ -2259,4 +2293,27 @@ public abstract class Node { ...@@ -2259,4 +2293,27 @@ public abstract class Node {
*/ */
publisher publisher
} }
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + nodeID.hashCode();
result = prime * result + service.getServiceID().hashCode();
return result;
}
@Override
public boolean equals(Object obj) {
if (obj == this)
return true;
if (getClass() != obj.getClass())
return false;
Node compareNode = (Node) obj;
return (service.getServiceID().equals(compareNode.service.getServiceID()) && nodeID.equals(compareNode.nodeID));
}
} }
...@@ -368,7 +368,7 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di ...@@ -368,7 +368,7 @@ public class PubSubModule extends BasicModule implements ServerItemsProvider, Di
routingTable = server.getRoutingTable(); routingTable = server.getRoutingTable();
router = server.getPacketRouter(); router = server.getPacketRouter();
engine = new PubSubEngine(server.getPacketRouter()); engine = new PubSubEngine(router);
// Load default configuration for leaf nodes // Load default configuration for leaf nodes
leafDefaultConfiguration = PubSubPersistenceManager.loadDefaultConfiguration(this, true); leafDefaultConfiguration = PubSubPersistenceManager.loadDefaultConfiguration(this, true);
......
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