Search in sources :

Example 1 with GroupEntity

use of org.jivesoftware.openfire.plugin.rest.entity.GroupEntity 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 2 with GroupEntity

use of org.jivesoftware.openfire.plugin.rest.entity.GroupEntity in project Openfire by igniterealtime.

the class GroupController method getGroup.

/**
	 * Gets the group.
	 *
	 * @param groupName
	 *            the group name
	 * @return the group
	 * @throws ServiceException
	 *             the service exception
	 */
public GroupEntity getGroup(String groupName) throws ServiceException {
    Group group;
    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);
    }
    GroupEntity groupEntity = new GroupEntity(group.getName(), group.getDescription());
    groupEntity.setAdmins(MUCRoomUtils.convertJIDsToStringList(group.getAdmins()));
    groupEntity.setMembers(MUCRoomUtils.convertJIDsToStringList(group.getMembers()));
    return groupEntity;
}
Also used : Group(org.jivesoftware.openfire.group.Group) ServiceException(org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException) GroupEntity(org.jivesoftware.openfire.plugin.rest.entity.GroupEntity) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 3 with GroupEntity

use of org.jivesoftware.openfire.plugin.rest.entity.GroupEntity in project Openfire by igniterealtime.

the class GroupController method getGroups.

/**
	 * Gets the groups.
	 *
	 * @return the groups
	 * @throws ServiceException
	 *             the service exception
	 */
public List<GroupEntity> getGroups() throws ServiceException {
    Collection<Group> groups = GroupManager.getInstance().getGroups();
    List<GroupEntity> groupEntities = new ArrayList<GroupEntity>();
    for (Group group : groups) {
        GroupEntity groupEntity = new GroupEntity(group.getName(), group.getDescription());
        groupEntities.add(groupEntity);
    }
    return groupEntities;
}
Also used : Group(org.jivesoftware.openfire.group.Group) GroupEntity(org.jivesoftware.openfire.plugin.rest.entity.GroupEntity) ArrayList(java.util.ArrayList)

Example 4 with GroupEntity

use of org.jivesoftware.openfire.plugin.rest.entity.GroupEntity in project Openfire by igniterealtime.

the class UserServiceController method addUserToGroup.

/**
	 * Adds the user to group.
	 *
	 * @param username the username
	 * @param groupName the group name
	 * @throws ServiceException the service exception
	 */
public void addUserToGroup(String username, String groupName) throws ServiceException {
    Group group = null;
    try {
        group = GroupManager.getInstance().getGroup(groupName);
    } catch (GroupNotFoundException e) {
        // Create this group
        group = GroupController.getInstance().createGroup(new GroupEntity(groupName, ""));
    }
    group.getMembers().add(server.createJID(username, null));
}
Also used : Group(org.jivesoftware.openfire.group.Group) GroupEntity(org.jivesoftware.openfire.plugin.rest.entity.GroupEntity) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Aggregations

Group (org.jivesoftware.openfire.group.Group)4 GroupEntity (org.jivesoftware.openfire.plugin.rest.entity.GroupEntity)4 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)3 ArrayList (java.util.ArrayList)2 ServiceException (org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException)1