Search in sources :

Example 6 with ServiceException

use of org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException 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 7 with ServiceException

use of org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException 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)

Example 8 with ServiceException

use of org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException in project Openfire by igniterealtime.

the class MUCRoomController method getChatRoom.

/**
	 * Gets the chat room.
	 * 
	 * @param roomName
	 *            the room name
	 * @param serviceName
	 *            the service name
	 * @return the chat room
	 * @throws ServiceException
	 *             the service exception
	 */
public MUCRoomEntity getChatRoom(String roomName, String serviceName, boolean expand) throws ServiceException {
    MUCRoom chatRoom = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName).getChatRoom(roomName);
    if (chatRoom == null) {
        throw new ServiceException("Could not find the chat room", roomName, ExceptionType.ROOM_NOT_FOUND, Response.Status.NOT_FOUND);
    }
    MUCRoomEntity mucRoomEntity = convertToMUCRoomEntity(chatRoom, expand);
    return mucRoomEntity;
}
Also used : LocalMUCRoom(org.jivesoftware.openfire.muc.spi.LocalMUCRoom) MUCRoom(org.jivesoftware.openfire.muc.MUCRoom) ServiceException(org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException) MUCRoomEntity(org.jivesoftware.openfire.plugin.rest.entity.MUCRoomEntity)

Example 9 with ServiceException

use of org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException in project Openfire by igniterealtime.

the class GroupController method createGroup.

/**
	 * Creates the group.
	 *
	 * @param groupEntity
	 *            the group entity
	 * @return the group
	 * @throws ServiceException
	 *             the service exception
	 */
public Group createGroup(GroupEntity groupEntity) throws ServiceException {
    Group group;
    if (groupEntity != null && !groupEntity.getName().isEmpty()) {
        try {
            group = GroupManager.getInstance().createGroup(groupEntity.getName());
            group.setDescription(groupEntity.getDescription());
            group.getProperties().put("sharedRoster.showInRoster", "onlyGroup");
            group.getProperties().put("sharedRoster.displayName", groupEntity.getName());
            group.getProperties().put("sharedRoster.groupList", "");
        } catch (GroupAlreadyExistsException e) {
            throw new ServiceException("Could not create a group", groupEntity.getName(), ExceptionType.GROUP_ALREADY_EXISTS, Response.Status.CONFLICT, e);
        }
    } else {
        throw new ServiceException("Could not create 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) GroupAlreadyExistsException(org.jivesoftware.openfire.group.GroupAlreadyExistsException)

Example 10 with ServiceException

use of org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException in project Openfire by igniterealtime.

the class JustMarriedController method changeName.

/**
	 * Change name.
	 *
	 * @param currentUserName
	 *            the current user name
	 * @param newUserName
	 *            the new user name
	 * @param deleteOldUser
	 *            the delete old user
	 * @param newEmail
	 *            the new email
	 * @param newRealName
	 *            the new real name
	 * @return true, if successful
	 * @throws ServiceException
	 *             the service exception
	 */
public static boolean changeName(String currentUserName, String newUserName, boolean deleteOldUser, String newEmail, String newRealName) throws ServiceException {
    UserManager userManager = UserManager.getInstance();
    try {
        User currentUser = userManager.getUser(currentUserName);
        // Old user found, create new one
        String password = AuthFactory.getPassword(currentUserName);
        String newName = (newRealName == null || newRealName.length() == 0) ? currentUser.getName() : newRealName;
        String newMail = (newEmail == null || newEmail.length() == 0) ? currentUser.getEmail() : newEmail;
        User newUser = userManager.createUser(newUserName, password, currentUser.getName(), newMail);
        newUser.setName(newName);
        newUser.setNameVisible(currentUser.isNameVisible());
        newUser.setEmailVisible(currentUser.isEmailVisible());
        newUser.setCreationDate(currentUser.getCreationDate());
        copyRoster(currentUser, newUser, currentUserName);
        copyProperties(currentUser, newUser);
        copyToGroups(currentUserName, newUserName);
        copyVCard(currentUserName, newUserName);
        if (deleteOldUser) {
            deleteUser(currentUser);
        }
    } catch (UserNotFoundException e) {
        throw new ServiceException("Could not find user", currentUserName, ExceptionType.USER_NOT_FOUND_EXCEPTION, Response.Status.NOT_FOUND, e);
    } catch (UserAlreadyExistsException e) {
        throw new ServiceException("Could not create new user", newUserName, ExceptionType.USER_ALREADY_EXISTS_EXCEPTION, Response.Status.CONFLICT, e);
    }
    return true;
}
Also used : UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException) User(org.jivesoftware.openfire.user.User) ServiceException(org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException) UserManager(org.jivesoftware.openfire.user.UserManager) UserAlreadyExistsException(org.jivesoftware.openfire.user.UserAlreadyExistsException)

Aggregations

ServiceException (org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException)16 Group (org.jivesoftware.openfire.group.Group)7 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)6 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)5 UserAlreadyExistsException (org.jivesoftware.openfire.user.UserAlreadyExistsException)5 Roster (org.jivesoftware.openfire.roster.Roster)4 SharedGroupException (org.jivesoftware.openfire.SharedGroupException)3 RosterItem (org.jivesoftware.openfire.roster.RosterItem)3 JID (org.xmpp.packet.JID)3 ArrayList (java.util.ArrayList)2 MUCRoom (org.jivesoftware.openfire.muc.MUCRoom)2 LocalMUCRoom (org.jivesoftware.openfire.muc.spi.LocalMUCRoom)2 User (org.jivesoftware.openfire.user.User)2 UserManager (org.jivesoftware.openfire.user.UserManager)2 Presence (org.xmpp.packet.Presence)2 UnknownHostException (java.net.UnknownHostException)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1