use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.
the class AddGroup method execute.
@Override
public void execute(SessionData data, Element command) {
Element note = command.addElement("note");
// Check if groups cannot be modified (backend is read-only)
if (GroupManager.getInstance().isReadOnly()) {
note.addAttribute("type", "error");
note.setText("Groups are read only");
return;
}
// Get requested group
Group group;
try {
group = GroupManager.getInstance().createGroup(data.getData().get("group").get(0));
} catch (GroupAlreadyExistsException e) {
// Group not found
note.addAttribute("type", "error");
note.setText("Group already exists");
return;
}
List<String> desc = data.getData().get("desc");
if (desc != null && !desc.isEmpty()) {
group.setDescription(desc.get(0));
}
List<String> members = data.getData().get("members");
boolean withErrors = false;
if (members != null) {
Collection<JID> users = group.getMembers();
for (String user : members) {
try {
users.add(new JID(user));
} catch (Exception e) {
Log.warn("User not added to group", e);
withErrors = true;
}
}
}
String showInRoster = data.getData().get("showInRoster").get(0);
if ("nobody".equals(showInRoster)) {
// New group is not a shared group
group.getProperties().put("sharedRoster.showInRoster", "nobody");
group.getProperties().put("sharedRoster.displayName", " ");
group.getProperties().put("sharedRoster.groupList", " ");
} else {
// New group is configured as a shared group
if ("spefgroups".equals(showInRoster)) {
// Show shared group to other groups
showInRoster = "onlyGroup";
}
List<String> displayName = data.getData().get("displayName");
List<String> groupList = data.getData().get("groupList");
if (displayName != null) {
group.getProperties().put("sharedRoster.showInRoster", showInRoster);
group.getProperties().put("sharedRoster.displayName", displayName.get(0));
if (groupList != null) {
StringBuilder buf = new StringBuilder();
String sep = "";
for (String groupName : groupList) {
buf.append(sep).append(groupName);
sep = ",";
}
group.getProperties().put("sharedRoster.groupList", buf.toString());
}
} else {
withErrors = true;
}
}
note.addAttribute("type", "info");
note.setText("Operation finished" + (withErrors ? " with errors" : " successfully"));
}
use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.
the class GetListGroupUsers method execute.
@Override
public void execute(SessionData data, Element command) {
Group group;
try {
group = GroupManager.getInstance().getGroup(data.getData().get("group").get(0));
} catch (GroupNotFoundException e) {
// Group not found
Element note = command.addElement("note");
note.addAttribute("type", "error");
note.setText("Group name does not exist");
return;
}
DataForm form = new DataForm(DataForm.Type.result);
form.addReportedField("jid", "User", FormField.Type.jid_single);
form.addReportedField("admin", "Description", FormField.Type.boolean_type);
// Add group members the result
for (JID memberJID : group.getMembers()) {
Map<String, Object> fields = new HashMap<>();
fields.put("jid", memberJID.toString());
fields.put("admin", false);
form.addItemFields(fields);
}
// Add group admins the result
for (JID memberJID : group.getAdmins()) {
Map<String, Object> fields = new HashMap<>();
fields.put("jid", memberJID.toString());
fields.put("admin", true);
form.addItemFields(fields);
}
command.add(form.getElement());
}
use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.
the class UpdateGroup method addStageInformation.
@Override
protected void addStageInformation(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.form);
if (data.getStage() == 0) {
form.setTitle("Update group configuration");
form.addInstruction("Fill out this form to specify the group to update.");
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("Group Name");
field.setVariable("group");
field.setRequired(true);
} else {
// Check if groups cannot be modified (backend is read-only)
if (GroupManager.getInstance().isReadOnly()) {
Element note = command.addElement("note");
note.addAttribute("type", "error");
note.setText("Groups are read only");
return;
}
// Get requested group
Group group;
try {
group = GroupManager.getInstance().getGroup(data.getData().get("group").get(0));
} catch (GroupNotFoundException e) {
// Group not found
Element note = command.addElement("note");
note.addAttribute("type", "error");
note.setText("Group not found");
return;
}
form.setTitle("Update group configuration");
form.addInstruction("Fill out this form with the new group configuration.");
FormField field = form.addField();
field.setType(FormField.Type.hidden);
field.setVariable("FORM_TYPE");
field.addValue("http://jabber.org/protocol/admin");
field = form.addField();
field.setType(FormField.Type.text_multi);
field.setLabel("Description");
field.setVariable("desc");
if (group.getDescription() != null) {
field.addValue(group.getDescription());
}
field = form.addField();
field.setType(FormField.Type.list_single);
field.setLabel("Shared group visibility");
field.setVariable("showInRoster");
field.addValue("nobody");
field.addOption("Disable sharing group in rosters", "nobody");
field.addOption("Show group in all users' rosters", "everybody");
field.addOption("Show group in group members' rosters", "onlyGroup");
field.addOption("Show group to members' rosters of these groups", "spefgroups");
field.setRequired(true);
String showInRoster = group.getProperties().get("sharedRoster.showInRoster");
if (showInRoster != null) {
if ("onlyGroup".equals(showInRoster) && group.getProperties().get("sharedRoster.groupList").trim().length() > 0) {
// Show shared group to other groups
showInRoster = "spefgroups";
}
field.addValue(showInRoster);
}
field = form.addField();
field.setType(FormField.Type.list_multi);
field.setVariable("groupList");
for (Group otherGroup : GroupManager.getInstance().getGroups()) {
field.addOption(otherGroup.getName(), otherGroup.getName());
}
String groupList = group.getProperties().get("sharedRoster.groupList");
if (groupList != null) {
Collection<String> groups = new ArrayList<>();
StringTokenizer tokenizer = new StringTokenizer(groupList, ",\t\n\r\f");
while (tokenizer.hasMoreTokens()) {
String tok = tokenizer.nextToken().trim();
groups.add(tok.trim());
}
for (String othergroup : groups) {
field.addValue(othergroup);
}
}
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("Group Display Name");
field.setVariable("displayName");
String displayName = group.getProperties().get("sharedRoster.displayName");
if (displayName != null) {
field.addValue(displayName);
}
}
// Add the form to the command
command.add(form.getElement());
}
use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.
the class GroupAdminRemoved method execute.
@Override
public void execute(SessionData sessionData, Element command) {
Element note = command.addElement("note");
Map<String, List<String>> data = sessionData.getData();
// Get the group name
String groupname;
try {
groupname = get(data, "groupName", 0);
} catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText("Group name required parameter.");
return;
}
// Creates event params.
Map<String, Object> params = null;
try {
// Get the admin
String admin = get(data, "admin", 0);
// Adds the admin
params = new HashMap<>();
params.put("admin", admin);
} catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText("Admin required parameter.");
return;
}
// Sends the event
Group group;
try {
group = GroupManager.getInstance().getGroup(groupname, true);
// Fire event.
GroupEventDispatcher.dispatchEvent(group, GroupEventDispatcher.EventType.admin_removed, params);
} catch (GroupNotFoundException e) {
note.addAttribute("type", "error");
note.setText("Group not found.");
}
// Answer that the operation was successful
note.addAttribute("type", "info");
note.setText("Operation finished successfully");
}
use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.
the class RosterManager method userDeleting.
@Override
public void userDeleting(User user, Map<String, Object> params) {
// Shared public groups that have a presence subscription of type FROM
// for the deleted user should no longer have a reference to the deleted user
JID userJID = server.createJID(user.getUsername(), null);
// of type FROM for the new user
for (Group group : getPublicSharedGroups()) {
// Get group members of public group
Collection<JID> users = new HashSet<>(group.getMembers());
users.addAll(group.getAdmins());
// Update the roster of each group member to include a subscription of type FROM
for (JID userToUpdate : users) {
// Get the roster to update
Roster roster = null;
if (server.isLocal(userToUpdate)) {
// Check that the user exists, if not then continue with the next user
try {
UserManager.getInstance().getUser(userToUpdate.getNode());
} catch (UserNotFoundException e) {
continue;
}
roster = rosterCache.get(userToUpdate.getNode());
}
// Only update rosters in memory
if (roster != null) {
roster.deleteSharedUser(group, userJID);
}
if (!server.isLocal(userToUpdate)) {
// Unsusbcribe from the presence of the remote user. This is only necessary for
// remote users and may only work with remote users that **automatically**
// accept presence subscription requests
sendSubscribeRequest(userJID, userToUpdate, false);
}
}
}
deleteRoster(userJID);
}
Aggregations