use of org.jivesoftware.openfire.muc.MUCRoom 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 MUCServiceException
* the MUC service exception
*/
public MUCRoomEntity getChatRoom(String roomName, String serviceName) throws MUCServiceException {
MUCRoom chatRoom = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName).getChatRoom(roomName);
if (chatRoom == null) {
throw new MUCServiceException("Could not fetch the channel", roomName, "Chat room could be not found");
}
MUCRoomEntity mucRoomEntity = convertToMUCRoomEntity(chatRoom);
return mucRoomEntity;
}
use of org.jivesoftware.openfire.muc.MUCRoom in project Openfire by igniterealtime.
the class MUCRoomController method createRoom.
/**
* Creates the room.
*
* @param mucRoomEntity
* the MUC room entity
* @param serviceName
* the service name
* @throws NotAllowedException
* the not allowed exception
* @throws ForbiddenException
* the forbidden exception
* @throws ConflictException
* the conflict exception
*/
private void createRoom(MUCRoomEntity mucRoomEntity, String serviceName) throws NotAllowedException, ForbiddenException, ConflictException {
// Set owner
JID owner = XMPPServer.getInstance().createJID("admin", null);
if (mucRoomEntity.getOwners() != null && mucRoomEntity.getOwners().size() > 0) {
owner = new JID(mucRoomEntity.getOwners().get(0));
} else {
List<String> owners = new ArrayList<String>();
owners.add(owner.toBareJID());
mucRoomEntity.setOwners(owners);
}
MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName).getChatRoom(mucRoomEntity.getRoomName().toLowerCase(), owner);
// Set values
room.setNaturalLanguageName(mucRoomEntity.getNaturalName());
room.setSubject(mucRoomEntity.getSubject());
room.setDescription(mucRoomEntity.getDescription());
room.setPassword(mucRoomEntity.getPassword());
room.setPersistent(mucRoomEntity.isPersistent());
room.setPublicRoom(mucRoomEntity.isPublicRoom());
room.setRegistrationEnabled(mucRoomEntity.isRegistrationEnabled());
room.setCanAnyoneDiscoverJID(mucRoomEntity.isCanAnyoneDiscoverJID());
room.setCanOccupantsChangeSubject(mucRoomEntity.isCanOccupantsChangeSubject());
room.setCanOccupantsInvite(mucRoomEntity.isCanOccupantsInvite());
room.setChangeNickname(mucRoomEntity.isCanChangeNickname());
room.setModificationDate(mucRoomEntity.getModificationDate());
room.setLogEnabled(mucRoomEntity.isLogEnabled());
room.setLoginRestrictedToNickname(mucRoomEntity.isLoginRestrictedToNickname());
room.setMaxUsers(mucRoomEntity.getMaxUsers());
room.setMembersOnly(mucRoomEntity.isMembersOnly());
room.setModerated(mucRoomEntity.isModerated());
// Set broadcast presence roles
if (mucRoomEntity.getBroadcastPresenceRoles() != null) {
room.setRolesToBroadcastPresence(mucRoomEntity.getBroadcastPresenceRoles());
} else {
room.setRolesToBroadcastPresence(new ArrayList<String>());
}
// Set all roles
setRoles(room, mucRoomEntity);
// Set creation date
if (mucRoomEntity.getCreationDate() != null) {
room.setCreationDate(mucRoomEntity.getCreationDate());
} else {
room.setCreationDate(new Date());
}
// Set modification date
if (mucRoomEntity.getModificationDate() != null) {
room.setModificationDate(mucRoomEntity.getModificationDate());
} else {
room.setModificationDate(new Date());
}
// Unlock the room, because the default configuration lock the room.
room.unlock(room.getRole());
// Save the room to the DB if the room should be persistant
if (room.isPersistent()) {
room.saveToDB();
}
}
use of org.jivesoftware.openfire.muc.MUCRoom in project Openfire by igniterealtime.
the class MUCRoomController method getChatRooms.
/**
* Gets the chat rooms.
*
* @param serviceName
* the service name
* @param channelType
* the channel type
* @param roomSearch
* the room search
* @return the chat rooms
*/
public MUCRoomEntities getChatRooms(String serviceName, String channelType, String roomSearch) {
List<MUCRoom> rooms = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName).getChatRooms();
List<MUCRoomEntity> mucRoomEntities = new ArrayList<MUCRoomEntity>();
for (MUCRoom chatRoom : rooms) {
if (roomSearch != null) {
if (!chatRoom.getName().contains(roomSearch)) {
continue;
}
}
if (channelType.equals(MUCChannelType.ALL)) {
mucRoomEntities.add(convertToMUCRoomEntity(chatRoom));
} else if (channelType.equals(MUCChannelType.PUBLIC) && chatRoom.isPublicRoom()) {
mucRoomEntities.add(convertToMUCRoomEntity(chatRoom));
}
}
return new MUCRoomEntities(mucRoomEntities);
}
use of org.jivesoftware.openfire.muc.MUCRoom 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;
}
use of org.jivesoftware.openfire.muc.MUCRoom in project Openfire by igniterealtime.
the class MUCRoomController method createRoom.
/**
* Creates the room.
*
* @param mucRoomEntity
* the MUC room entity
* @param serviceName
* the service name
* @throws NotAllowedException
* the not allowed exception
* @throws ForbiddenException
* the forbidden exception
* @throws ConflictException
* the conflict exception
* @throws AlreadyExistsException
*/
private void createRoom(MUCRoomEntity mucRoomEntity, String serviceName) throws NotAllowedException, ForbiddenException, ConflictException, AlreadyExistsException {
// Set owner
JID owner = XMPPServer.getInstance().createJID("admin", null);
if (mucRoomEntity.getOwners() != null && mucRoomEntity.getOwners().size() > 0) {
owner = new JID(mucRoomEntity.getOwners().get(0));
} else {
List<String> owners = new ArrayList<String>();
owners.add(owner.toBareJID());
mucRoomEntity.setOwners(owners);
}
// Check if chat service is available, if not create a new one
boolean serviceRegistered = XMPPServer.getInstance().getMultiUserChatManager().isServiceRegistered(serviceName);
if (!serviceRegistered) {
XMPPServer.getInstance().getMultiUserChatManager().createMultiUserChatService(serviceName, serviceName, false);
}
MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName).getChatRoom(mucRoomEntity.getRoomName().toLowerCase(), owner);
// Set values
room.setNaturalLanguageName(mucRoomEntity.getNaturalName());
room.setSubject(mucRoomEntity.getSubject());
room.setDescription(mucRoomEntity.getDescription());
room.setPassword(mucRoomEntity.getPassword());
room.setPersistent(mucRoomEntity.isPersistent());
room.setPublicRoom(mucRoomEntity.isPublicRoom());
room.setRegistrationEnabled(mucRoomEntity.isRegistrationEnabled());
room.setCanAnyoneDiscoverJID(mucRoomEntity.isCanAnyoneDiscoverJID());
room.setCanOccupantsChangeSubject(mucRoomEntity.isCanOccupantsChangeSubject());
room.setCanOccupantsInvite(mucRoomEntity.isCanOccupantsInvite());
room.setChangeNickname(mucRoomEntity.isCanChangeNickname());
room.setModificationDate(mucRoomEntity.getModificationDate());
room.setLogEnabled(mucRoomEntity.isLogEnabled());
room.setLoginRestrictedToNickname(mucRoomEntity.isLoginRestrictedToNickname());
room.setMaxUsers(mucRoomEntity.getMaxUsers());
room.setMembersOnly(mucRoomEntity.isMembersOnly());
room.setModerated(mucRoomEntity.isModerated());
// Fire RoomUpdateEvent if cluster is started
if (ClusterManager.isClusteringStarted()) {
CacheFactory.doClusterTask(new RoomUpdatedEvent((LocalMUCRoom) room));
}
// Set broadcast presence roles
if (mucRoomEntity.getBroadcastPresenceRoles() != null) {
room.setRolesToBroadcastPresence(mucRoomEntity.getBroadcastPresenceRoles());
} else {
room.setRolesToBroadcastPresence(new ArrayList<String>());
}
// Set all roles
setRoles(room, mucRoomEntity);
// Set creation date
if (mucRoomEntity.getCreationDate() != null) {
room.setCreationDate(mucRoomEntity.getCreationDate());
} else {
room.setCreationDate(new Date());
}
// Set modification date
if (mucRoomEntity.getModificationDate() != null) {
room.setModificationDate(mucRoomEntity.getModificationDate());
} else {
room.setModificationDate(new Date());
}
// Unlock the room, because the default configuration lock the room.
room.unlock(room.getRole());
// Save the room to the DB if the room should be persistant
if (room.isPersistent()) {
room.saveToDB();
}
}
Aggregations