Search in sources :

Example 6 with Group

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

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

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

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

the class UserServiceLegacyController method updateUser.

/**
	 * Update user.
	 *
	 * @param username the username
	 * @param password the password
	 * @param name the name
	 * @param email the email
	 * @param groupNames the group names
	 * @throws UserNotFoundException the user not found exception
	 * @throws GroupAlreadyExistsException the group already exists exception
	 */
public void updateUser(String username, String password, String name, String email, String groupNames) throws UserNotFoundException, GroupAlreadyExistsException {
    User user = getUser(username);
    if (password != null)
        user.setPassword(password);
    if (name != null)
        user.setName(name);
    if (email != null)
        user.setEmail(email);
    if (groupNames != null) {
        Collection<Group> newGroups = 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", "");
            }
            newGroups.add(group);
        }
        Collection<Group> existingGroups = GroupManager.getInstance().getGroups(user);
        // Get the list of groups to add to the user
        Collection<Group> groupsToAdd = new ArrayList<Group>(newGroups);
        groupsToAdd.removeAll(existingGroups);
        // Get the list of groups to remove from the user
        Collection<Group> groupsToDelete = new ArrayList<Group>(existingGroups);
        groupsToDelete.removeAll(newGroups);
        // Add the user to the new groups
        for (Group group : groupsToAdd) {
            group.getMembers().add(server.createJID(username, null));
        }
        // Remove the user from the old groups
        for (Group group : groupsToDelete) {
            group.getMembers().remove(server.createJID(username, null));
        }
    }
}
Also used : Group(org.jivesoftware.openfire.group.Group) StringTokenizer(java.util.StringTokenizer) User(org.jivesoftware.openfire.user.User) ArrayList(java.util.ArrayList) GroupNotFoundException(org.jivesoftware.openfire.group.GroupNotFoundException)

Example 10 with Group

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

the class PermissionManager method storeGroupList.

/**
     * Stores a list of groups as having access to the transport in question.
     *
     * @param groups list of groups who should have access.
     */
public void storeGroupList(ArrayList<Group> groups) {
    Connection con = null;
    PreparedStatement pstmt = null;
    try {
        con = DbConnectionManager.getConnection();
        pstmt = con.prepareStatement(DELETE_ALL_GROUPS);
        pstmt.setString(1, transportType.toString());
        pstmt.executeUpdate();
        pstmt.close();
        pstmt = con.prepareStatement(ADD_NEW_GROUP);
        pstmt.setString(1, transportType.toString());
        for (Group group : groups) {
            pstmt.setString(2, group.getName());
            pstmt.executeUpdate();
        }
        pstmt.close();
    } catch (SQLException sqle) {
        Log.error(sqle);
    } finally {
        DbConnectionManager.closeConnection(pstmt, con);
    }
}
Also used : Group(org.jivesoftware.openfire.group.Group) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

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