Search in sources :

Example 1 with Group

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

the class SearchPlugin method filterGroupSearchResults.

public Set<User> filterGroupSearchResults(JID jid, Set<User> searchResults) {
    if (groupOnly) {
        Collection<Group> groups = GroupManager.getInstance().getGroups(jid);
        Set<User> allSearchResults = new HashSet<User>(searchResults);
        searchResults.clear();
        for (User user : allSearchResults) {
            for (Group group : groups) {
                if (group.isUser(user.getUID())) {
                    searchResults.add(user);
                }
            }
        }
    }
    return searchResults;
}
Also used : Group(org.jivesoftware.openfire.group.Group) User(org.jivesoftware.openfire.user.User) HashSet(java.util.HashSet)

Example 2 with Group

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

the class UserServiceController method deleteUserFromGroups.

/**
	 * Delete user from groups.
	 *
	 * @param username
	 *            the username
	 * @param userGroupsEntity
	 *            the user groups entity
	 * @throws ServiceException
	 *             the service exception
	 */
public void deleteUserFromGroups(String username, UserGroupsEntity userGroupsEntity) throws ServiceException {
    if (userGroupsEntity != null) {
        for (String groupName : userGroupsEntity.getGroupNames()) {
            Group group = null;
            try {
                group = GroupManager.getInstance().getGroup(groupName);
            } catch (GroupNotFoundException e) {
                throw new ServiceException("Could not find group", groupName, ExceptionType.GROUP_NOT_FOUND, Response.Status.NOT_FOUND, e);
            }
            group.getMembers().remove(server.createJID(username, null));
        }
    }
}
Also used : Group(org.jivesoftware.openfire.group.Group) ServiceException(org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 3 with Group

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

the class UserServiceController method getUserGroups.

/**
	 * Gets the user groups.
	 *
	 * @param username
	 *            the username
	 * @return the user groups
	 * @throws ServiceException
	 *             the service exception
	 */
public List<String> getUserGroups(String username) throws ServiceException {
    User user = getAndCheckUser(username);
    Collection<Group> groups = GroupManager.getInstance().getGroups(user);
    List<String> groupNames = new ArrayList<String>();
    for (Group group : groups) {
        groupNames.add(group.getName());
    }
    return groupNames;
}
Also used : Group(org.jivesoftware.openfire.group.Group) User(org.jivesoftware.openfire.user.User) ArrayList(java.util.ArrayList)

Example 4 with Group

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

the class UserServiceController method addUserToGroups.

/**
	 * Adds the user to group.
	 *
	 * @param username
	 *            the username
	 * @param userGroupsEntity
	 *            the user groups entity
	 * @throws ServiceException
	 *             the service exception
	 */
public void addUserToGroups(String username, UserGroupsEntity userGroupsEntity) throws ServiceException {
    if (userGroupsEntity != null) {
        Collection<Group> groups = new ArrayList<Group>();
        for (String groupName : userGroupsEntity.getGroupNames()) {
            Group group = null;
            try {
                group = GroupManager.getInstance().getGroup(groupName);
            } catch (GroupNotFoundException e) {
                // Create this group
                group = GroupController.getInstance().createGroup(new GroupEntity(groupName, ""));
            }
            groups.add(group);
        }
        for (Group group : groups) {
            group.getMembers().add(server.createJID(username, null));
        }
    }
}
Also used : Group(org.jivesoftware.openfire.group.Group) GroupEntity(org.jivesoftware.openfire.plugin.rest.entity.GroupEntity) ArrayList(java.util.ArrayList) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 5 with Group

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

the class UserServiceController method deleteUserFromGroup.

/**
	 * Delete user from group.
	 *
	 * @param username the username
	 * @param groupName the group name
	 * @throws ServiceException the service exception
	 */
public void deleteUserFromGroup(String username, String groupName) throws ServiceException {
    Group group = null;
    try {
        group = GroupManager.getInstance().getGroup(groupName);
    } catch (GroupNotFoundException e) {
        throw new ServiceException("Could not find group", groupName, ExceptionType.GROUP_NOT_FOUND, Response.Status.NOT_FOUND, e);
    }
    group.getMembers().remove(server.createJID(username, null));
}
Also used : Group(org.jivesoftware.openfire.group.Group) ServiceException(org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException) 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