Search in sources :

Example 81 with Group

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

the class UserServiceLegacyController method getAllGroups.

/**
	 * Returns all group names or an empty collection.
	 *
	 * @return the all groups
	 */
public Collection<String> getAllGroups() {
    Collection<Group> groups = GroupManager.getInstance().getGroups();
    Collection<String> groupNames = new ArrayList<String>();
    for (Group group : groups) {
        groupNames.add(group.getName());
    }
    return groupNames;
}
Also used : Group(org.jivesoftware.openfire.group.Group) ArrayList(java.util.ArrayList)

Example 82 with Group

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

the class UserServiceLegacyController method createUser.

/**
	 * Creates the user.
	 *
	 * @param username the username
	 * @param password the password
	 * @param name the name
	 * @param email the email
	 * @param groupNames the group names
	 * @throws UserAlreadyExistsException the user already exists exception
	 * @throws GroupAlreadyExistsException the group already exists exception
	 * @throws UserNotFoundException the user not found exception
	 * @throws GroupNotFoundException the group not found exception
	 */
public void createUser(String username, String password, String name, String email, String groupNames) throws UserAlreadyExistsException, GroupAlreadyExistsException, UserNotFoundException, GroupNotFoundException {
    userManager.createUser(username, password, name, email);
    userManager.getUser(username);
    if (groupNames != null) {
        Collection<Group> groups = new ArrayList<Group>();
        StringTokenizer tkn = new StringTokenizer(groupNames, ",");
        while (tkn.hasMoreTokens()) {
            String groupName = tkn.nextToken();
            Group group = null;
            try {
                group = GroupManager.getInstance().getGroup(groupName);
            } catch (GroupNotFoundException e) {
                // Create this group ;
                group = GroupManager.getInstance().createGroup(groupName);
                group.getProperties().put("sharedRoster.showInRoster", "onlyGroup");
                group.getProperties().put("sharedRoster.displayName", groupName);
                group.getProperties().put("sharedRoster.groupList", "");
            }
            groups.add(group);
        }
        for (Group group : groups) {
            group.getMembers().add(server.createJID(username, null));
        }
    }
}
Also used : Group(org.jivesoftware.openfire.group.Group) StringTokenizer(java.util.StringTokenizer) ArrayList(java.util.ArrayList) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 83 with Group

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

the class UserServiceLegacyController method getUserGroups.

/**
	 * Returns all group names or an empty collection for specific user.
	 *
	 * @param username the username
	 * @return the user groups
	 * @throws UserNotFoundException the user not found exception
	 */
public Collection<String> getUserGroups(String username) throws UserNotFoundException {
    User user = getUser(username);
    Collection<Group> groups = GroupManager.getInstance().getGroups(user);
    Collection<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)

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