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);
}
}
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;
}
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;
}
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));
}
}
}
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);
}
}
Aggregations