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