Commit cb24188f authored by Gabriel Guardincerri's avatar Gabriel Guardincerri Committed by gguardin

[JM-1399] ClearspaceGroupProvider sends a change event when loading groups. To be reviewed by Gato

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@10578 b35dd754-fafc-0310-a699-88a17e54d16e
parent 7c2385f6
......@@ -23,9 +23,7 @@ import org.jivesoftware.openfire.group.GroupProvider;
import org.jivesoftware.openfire.user.UserNotFoundException;
import org.xmpp.packet.JID;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.*;
/**
* @author Daniel Henninger
......@@ -193,19 +191,28 @@ public class ClearspaceGroupProvider implements GroupProvider {
// this won't happen, the group exists.
}
// Creates the group
Group group = new Group(name, description, members, administrators);
Map<String, String> properties = new HashMap<String, String>();
// Type 0 is OPEN
if (type == 0) {
group.getProperties().put("sharedRoster.showInRoster", "everybody");
properties.put("sharedRoster.showInRoster", "everybody");
} else {
// Types 1, 2 or 3 are MEMBER_ONLY, PRIVATE, SECRET
group.getProperties().put("sharedRoster.showInRoster", "onlyGroup");
properties.put("sharedRoster.showInRoster", "onlyGroup");
}
group.getProperties().put("sharedRoster.displayName", displayName);
group.getProperties().put("sharedRoster.groupList", "");
properties.put("sharedRoster.displayName", displayName);
properties.put("sharedRoster.groupList", "");
// Creates the group
// There are some interesting things happening here.
// If this is the first time that this group is loaded from CS, the OF will save this properties.
// If this is not the first time and these properties haven't changed, then nothing happens
// If this is not the first time but these properties have changed, then OF will update it's saved data.
// And this is OK, event if this "getGroup" is to be used in a "change group properties event", the group should
// always show the last information.
Group group = new Group(name, description, members, administrators, properties);
return group;
}
......
......@@ -120,6 +120,62 @@ public class Group implements Cacheable, Externalizable {
this.administrators = new HashSet<JID>(administrators);
}
/**
* Constructs a new group. Note: this constructor is intended for implementors of the
* {@link GroupProvider} interface. To create a new group, use the
* {@link GroupManager#createGroup(String)} method.
*
* @param name the name.
* @param description the description.
* @param members a Collection of the group members.
* @param administrators a Collection of the group administrators.
* @param properties a Map of properties with names and its values.
*/
public Group(String name, String description, Collection<JID> members,
Collection<JID> administrators, Map<String, String> properties)
{
this.groupManager = GroupManager.getInstance();
this.provider = groupManager.getProvider();
this.name = name;
this.description = description;
this.members = new HashSet<JID>(members);
this.administrators = new HashSet<JID>(administrators);
this.properties = new ConcurrentHashMap<String, String>();
// Load the properties that this groups has in the DB
loadProperties();
// Check if we have to create or update some properties
for (Map.Entry<String, String> property : properties.entrySet()) {
// If the DB contains this property
if (properties.containsKey(property.getKey())) {
// then check if we need to update it
if (!property.getValue().equals(properties.get(property.getKey()))) {
// update the properties map
properties.put(property.getKey(), property.getValue());
// and the DB
updateProperty(property.getKey(), property.getValue());
}
} // else we need to add it
else {
// add to the properties map
properties.put(property.getKey(), property.getValue());
// and insert it to the DB
insertProperty(property.getKey(), property.getValue());
}
}
// Check if we have to delete some properties
for (String oldPropName : properties.keySet()) {
if (!properties.containsKey(oldPropName)) {
// delete it from the property map
properties.remove(oldPropName);
// delete it from the DB
deleteProperty(oldPropName);
}
}
}
/**
* Returns the name of the group. For example, 'XYZ Admins'.
*
......
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