use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.
the class AddGroup method addStageInformation.
@Override
protected void addStageInformation(SessionData data, Element command) {
DataForm form = new DataForm(DataForm.Type.form);
form.setTitle("Create new group");
form.addInstruction("Fill out this form to create a new group.");
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);
field = form.addField();
field.setType(FormField.Type.text_multi);
field.setLabel("Description");
field.setVariable("desc");
field = form.addField();
field.setType(FormField.Type.jid_multi);
field.setLabel("Initial members");
field.setVariable("members");
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);
field = form.addField();
field.setType(FormField.Type.list_multi);
field.setVariable("groupList");
for (Group group : GroupManager.getInstance().getGroups()) {
field.addOption(group.getName(), group.getName());
}
field = form.addField();
field.setType(FormField.Type.text_single);
field.setLabel("Group Display Name");
field.setVariable("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 AddGroupUsers 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().getGroup(data.getData().get("group").get(0));
} catch (GroupNotFoundException e) {
// Group not found
note.addAttribute("type", "error");
note.setText("Group name does not exist");
return;
}
String admin = data.getData().get("admin").get(0);
boolean isAdmin = "1".equals(admin) || "true".equals(admin);
Collection<JID> users = (isAdmin ? group.getAdmins() : group.getMembers());
boolean withErrors = false;
for (String user : data.getData().get("users")) {
try {
users.add(new JID(user));
} catch (Exception e) {
Log.warn("User not added to group", e);
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 DeleteGroup 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().getGroup(data.getData().get("group").get(0));
} catch (GroupNotFoundException e) {
// Group not found
note.addAttribute("type", "error");
note.setText("Group name does not exist");
return;
}
GroupManager.getInstance().deleteGroup(group);
note.addAttribute("type", "info");
note.setText("Operation finished successfully");
}
use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.
the class DeleteGroupUsers 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().getGroup(data.getData().get("group").get(0));
} catch (GroupNotFoundException e) {
// Group not found
note.addAttribute("type", "error");
note.setText("Group name does not exist");
return;
}
boolean withErrors = false;
for (String user : data.getData().get("users")) {
try {
group.getAdmins().remove(new JID(user));
group.getMembers().remove(new JID(user));
} catch (Exception e) {
Log.warn("User not deleted from group", e);
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 GroupMemberRemoved 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 member
String member = get(data, "member", 0);
// Adds the member
params = new HashMap<>();
params.put("member", member);
} catch (NullPointerException npe) {
note.addAttribute("type", "error");
note.setText("Member required parameter.");
return;
}
// Sends the event
Group group;
try {
group = GroupManager.getInstance().getGroup(groupname, true);
// Fire event.
GroupEventDispatcher.dispatchEvent(group, GroupEventDispatcher.EventType.member_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");
}
Aggregations