Search in sources :

Example 6 with GroupNotFoundException

use of org.jivesoftware.openfire.group.GroupNotFoundException in project Openfire by igniterealtime.

the class GroupModified 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;
    }
    // Get the modification type
    String type;
    try {
        type = get(data, "changeType", 0);
    } catch (NullPointerException npe) {
        note.addAttribute("type", "error");
        note.setText("Change type required parameter.");
        return;
    }
    // Identifies the value variable
    String valueVariable = null;
    String valueVariableName = null;
    if ("nameModified".equals(type) || "descriptionModified".equals(type)) {
        valueVariable = "originalValue";
        valueVariableName = "Original value";
    } else if ("propertyModified".equals(type) || "propertyAdded".equals(type) || "propertyDeleted".equals(type)) {
        valueVariable = "propertyKey";
        valueVariableName = "Property key";
    }
    // Creates event params.
    Map<String, Object> params = new HashMap<>();
    // Gets the value of the change if it exist
    String value;
    if (valueVariable != null) {
        try {
            // Gets the value
            value = get(data, valueVariable, 0);
            // Adds it to the event params
            params.put(valueVariable, value);
        } catch (NullPointerException npe) {
            note.addAttribute("type", "error");
            note.setText(valueVariableName + " required parameter.");
            return;
        }
    }
    // Adds the type of change
    params.put("type", type);
    // Sends the event
    Group group;
    try {
        group = GroupManager.getInstance().getGroup(groupname, true);
        // Fire event.
        GroupEventDispatcher.dispatchEvent(group, GroupEventDispatcher.EventType.group_modified, 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) HashMap(java.util.HashMap) Element(org.dom4j.Element) List(java.util.List) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 7 with GroupNotFoundException

use of org.jivesoftware.openfire.group.GroupNotFoundException in project Openfire by igniterealtime.

the class GroupAdminAdded 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_added, 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)

Example 8 with GroupNotFoundException

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

Example 9 with GroupNotFoundException

use of org.jivesoftware.openfire.group.GroupNotFoundException in project Openfire by igniterealtime.

the class GroupCreated 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;
    }
    // Sends the event
    Group group;
    try {
        group = GroupManager.getInstance().getGroup(groupname, true);
        // Fire event.
        Map<String, Object> params = Collections.emptyMap();
        GroupEventDispatcher.dispatchEvent(group, GroupEventDispatcher.EventType.group_created, 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)

Example 10 with GroupNotFoundException

use of org.jivesoftware.openfire.group.GroupNotFoundException in project Openfire by igniterealtime.

the class RosterAccess method canSubscribe.

@Override
public boolean canSubscribe(Node node, JID owner, JID subscriber) {
    // Let node owners and sysadmins always subscribe to the node
    if (node.isAdmin(owner)) {
        return true;
    }
    for (JID nodeOwner : node.getOwners()) {
        if (nodeOwner.equals(owner)) {
            return true;
        }
    }
    // Check that the subscriber is a local user
    XMPPServer server = XMPPServer.getInstance();
    if (server.isLocal(owner)) {
        GroupManager gMgr = GroupManager.getInstance();
        Collection<String> nodeGroups = node.getRosterGroupsAllowed();
        for (String groupName : nodeGroups) {
            try {
                Group group = gMgr.getGroup(groupName);
                // access allowed if the node group is visible to the subscriber
                if (server.getRosterManager().isGroupVisible(group, owner)) {
                    return true;
                }
            } catch (GroupNotFoundException gnfe) {
            // ignore
            }
        }
    } else {
        // Subscriber is a remote user. This should never happen.
        Log.warn("Node with access model Roster has a remote user as subscriber: " + node.getNodeID());
    }
    return false;
}
Also used : Group(org.jivesoftware.openfire.group.Group) XMPPServer(org.jivesoftware.openfire.XMPPServer) JID(org.xmpp.packet.JID) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) GroupManager(org.jivesoftware.openfire.group.GroupManager)

Aggregations

GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)40 Group (org.jivesoftware.openfire.group.Group)38 Element (org.dom4j.Element)15 JID (org.xmpp.packet.JID)12 ArrayList (java.util.ArrayList)11 List (java.util.List)8 StringTokenizer (java.util.StringTokenizer)6 ServiceException (org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException)5 GroupManager (org.jivesoftware.openfire.group.GroupManager)4 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)4 GroupJID (org.jivesoftware.openfire.group.GroupJID)3 GroupEntity (org.jivesoftware.openfire.plugin.rest.entity.GroupEntity)3 User (org.jivesoftware.openfire.user.User)3 Presence (org.xmpp.packet.Presence)3 HashMap (java.util.HashMap)2 NamingException (javax.naming.NamingException)2 MUCRole (org.jivesoftware.openfire.muc.MUCRole)2 DataForm (org.xmpp.forms.DataForm)2 FormField (org.xmpp.forms.FormField)2 RemoteException (java.rmi.RemoteException)1