Search in sources :

Example 76 with Group

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());
}
Also used : Group(org.jivesoftware.openfire.group.Group) DataForm(org.xmpp.forms.DataForm) FormField(org.xmpp.forms.FormField)

Example 77 with Group

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"));
}
Also used : Group(org.jivesoftware.openfire.group.Group) JID(org.xmpp.packet.JID) Element(org.dom4j.Element) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 78 with Group

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");
}
Also used : Group(org.jivesoftware.openfire.group.Group) Element(org.dom4j.Element) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 79 with Group

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"));
}
Also used : Group(org.jivesoftware.openfire.group.Group) JID(org.xmpp.packet.JID) Element(org.dom4j.Element) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 80 with Group

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");
}
Also used : Group(org.jivesoftware.openfire.group.Group) Element(org.dom4j.Element) List(java.util.List) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Aggregations

Group (org.jivesoftware.openfire.group.Group)83 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)41 JID (org.xmpp.packet.JID)30 ArrayList (java.util.ArrayList)22 Element (org.dom4j.Element)20 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)10 List (java.util.List)9 User (org.jivesoftware.openfire.user.User)9 ServiceException (org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException)7 StringTokenizer (java.util.StringTokenizer)6 HashMap (java.util.HashMap)5 GroupManager (org.jivesoftware.openfire.group.GroupManager)5 SharedGroupException (org.jivesoftware.openfire.SharedGroupException)4 GroupEntity (org.jivesoftware.openfire.plugin.rest.entity.GroupEntity)4 DataForm (org.xmpp.forms.DataForm)4 IQ (org.xmpp.packet.IQ)4 HashSet (java.util.HashSet)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2