Search in sources :

Example 16 with Group

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

the class UserServicePluginNG method createGroup.

/**
	 * Creates the group.
	 *
	 * @param groupName
	 *            the group name
	 * @return the group
	 * @throws ServiceException
	 * @throws GroupAlreadyExistsException
	 *             the group already exists exception
	 */
private Group createGroup(String groupName) throws ServiceException {
    Group group = null;
    try {
        group = GroupManager.getInstance().createGroup(groupName);
        group.getProperties().put("sharedRoster.showInRoster", "onlyGroup");
        group.getProperties().put("sharedRoster.displayName", groupName);
        group.getProperties().put("sharedRoster.groupList", "");
    } catch (GroupAlreadyExistsException e) {
        throw new ServiceException("Could not create group", groupName, ExceptionType.GROUP_ALREADY_EXISTS, Response.Status.BAD_REQUEST, e);
    }
    return group;
}
Also used : Group(org.jivesoftware.openfire.group.Group) ServiceException(org.jivesoftware.openfire.exceptions.ServiceException) GroupAlreadyExistsException(org.jivesoftware.openfire.group.GroupAlreadyExistsException)

Example 17 with Group

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

the class RequestQueue method getGroupObjects.

private Collection<Group> getGroupObjects() {
    final GroupManager groupManager = GroupManager.getInstance();
    Set<Group> objects = new HashSet<Group>(groups.size());
    for (String group : groups) {
        try {
            objects.add(groupManager.getGroup(group));
        } catch (GroupNotFoundException e) {
            Log.error("Error retrieving group: " + group, e);
        }
    }
    return objects;
}
Also used : Group(org.jivesoftware.openfire.group.Group) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException) GroupManager(org.jivesoftware.openfire.group.GroupManager) HashSet(java.util.HashSet)

Example 18 with Group

use of org.jivesoftware.openfire.group.Group 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 19 with Group

use of org.jivesoftware.openfire.group.Group 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 20 with Group

use of org.jivesoftware.openfire.group.Group 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)

Aggregations

Group (org.jivesoftware.openfire.group.Group)84 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)42 JID (org.xmpp.packet.JID)30 Element (org.dom4j.Element)20 ArrayList (java.util.ArrayList)19 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)11 User (org.jivesoftware.openfire.user.User)9 List (java.util.List)7 ServiceException (org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException)7 StringTokenizer (java.util.StringTokenizer)6 GroupManager (org.jivesoftware.openfire.group.GroupManager)5 HashMap (java.util.HashMap)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 XMPPServer (org.jivesoftware.openfire.XMPPServer)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2