Search in sources :

Example 16 with GroupNotFoundException

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

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

Example 18 with GroupNotFoundException

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

the class GroupController method deleteGroup.

/**
	 * Delete group.
	 *
	 * @param groupName
	 *            the group name
	 * @throws ServiceException
	 *             the service exception
	 */
public void deleteGroup(String groupName) throws ServiceException {
    try {
        Group group = GroupManager.getInstance().getGroup(groupName);
        GroupManager.getInstance().deleteGroup(group);
    } catch (GroupNotFoundException e) {
        throw new ServiceException("Could not find group", groupName, ExceptionType.GROUP_NOT_FOUND, Response.Status.NOT_FOUND, e);
    }
}
Also used : Group(org.jivesoftware.openfire.group.Group) ServiceException(org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 19 with GroupNotFoundException

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

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

the class GroupController method updateGroup.

/**
	 * Update group.
	 *
	 * @param groupName the group name
	 * @param groupEntity the group entity
	 * @return the group
	 * @throws ServiceException the service exception
	 */
public Group updateGroup(String groupName, GroupEntity groupEntity) throws ServiceException {
    Group group;
    if (groupEntity != null && !groupEntity.getName().isEmpty()) {
        if (groupName.equals(groupEntity.getName())) {
            try {
                group = GroupManager.getInstance().getGroup(groupName);
                group.setDescription(groupEntity.getDescription());
            } catch (GroupNotFoundException e) {
                throw new ServiceException("Could not find group", groupName, ExceptionType.GROUP_NOT_FOUND, Response.Status.NOT_FOUND, e);
            }
        } else {
            throw new ServiceException("Could not update the group. The group name is different to the payload group name.", groupName + " != " + groupEntity.getName(), ExceptionType.ILLEGAL_ARGUMENT_EXCEPTION, Response.Status.BAD_REQUEST);
        }
    } else {
        throw new ServiceException("Could not update new group", "groups", ExceptionType.ILLEGAL_ARGUMENT_EXCEPTION, Response.Status.BAD_REQUEST);
    }
    return group;
}
Also used : Group(org.jivesoftware.openfire.group.Group) ServiceException(org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

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